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