1 #include "pEp_internal.h"
9 DYNAMIC_API message *new_message(
13 message *msg = calloc(1, sizeof(message));
23 DYNAMIC_API void free_message(message *msg)
29 free(msg->longmsg_formatted);
30 free_bloblist(msg->attachments);
31 free_timestamp(msg->sent);
32 free_timestamp(msg->recv);
33 free_identity(msg->from);
34 free_identity_list(msg->to);
35 free_identity(msg->recv_by);
36 free_identity_list(msg->cc);
37 free_identity_list(msg->bcc);
38 free_identity_list(msg->reply_to);
39 free_stringlist(msg->in_reply_to);
40 free_stringlist(msg->references);
41 free_stringlist(msg->keywords);
43 free_stringpair_list(msg->opt_fields);
48 DYNAMIC_API message * message_dup(const message *src)
51 pEp_identity * from = NULL;
52 identity_list * to = NULL;
56 msg = new_message(src->dir);
61 msg->id = strdup(src->id);
68 msg->shortmsg = strdup(src->shortmsg);
69 assert(msg->shortmsg);
70 if (msg->shortmsg == NULL)
75 msg->longmsg = strdup(src->longmsg);
77 if (msg->longmsg == NULL)
81 if (src->longmsg_formatted) {
82 msg->longmsg_formatted = strdup(src->longmsg_formatted);
83 assert(msg->longmsg_formatted);
84 if (msg->longmsg_formatted == NULL)
88 if (src->attachments) {
89 msg->attachments = bloblist_dup(src->attachments);
90 if (msg->attachments == NULL)
94 msg->rawmsg_ref = src->rawmsg_ref;
95 msg->rawmsg_size = src->rawmsg_size;
98 msg->sent = timestamp_dup(src->sent);
99 if (msg->sent == NULL)
104 msg->recv = timestamp_dup(src->recv);
105 if (msg->recv == NULL)
110 msg->from = identity_dup(src->from);
111 if (msg->from == NULL)
116 msg->recv_by = identity_dup(src->recv_by);
117 if (msg->recv_by == NULL)
122 msg->to = identity_list_dup(src->to);
128 msg->cc = identity_list_dup(src->cc);
134 msg->bcc = identity_list_dup(src->bcc);
135 if (msg->bcc == NULL)
140 msg->reply_to = identity_list_dup(src->reply_to);
141 if (msg->reply_to == NULL)
145 if (src->in_reply_to) {
146 msg->in_reply_to = stringlist_dup(src->in_reply_to);
147 assert(msg->in_reply_to);
148 if (msg->in_reply_to == NULL)
152 msg->refering_msg_ref = src->refering_msg_ref;
154 if (src->references) {
155 msg->references = stringlist_dup(src->references);
156 if (msg->references == NULL)
160 if (src->refered_by) {
161 msg->refered_by = message_ref_list_dup(src->refered_by);
162 if (msg->refered_by == NULL)
167 msg->keywords = stringlist_dup(src->keywords);
168 if (msg->keywords == NULL)
173 msg->comments = strdup(src->comments);
174 assert(msg->comments);
175 if (msg->comments == NULL)
179 if (src->opt_fields) {
180 msg->opt_fields = stringpair_list_dup(src->opt_fields);
181 if (msg->opt_fields == NULL)
185 msg->enc_format = src->enc_format;
195 free_identity_list(to);
201 DYNAMIC_API message_ref_list *new_message_ref_list(message *msg)
203 message_ref_list *msg_list = calloc(1, sizeof(message_ref_list));
205 if (msg_list == NULL)
208 msg_list->msg_ref = msg;
213 DYNAMIC_API void free_message_ref_list(message_ref_list *msg_list)
216 free_message_ref_list(msg_list->next);
221 DYNAMIC_API message_ref_list *message_ref_list_dup(
222 const message_ref_list *src
225 message_ref_list * msg_list = NULL;
229 msg_list = new_message_ref_list(src->msg_ref);
230 if (msg_list == NULL)
234 msg_list->next = message_ref_list_dup(src->next);
235 if (msg_list->next == NULL)
242 free_message_ref_list(msg_list);
246 DYNAMIC_API message_ref_list *message_ref_list_add(message_ref_list *msg_list, message *msg)
250 if (msg_list == NULL)
251 return new_message_ref_list(msg);
253 if (msg_list->msg_ref == NULL) {
254 msg_list->msg_ref = msg;
257 else if (msg_list->next == NULL) {
258 msg_list->next = new_message_ref_list(msg);
259 assert(msg_list->next);
260 return msg_list->next;
263 return message_ref_list_add(msg_list->next, msg);