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