src/message.h
author Volker Birk <vb@pep.foundation>
Tue, 27 Dec 2016 21:13:41 +0100
changeset 1513 e7f7e42385b5
parent 497 37a111f06c7f
child 1557 72aa4570d2c9
permissions -rw-r--r--
adding license info to each file
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
vb@99
    36
    PEP_enc_PEP                             // pEp encryption format
vb@99
    37
} PEP_enc_format;
vb@99
    38
vb@99
    39
struct _message_ref_list;
vb@99
    40
vb@99
    41
typedef struct _message {
vb@99
    42
    PEP_msg_direction dir;
vb@99
    43
    char *id;                               // UTF-8 string of message ID
vb@99
    44
    char *shortmsg;                         // UTF-8 string of short message
vb@99
    45
    char *longmsg;                          // UTF-8 string of long message
vb@99
    46
                                            // (plain)
vb@99
    47
    char *longmsg_formatted;                // UTF-8 string of long message
vb@99
    48
                                            // (formatted)
vb@99
    49
    bloblist_t *attachments;                // blobs with attachements
vb@497
    50
    char *rawmsg_ref;                       // reference to raw message data
vb@99
    51
    size_t rawmsg_size;                     // size of raw message data
vb@99
    52
    timestamp *sent;                        // when the message is sent
vb@99
    53
    timestamp *recv;                        // when the message is received
vb@99
    54
    pEp_identity *from;                     // whom the message is from
vb@99
    55
    identity_list *to;                      // whom the message is to
vb@99
    56
    pEp_identity *recv_by;                  // via which identity the message
vb@99
    57
                                            // is received
vb@99
    58
    identity_list *cc;                      // whom a CC is being sent
vb@99
    59
    identity_list *bcc;                     // whom a BCC is being sent
vb@99
    60
    identity_list *reply_to;                // where a reply should go to
vb@99
    61
    stringlist_t *in_reply_to;              // list of UTF-8 strings with
vb@351
    62
                                            // MessageIDs of refering messages
vb@99
    63
    struct _message *refering_msg_ref;      // reference to refering message
vb@99
    64
    stringlist_t *references;               // list of UTF-8 strings with references
vb@99
    65
    struct _message_ref_list *refered_by;   // list of references to messages being
vb@99
    66
                                            // refered
vb@99
    67
    stringlist_t *keywords;                 // list of UTF-8 strings with keywords
vb@99
    68
    char *comments;                         // UTF-8 string with comments
vb@99
    69
    stringpair_list_t *opt_fields;          // optional fields
vb@99
    70
    PEP_enc_format enc_format;              // format of encrypted data
vb@99
    71
} message;
vb@99
    72
vb@99
    73
typedef struct _message_ref_list {
vb@99
    74
    message *msg_ref;                       // reference to message
vb@99
    75
    struct _message_ref_list *next;
vb@99
    76
} message_ref_list;
vb@99
    77
vb@99
    78
vb@99
    79
// new_message() - allocate new message
vb@99
    80
//
vb@99
    81
//  parameters:
vb@99
    82
//      dir (in)        PEP_dir_incoming or PEP_dir_outgoing
vb@99
    83
//
vb@99
    84
//  return value:
vb@99
    85
//      pointer to new message or NULL if out of memory
vb@99
    86
vb@99
    87
DYNAMIC_API message *new_message(
vb@305
    88
        PEP_msg_direction dir
vb@99
    89
    );
vb@99
    90
vb@99
    91
vb@99
    92
// free_message() - free message struct
vb@99
    93
//
vb@99
    94
//  parameters:
vb@117
    95
//      msg (in)        message struct to free
vb@99
    96
//
roker@492
    97
//  NOTA BENE:
roker@492
    98
//      raw data (msg->rawmsg_ref) and referenced other messages (msg->refering_msg_ref)
roker@492
    99
//      aren't freed and remain in the ownership of the caller!
vb@99
   100
vb@117
   101
DYNAMIC_API void free_message(message *msg);
vb@99
   102
vb@99
   103
vb@99
   104
// message_dup - duplicate message (deep copy)
vb@99
   105
//
vb@99
   106
//  parameters:
vb@99
   107
//      msg (in)        message to duplicate
vb@99
   108
//
vb@99
   109
//  return value:
vb@99
   110
//      pointer to duplicate of message pointed by msg or NULL
roker@492
   111
//  NOTA BENE:
roker@492
   112
//      not owned pointees (msg->rawmsg_ref and msg->refering_msg_ref) are shared!
vb@99
   113
vb@99
   114
DYNAMIC_API message * message_dup(const message *msg);
vb@99
   115
vb@99
   116
// new_message_ref_list() - allocate new message reference list
vb@99
   117
//
vb@99
   118
//  parameters:
vb@99
   119
//      msg (in)        message to add a reference to or NULL
vb@99
   120
//
vb@99
   121
//  return value:
vb@99
   122
//      pointer to new message_ref_list or NULL if out of memory
vb@99
   123
vb@99
   124
DYNAMIC_API message_ref_list *new_message_ref_list(message *msg);
vb@99
   125
vb@99
   126
vb@99
   127
// free_message_ref_list() - free message reference list
vb@99
   128
//
vb@99
   129
//  parameters:
vb@99
   130
//      msg_list (in)   message_ref_list to free
vb@99
   131
vb@99
   132
DYNAMIC_API void free_message_ref_list(message_ref_list *msg_list);
vb@99
   133
vb@99
   134
vb@99
   135
// message_ref_list_dup() - duplicate message reference list
vb@99
   136
//
vb@99
   137
//  paramters:
vb@99
   138
//      src (in)        message_ref_list to duplicate
vb@99
   139
//
vb@99
   140
//  return value:
vb@99
   141
//      pointer to new message_ref_list or NULL if out of memory
vb@99
   142
vb@99
   143
DYNAMIC_API message_ref_list *message_ref_list_dup(
vb@99
   144
        const message_ref_list *src
vb@99
   145
    );
vb@99
   146
vb@99
   147
// message_ref_list_add() - add a reference to a message to a message reference
vb@99
   148
// list
vb@99
   149
//
vb@99
   150
//  parameters:
vb@99
   151
//      msg_list (in)   message_ref_list to add to
vb@99
   152
//      msg (in)        message to add a reference to
vb@99
   153
//
vb@99
   154
//  return value:
vb@99
   155
//      pointer to the last element of message_ref_list or NULL if out of
vb@99
   156
//      memory
vb@99
   157
vb@99
   158
DYNAMIC_API message_ref_list *message_ref_list_add(message_ref_list *msg_list,
vb@99
   159
        message *msg);
vb@99
   160
vb@99
   161
vb@99
   162
#ifdef __cplusplus
vb@99
   163
}
vb@99
   164
#endif
vb@99
   165