src/message_api.c
changeset 236 154a7077dbb7
parent 235 8b7468ca8034
child 237 62e817a8ea83
     1.1 --- a/src/message_api.c	Sun May 03 16:40:28 2015 +0200
     1.2 +++ b/src/message_api.c	Mon May 04 13:34:06 2015 +0200
     1.3 @@ -52,6 +52,7 @@
     1.4  
     1.5  void import_attached_keys(PEP_SESSION session, const message *msg)
     1.6  {
     1.7 +    assert(session);
     1.8      assert(msg);
     1.9  
    1.10      bloblist_t *bl;
    1.11 @@ -76,6 +77,34 @@
    1.12      }
    1.13  }
    1.14  
    1.15 +void attach_own_key(PEP_SESSION session, message *msg)
    1.16 +{
    1.17 +    char *keydata;
    1.18 +    size_t size;
    1.19 +    bloblist_t *bl;
    1.20 +
    1.21 +    assert(session);
    1.22 +    assert(msg);
    1.23 +
    1.24 +    if (msg->dir == PEP_dir_incoming)
    1.25 +        return;
    1.26 +
    1.27 +    assert(msg->from && msg->from->fpr);
    1.28 +    if (msg->from == NULL || msg->from->fpr == NULL)
    1.29 +        return;
    1.30 +
    1.31 +    PEP_STATUS status = export_key(session, msg->from->fpr, &keydata, &size);
    1.32 +    assert(status == PEP_STATUS_OK);
    1.33 +    if (status != PEP_STATUS_OK)
    1.34 +        return;
    1.35 +    assert(size);
    1.36 +
    1.37 +    bl = bloblist_add(msg->attachments, keydata, size, "application/pgp-keys",
    1.38 +            "pEp_key.asc");
    1.39 +    if (bl)
    1.40 +        msg->attachments = bl;
    1.41 +}
    1.42 +
    1.43  static char * combine_short_and_long(const char *shortmsg, const char *longmsg)
    1.44  {
    1.45      char * ptext;
    1.46 @@ -341,14 +370,14 @@
    1.47          }
    1.48      }
    1.49  
    1.50 +    status = myself(session, src->from);
    1.51 +    if (status != PEP_STATUS_OK)
    1.52 +        goto pep_error;
    1.53 +
    1.54      msg = clone_to_empty_message(src);
    1.55      if (msg == NULL)
    1.56          goto enomem;
    1.57  
    1.58 -    status = myself(session, src->from);
    1.59 -    if (status != PEP_STATUS_OK)
    1.60 -        goto pep_error;
    1.61 -
    1.62      keys = new_stringlist(src->from->fpr);
    1.63      if (keys == NULL)
    1.64          goto enomem;
    1.65 @@ -545,7 +574,7 @@
    1.66      if (msg->shortmsg == NULL)
    1.67          msg->shortmsg = strdup("pEp");
    1.68  
    1.69 -    import_attached_keys(session, msg);
    1.70 +    attach_own_key(session, msg);
    1.71  
    1.72      *dst = msg;
    1.73      return PEP_STATUS_OK;