src/mime.c
changeset 91 00c67be2d56d
parent 90 42b5eb9d5af2
child 93 6f3f781caaa0
     1.1 --- a/src/mime.c	Sun Mar 08 00:35:18 2015 +0100
     1.2 +++ b/src/mime.c	Sun Mar 08 11:58:26 2015 +0100
     1.3 @@ -307,6 +307,34 @@
     1.4      return NULL;
     1.5  }
     1.6  
     1.7 +static clist * clist_from_stringlist(stringlist_t *sl)
     1.8 +{
     1.9 +    clist * cl = clist_new();
    1.10 +    assert(cl);
    1.11 +    if (cl == NULL)
    1.12 +        return NULL;
    1.13 +
    1.14 +    stringlist_t *_sl;
    1.15 +    for (_sl = sl; _sl; _sl = _sl->next) {
    1.16 +        int r;
    1.17 +        char * value = strdup(_sl->value);
    1.18 +        assert(value);
    1.19 +        if (value == NULL) {
    1.20 +            clist_free(cl);
    1.21 +            return NULL;
    1.22 +        }
    1.23 +        r = clist_append(cl, value);
    1.24 +        assert(r == 0);
    1.25 +        if (r) {
    1.26 +            free(value);
    1.27 +            clist_free(cl);
    1.28 +            return NULL;
    1.29 +        }
    1.30 +    }
    1.31 +
    1.32 +    return cl;
    1.33 +}
    1.34 +
    1.35  static PEP_STATUS build_fields(const message *msg, struct mailimf_fields **result)
    1.36  {
    1.37      PEP_STATUS status = PEP_STATUS_OK;
    1.38 @@ -367,7 +395,7 @@
    1.39          dt = NULL;
    1.40      }
    1.41  
    1.42 -    if (msg->from) {
    1.43 +    /* if (msg->from) */ {
    1.44          struct mailimf_mailbox_list *from = mbl_from_identity(msg->from);
    1.45          if (from == NULL)
    1.46              goto enomem;
    1.47 @@ -385,7 +413,7 @@
    1.48          if (to == NULL)
    1.49              goto enomem;
    1.50  
    1.51 -        r = _append_field(fields_list, MAILIMF_FIELD_FROM,
    1.52 +        r = _append_field(fields_list, MAILIMF_FIELD_TO,
    1.53                  (_new_func_t) mailimf_to_new, to);
    1.54          if (r) {
    1.55              mailimf_mailbox_list_free(to);
    1.56 @@ -393,6 +421,97 @@
    1.57          }
    1.58      }
    1.59  
    1.60 +    if (msg->cc) {
    1.61 +        struct mailimf_mailbox_list *cc = mbl_from_identity_list(msg->cc);
    1.62 +        if (cc == NULL)
    1.63 +            goto enomem;
    1.64 +
    1.65 +        r = _append_field(fields_list, MAILIMF_FIELD_CC,
    1.66 +                (_new_func_t) mailimf_cc_new, cc);
    1.67 +        if (r) {
    1.68 +            mailimf_mailbox_list_free(cc);
    1.69 +            goto enomem;
    1.70 +        }
    1.71 +    }
    1.72 +    
    1.73 +    if (msg->bcc) {
    1.74 +        struct mailimf_mailbox_list *bcc = mbl_from_identity_list(msg->bcc);
    1.75 +        if (bcc == NULL)
    1.76 +            goto enomem;
    1.77 +
    1.78 +        r = _append_field(fields_list, MAILIMF_FIELD_BCC,
    1.79 +                (_new_func_t) mailimf_bcc_new, bcc);
    1.80 +        if (r) {
    1.81 +            mailimf_mailbox_list_free(bcc);
    1.82 +            goto enomem;
    1.83 +        }
    1.84 +    }
    1.85 +    
    1.86 +    if (msg->reply_to) {
    1.87 +        struct mailimf_mailbox_list *reply_to= mbl_from_identity(msg->reply_to);
    1.88 +        if (reply_to == NULL)
    1.89 +            goto enomem;
    1.90 +
    1.91 +        r = _append_field(fields_list, MAILIMF_FIELD_REPLY_TO,
    1.92 +                (_new_func_t) mailimf_reply_to_new, reply_to);
    1.93 +        if (r) {
    1.94 +            mailimf_mailbox_list_free(reply_to);
    1.95 +            goto enomem;
    1.96 +        }
    1.97 +    }
    1.98 +
    1.99 +    if (msg->in_reply_to) {
   1.100 +        char *in_reply_to = strdup(msg->in_reply_to);
   1.101 +        if (in_reply_to == NULL)
   1.102 +            goto enomem;
   1.103 +
   1.104 +        r = _append_field(fields_list, MAILIMF_FIELD_IN_REPLY_TO,
   1.105 +                (_new_func_t) mailimf_in_reply_to_new, in_reply_to);
   1.106 +        if (r) {
   1.107 +            free(in_reply_to);
   1.108 +            goto enomem;
   1.109 +        }
   1.110 +    }
   1.111 +
   1.112 +    if (msg->references) {
   1.113 +        clist *references = clist_from_stringlist(msg->references);
   1.114 +        if (references == NULL)
   1.115 +            goto enomem;
   1.116 +
   1.117 +        r = _append_field(fields_list, MAILIMF_FIELD_REFERENCES,
   1.118 +                (_new_func_t) mailimf_references_new, references);
   1.119 +        if (r) {
   1.120 +            clist_free(references);
   1.121 +            goto enomem;
   1.122 +        }
   1.123 +    }
   1.124 +
   1.125 +    if (msg->keywords) {
   1.126 +        clist *keywords = clist_from_stringlist(msg->keywords);
   1.127 +        if (keywords == NULL)
   1.128 +            goto enomem;
   1.129 +
   1.130 +        r = _append_field(fields_list, MAILIMF_FIELD_KEYWORDS,
   1.131 +                (_new_func_t) mailimf_keywords_new, keywords);
   1.132 +        if (r) {
   1.133 +            clist_free(keywords);
   1.134 +            goto enomem;
   1.135 +        }
   1.136 +    }
   1.137 +
   1.138 +    if (msg->comments) {
   1.139 +        char *comments = strdup(msg->comments);
   1.140 +        if (comments == NULL)
   1.141 +            goto enomem;
   1.142 +
   1.143 +        r = _append_field(fields_list, MAILIMF_FIELD_COMMENTS,
   1.144 +                (_new_func_t) mailimf_comments_new, comments);
   1.145 +        if (r) {
   1.146 +            free(comments);
   1.147 +            goto enomem;
   1.148 +        }
   1.149 +    }
   1.150 +
   1.151      fields = mailimf_fields_new(fields_list);
   1.152      assert(fields);
   1.153      if (fields == NULL)