src/message.h
author Krista Bennett <krista@pep-project.org>
Fri, 27 Oct 2017 20:02:41 +0200
branchENGINE-293
changeset 2219 99b05a2f117e
parent 2147 22394e4b5047
child 2388 40cadfd425bb
permissions -rw-r--r--
shelving changes
     1 // This file is under GNU General Public License 3.0
     2 // see LICENSE.txt
     3 
     4 #pragma once
     5 
     6 #include <time.h>
     7 
     8 #include "pEpEngine.h"
     9 #include "identity_list.h"
    10 #include "bloblist.h"
    11 #include "stringlist.h"
    12 #include "stringpair.h"
    13 #include "timestamp.h"
    14 
    15 #ifdef __cplusplus
    16 extern "C" {
    17 #endif
    18 
    19 
    20 typedef enum _PEP_text_format {
    21     PEP_text_format_plain = 0,
    22     PEP_text_format_html,
    23     PEP_text_format_other = 0xff
    24 } PEP_text_format;
    25 
    26 typedef enum _PEP_msg_direction {
    27     PEP_dir_incoming = 0,
    28     PEP_dir_outgoing
    29 } PEP_msg_direction;
    30 
    31 typedef enum _PEP_enc_format {
    32     PEP_enc_none = 0,                       // message is not encrypted
    33     PEP_enc_pieces,                         // inline PGP + PGP extensions
    34     PEP_enc_S_MIME,                         // RFC5751
    35     PEP_enc_PGP_MIME,                       // RFC3156
    36     PEP_enc_PEP,                            // pEp encryption format
    37     PEP_enc_PGP_MIME_Outlook1               // Message B0rken by Outlook type 1
    38 } PEP_enc_format;
    39 
    40 struct _message_ref_list;
    41 
    42 typedef struct _message {
    43     PEP_msg_direction dir;
    44     char *id;                               // UTF-8 string of message ID
    45     bool me;                                // true if own identity
    46     char *shortmsg;                         // UTF-8 string of short message
    47     char *longmsg;                          // UTF-8 string of long message
    48                                             // (plain)
    49     char *longmsg_formatted;                // UTF-8 string of long message
    50                                             // (formatted)
    51     bloblist_t *attachments;                // blobs with attachements
    52     char *rawmsg_ref;                       // reference to raw message data
    53     size_t rawmsg_size;                     // size of raw message data
    54     timestamp *sent;                        // when the message is sent
    55     timestamp *recv;                        // when the message is received
    56     pEp_identity *from;                     // whom the message is from
    57     identity_list *to;                      // whom the message is to
    58     pEp_identity *recv_by;                  // via which identity the message
    59                                             // is received
    60     identity_list *cc;                      // whom a CC is being sent
    61     identity_list *bcc;                     // whom a BCC is being sent
    62     identity_list *reply_to;                // where a reply should go to
    63     stringlist_t *in_reply_to;              // list of UTF-8 strings with
    64                                             // MessageIDs of refering messages
    65     struct _message *refering_msg_ref;      // reference to refering message
    66     stringlist_t *references;               // list of UTF-8 strings with references
    67     struct _message_ref_list *refered_by;   // list of references to messages being
    68                                             // refered
    69     stringlist_t *keywords;                 // list of UTF-8 strings with keywords
    70     char *comments;                         // UTF-8 string with comments
    71     stringpair_list_t *opt_fields;          // optional fields
    72     PEP_enc_format enc_format;              // format of encrypted data
    73 } message;
    74 
    75 typedef struct _message_ref_list {
    76     message *msg_ref;                       // reference to message
    77     struct _message_ref_list *next;
    78 } message_ref_list;
    79 
    80 
    81 // new_message() - allocate new message
    82 //
    83 //  parameters:
    84 //      dir (in)        PEP_dir_incoming or PEP_dir_outgoing
    85 //
    86 //  return value:
    87 //      pointer to new message or NULL if out of memory
    88 
    89 DYNAMIC_API message *new_message(
    90         PEP_msg_direction dir
    91     );
    92 
    93 
    94 // free_message() - free message struct
    95 //
    96 //  parameters:
    97 //      msg (in)        message struct to free
    98 //
    99 //  NOTA BENE:
   100 //      raw data (msg->rawmsg_ref) and referenced other messages (msg->refering_msg_ref)
   101 //      aren't freed and remain in the ownership of the caller!
   102 
   103 DYNAMIC_API void free_message(message *msg);
   104 
   105 
   106 // message_dup - duplicate message (deep copy)
   107 //
   108 //  parameters:
   109 //      msg (in)        message to duplicate
   110 //
   111 //  return value:
   112 //      pointer to duplicate of message pointed by msg or NULL
   113 //  NOTA BENE:
   114 //      not owned pointees (msg->rawmsg_ref and msg->refering_msg_ref) are shared!
   115 
   116 DYNAMIC_API message * message_dup(const message *msg);
   117 
   118 // new_message_ref_list() - allocate new message reference list
   119 //
   120 //  parameters:
   121 //      msg (in)        message to add a reference to or NULL
   122 //
   123 //  return value:
   124 //      pointer to new message_ref_list or NULL if out of memory
   125 
   126 DYNAMIC_API message_ref_list *new_message_ref_list(message *msg);
   127 
   128 
   129 // free_message_ref_list() - free message reference list
   130 //
   131 //  parameters:
   132 //      msg_list (in)   message_ref_list to free
   133 
   134 DYNAMIC_API void free_message_ref_list(message_ref_list *msg_list);
   135 
   136 
   137 // message_ref_list_dup() - duplicate message reference list
   138 //
   139 //  paramters:
   140 //      src (in)        message_ref_list to duplicate
   141 //
   142 //  return value:
   143 //      pointer to new message_ref_list or NULL if out of memory
   144 
   145 DYNAMIC_API message_ref_list *message_ref_list_dup(
   146         const message_ref_list *src
   147     );
   148 
   149 // message_ref_list_add() - add a reference to a message to a message reference
   150 // list
   151 //
   152 //  parameters:
   153 //      msg_list (in)   message_ref_list to add to
   154 //      msg (in)        message to add a reference to
   155 //
   156 //  return value:
   157 //      pointer to the last element of message_ref_list or NULL if out of
   158 //      memory
   159 
   160 DYNAMIC_API message_ref_list *message_ref_list_add(message_ref_list *msg_list,
   161         message *msg);
   162 
   163 
   164 #ifdef __cplusplus
   165 }
   166 #endif