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);
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 = malloc(sizeof(timestamp));
123 if (msg->sent == NULL)
125 memcpy(msg->sent, src->sent, sizeof(timestamp));
129 msg->recv = malloc(sizeof(timestamp));
131 if (msg->recv == NULL)
133 memcpy(msg->recv, src->recv, sizeof(timestamp));
137 msg->recv_by = identity_dup(src->recv_by);
138 if (msg->recv_by == NULL)
143 msg->cc = identity_list_dup(src->cc);
149 msg->bcc = identity_list_dup(src->bcc);
150 if (msg->bcc == NULL)
155 msg->reply_to = identity_list_dup(src->reply_to);
156 if (msg->reply_to == NULL)
160 if (src->in_reply_to) {
161 msg->in_reply_to = stringlist_dup(src->in_reply_to);
162 assert(msg->in_reply_to);
163 if (msg->in_reply_to == NULL)
167 msg->refering_msg_ref = src->refering_msg_ref;
169 if (src->references) {
170 msg->references = stringlist_dup(src->references);
171 if (msg->references == NULL)
175 if (src->refered_by) {
176 msg->refered_by = message_ref_list_dup(src->refered_by);
177 if (msg->refered_by == NULL)
182 msg->keywords = stringlist_dup(src->keywords);
183 if (msg->keywords == NULL)
188 msg->comments = strdup(src->comments);
189 assert(msg->comments);
190 if (msg->comments == NULL)
194 if (src->opt_fields) {
195 msg->opt_fields = stringpair_list_dup(src->opt_fields);
196 if (msg->opt_fields == NULL)
200 msg->enc_format = src->enc_format;
210 free_identity_list(to);
216 DYNAMIC_API message_ref_list *new_message_ref_list(message *msg)
218 message_ref_list *msg_list = calloc(1, sizeof(message_ref_list));
220 if (msg_list == NULL)
223 msg_list->msg_ref = msg;
228 DYNAMIC_API void free_message_ref_list(message_ref_list *msg_list)
231 free_message_ref_list(msg_list->next);
236 DYNAMIC_API message_ref_list *message_ref_list_dup(
237 const message_ref_list *src
240 message_ref_list * msg_list = NULL;
244 msg_list = new_message_ref_list(src->msg_ref);
245 if (msg_list == NULL)
249 msg_list->next = message_ref_list_dup(src->next);
250 if (msg_list->next == NULL)
257 free_message_ref_list(msg_list);
261 DYNAMIC_API message_ref_list *message_ref_list_add(message_ref_list *msg_list, message *msg)
265 if (msg_list == NULL)
266 return new_message_ref_list(msg);
268 if (msg_list->msg_ref == NULL) {
269 msg_list->msg_ref = msg;
272 else if (msg_list->next == NULL) {
273 msg_list->next = new_message_ref_list(msg);
274 assert(msg_list->next);
275 return msg_list->next;
278 return message_ref_list_add(msg_list->next, msg);