src/message.h
author vb
Sun, 15 Mar 2015 10:14:43 +0100
changeset 113 4bee48270834
parent 112 d001ca329a48
child 117 d2ff99ccdf30
permissions -rw-r--r--
...
vb@99
     1
#pragma once
vb@99
     2
vb@99
     3
#include <time.h>
vb@106
     4
vb@99
     5
#include "pEpEngine.h"
vb@99
     6
#include "identity_list.h"
vb@99
     7
#include "bloblist.h"
vb@106
     8
#include "stringlist.h"
vb@99
     9
#include "stringpair.h"
vb@113
    10
#include "timestamp.h"
vb@99
    11
vb@99
    12
#ifdef __cplusplus
vb@99
    13
extern "C" {
vb@99
    14
#endif
vb@99
    15
vb@99
    16
vb@99
    17
typedef enum _PEP_text_format {
vb@99
    18
    PEP_text_format_plain = 0,
vb@99
    19
    PEP_text_format_html,
vb@99
    20
    PEP_text_format_other = 0xff
vb@99
    21
} PEP_text_format;
vb@99
    22
vb@99
    23
typedef enum _PEP_msg_direction {
vb@99
    24
    PEP_dir_incoming = 0,
vb@99
    25
    PEP_dir_outgoing
vb@99
    26
} PEP_msg_direction;
vb@99
    27
vb@113
    28
typedef enum _PEP_MIME_format {
vb@113
    29
    PEP_MIME_none = 0,                      // message is not MIME encoded
vb@113
    30
    PEP_MIME_fields_omitted,                // message content but no fields
vb@113
    31
    PEP_MIME                                // message is fully MIME encoded
vb@113
    32
} PEP_MIME_format;
vb@113
    33
vb@99
    34
typedef enum _PEP_enc_format {
vb@113
    35
    PEP_enc_none = 0,                       // message is not encrypted
vb@112
    36
    PEP_enc_pieces,                         // inline PGP + PGP extensions
vb@113
    37
    PEP_enc_S_MIME,                         // RFC5751
vb@112
    38
    PEP_enc_PGP_MIME,                       // RFC3156
vb@99
    39
    PEP_enc_PEP                             // pEp encryption format
vb@99
    40
} PEP_enc_format;
vb@99
    41
vb@99
    42
struct _message_ref_list;
vb@99
    43
vb@99
    44
typedef struct _message {
vb@99
    45
    PEP_msg_direction dir;
vb@99
    46
    char *id;                               // UTF-8 string of message ID
vb@99
    47
    char *shortmsg;                         // UTF-8 string of short message
vb@99
    48
    char *longmsg;                          // UTF-8 string of long message
vb@99
    49
                                            // (plain)
vb@99
    50
    char *longmsg_formatted;                // UTF-8 string of long message
vb@99
    51
                                            // (formatted)
vb@99
    52
    bloblist_t *attachments;                // blobs with attachements
vb@99
    53
    char *rawmsg_ref;                       // reference to raw message data
vb@99
    54
    size_t rawmsg_size;                     // size of raw message data
vb@99
    55
    timestamp *sent;                        // when the message is sent
vb@99
    56
    timestamp *recv;                        // when the message is received
vb@99
    57
    pEp_identity *from;                     // whom the message is from
vb@99
    58
    identity_list *to;                      // whom the message is to
vb@99
    59
    pEp_identity *recv_by;                  // via which identity the message
vb@99
    60
                                            // is received
vb@99
    61
    identity_list *cc;                      // whom a CC is being sent
vb@99
    62
    identity_list *bcc;                     // whom a BCC is being sent
vb@99
    63
    identity_list *reply_to;                // where a reply should go to
vb@99
    64
    stringlist_t *in_reply_to;              // list of UTF-8 strings with
vb@99
    65
                                            // MessageIDs ofrefering messages
vb@99
    66
    struct _message *refering_msg_ref;      // reference to refering message
vb@99
    67
    stringlist_t *references;               // list of UTF-8 strings with references
vb@99
    68
    struct _message_ref_list *refered_by;   // list of references to messages being
vb@99
    69
                                            // refered
vb@99
    70
    stringlist_t *keywords;                 // list of UTF-8 strings with keywords
vb@99
    71
    char *comments;                         // UTF-8 string with comments
vb@99
    72
    stringpair_list_t *opt_fields;          // optional fields
vb@99
    73
    PEP_enc_format enc_format;              // format of encrypted data
vb@113
    74
    PEP_MIME_format mime;                   // if this is not PEP_MIME_none the
vb@113
    75
                                            // message content is in longmsg
vb@99
    76
} message;
vb@99
    77
vb@99
    78
typedef struct _message_ref_list {
vb@99
    79
    message *msg_ref;                       // reference to message
vb@99
    80
    struct _message_ref_list *next;
vb@99
    81
} message_ref_list;
vb@99
    82
vb@99
    83
vb@99
    84
// new_message() - allocate new message
vb@99
    85
//
vb@99
    86
//  parameters:
vb@99
    87
//      dir (in)        PEP_dir_incoming or PEP_dir_outgoing
vb@99
    88
//      from (in)       identity whom the message is from
vb@99
    89
//      to (in)         identity list whom the message is sent to
vb@99
    90
//      shortmsg (in)   UTF-8 string of short message
vb@99
    91
//
vb@99
    92
//  return value:
vb@99
    93
//      pointer to new message or NULL if out of memory
vb@99
    94
//
vb@99
    95
//  caveat:
vb@99
    96
//      from and to are moved into the message, the caller loses ownership for
vb@99
    97
//      them; shortmsg is being copied, the ownership of the original remains
vb@99
    98
//      with the caller
vb@99
    99
vb@99
   100
DYNAMIC_API message *new_message(
vb@99
   101
        PEP_msg_direction dir,
vb@99
   102
        pEp_identity *from,
vb@99
   103
        identity_list *to,
vb@99
   104
        const char *shortmsg
vb@99
   105
    );
vb@99
   106
vb@99
   107
vb@99
   108
// free_message() - free message struct
vb@99
   109
//
vb@99
   110
//  parameters:
vb@99
   111
//      src (in)        message struct to free
vb@99
   112
//
vb@99
   113
//  caveat:
vb@99
   114
//      raw data as well as referenced other messages aren't freed and remain
vb@99
   115
//      in the ownership of the caller
vb@99
   116
vb@99
   117
DYNAMIC_API void free_message(message *src);
vb@99
   118
vb@99
   119
vb@99
   120
// message_dup - duplicate message (deep copy)
vb@99
   121
//
vb@99
   122
//  parameters:
vb@99
   123
//      msg (in)        message to duplicate
vb@99
   124
//
vb@99
   125
//  return value:
vb@99
   126
//      pointer to duplicate of message pointed by msg or NULL
vb@99
   127
vb@99
   128
DYNAMIC_API message * message_dup(const message *msg);
vb@99
   129
vb@99
   130
// new_message_ref_list() - allocate new message reference list
vb@99
   131
//
vb@99
   132
//  parameters:
vb@99
   133
//      msg (in)        message to add a reference to or NULL
vb@99
   134
//
vb@99
   135
//  return value:
vb@99
   136
//      pointer to new message_ref_list or NULL if out of memory
vb@99
   137
vb@99
   138
DYNAMIC_API message_ref_list *new_message_ref_list(message *msg);
vb@99
   139
vb@99
   140
vb@99
   141
// free_message_ref_list() - free message reference list
vb@99
   142
//
vb@99
   143
//  parameters:
vb@99
   144
//      msg_list (in)   message_ref_list to free
vb@99
   145
vb@99
   146
DYNAMIC_API void free_message_ref_list(message_ref_list *msg_list);
vb@99
   147
vb@99
   148
vb@99
   149
// message_ref_list_dup() - duplicate message reference list
vb@99
   150
//
vb@99
   151
//  paramters:
vb@99
   152
//      src (in)        message_ref_list to duplicate
vb@99
   153
//
vb@99
   154
//  return value:
vb@99
   155
//      pointer to new message_ref_list or NULL if out of memory
vb@99
   156
vb@99
   157
DYNAMIC_API message_ref_list *message_ref_list_dup(
vb@99
   158
        const message_ref_list *src
vb@99
   159
    );
vb@99
   160
vb@99
   161
// message_ref_list_add() - add a reference to a message to a message reference
vb@99
   162
// list
vb@99
   163
//
vb@99
   164
//  parameters:
vb@99
   165
//      msg_list (in)   message_ref_list to add to
vb@99
   166
//      msg (in)        message to add a reference to
vb@99
   167
//
vb@99
   168
//  return value:
vb@99
   169
//      pointer to the last element of message_ref_list or NULL if out of
vb@99
   170
//      memory
vb@99
   171
vb@99
   172
DYNAMIC_API message_ref_list *message_ref_list_add(message_ref_list *msg_list,
vb@99
   173
        message *msg);
vb@99
   174
vb@99
   175
vb@99
   176
#ifdef __cplusplus
vb@99
   177
}
vb@99
   178
#endif
vb@99
   179