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