...
7 DYNAMIC_API message *new_message(
14 message *msg = calloc(1, sizeof(message));
20 msg->shortmsg = strdup(shortmsg);
21 assert(msg->shortmsg);
22 if (msg->shortmsg == NULL) {
33 version.key = "X-pEp-Version";
34 version.value = PEP_VERSION;
36 msg->opt_fields = new_stringpair_list(&version);
37 if (msg->opt_fields == NULL) {
45 DYNAMIC_API void free_message(message *msg)
51 free(msg->longmsg_formatted);
52 free_bloblist(msg->attachments);
53 free_timestamp(msg->sent);
54 free_timestamp(msg->recv);
55 free_identity(msg->from);
56 free_identity_list(msg->to);
57 free_identity(msg->recv_by);
58 free_identity_list(msg->cc);
59 free_identity_list(msg->bcc);
60 free_identity_list(msg->reply_to);
61 free_stringlist(msg->in_reply_to);
62 free_stringlist(msg->references);
63 free_stringlist(msg->keywords);
65 free_stringpair_list(msg->opt_fields);
70 DYNAMIC_API message * message_dup(const message *src)
73 pEp_identity * from = NULL;
74 identity_list * to = NULL;
78 from = identity_dup(src->from);
82 to = identity_list_dup(src->to);
86 msg = new_message(src->dir, from, to, src->shortmsg);
91 msg->id = strdup(src->id);
98 msg->longmsg = strdup(src->longmsg);
100 if (msg->longmsg == NULL)
104 if (src->longmsg_formatted) {
105 msg->longmsg_formatted = strdup(src->longmsg_formatted);
106 assert(msg->longmsg_formatted);
107 if (msg->longmsg_formatted == NULL)
111 if (src->attachments) {
112 msg->attachments = bloblist_dup(src->attachments);
113 if (msg->attachments == NULL)
117 msg->rawmsg_ref = src->rawmsg_ref;
118 msg->rawmsg_size = src->rawmsg_size;
121 msg->sent = timestamp_dup(src->sent);
122 if (msg->sent == NULL)
127 msg->recv = timestamp_dup(src->recv);
128 if (msg->recv == NULL)
133 msg->recv_by = identity_dup(src->recv_by);
134 if (msg->recv_by == NULL)
139 msg->cc = identity_list_dup(src->cc);
145 msg->bcc = identity_list_dup(src->bcc);
146 if (msg->bcc == NULL)
151 msg->reply_to = identity_list_dup(src->reply_to);
152 if (msg->reply_to == NULL)
156 if (src->in_reply_to) {
157 msg->in_reply_to = stringlist_dup(src->in_reply_to);
158 assert(msg->in_reply_to);
159 if (msg->in_reply_to == NULL)
163 msg->refering_msg_ref = src->refering_msg_ref;
165 if (src->references) {
166 msg->references = stringlist_dup(src->references);
167 if (msg->references == NULL)
171 if (src->refered_by) {
172 msg->refered_by = message_ref_list_dup(src->refered_by);
173 if (msg->refered_by == NULL)
178 msg->keywords = stringlist_dup(src->keywords);
179 if (msg->keywords == NULL)
184 msg->comments = strdup(src->comments);
185 assert(msg->comments);
186 if (msg->comments == NULL)
190 if (src->opt_fields) {
191 msg->opt_fields = stringpair_list_dup(src->opt_fields);
192 if (msg->opt_fields == NULL)
196 msg->enc_format = src->enc_format;
206 free_identity_list(to);
212 DYNAMIC_API message_ref_list *new_message_ref_list(message *msg)
214 message_ref_list *msg_list = calloc(1, sizeof(message_ref_list));
216 if (msg_list == NULL)
219 msg_list->msg_ref = msg;
224 DYNAMIC_API void free_message_ref_list(message_ref_list *msg_list)
227 free_message_ref_list(msg_list->next);
232 DYNAMIC_API message_ref_list *message_ref_list_dup(
233 const message_ref_list *src
236 message_ref_list * msg_list = NULL;
240 msg_list = new_message_ref_list(src->msg_ref);
241 if (msg_list == NULL)
245 msg_list->next = message_ref_list_dup(src->next);
246 if (msg_list->next == NULL)
253 free_message_ref_list(msg_list);
257 DYNAMIC_API message_ref_list *message_ref_list_add(message_ref_list *msg_list, message *msg)
261 if (msg_list == NULL)
262 return new_message_ref_list(msg);
264 if (msg_list->msg_ref == NULL) {
265 msg_list->msg_ref = msg;
268 else if (msg_list->next == NULL) {
269 msg_list->next = new_message_ref_list(msg);
270 assert(msg_list->next);
271 return msg_list->next;
274 return message_ref_list_add(msg_list->next, msg);