1 #include "pEp_internal.h"
2 #include "message_api.h"
12 #define MIN(A, B) ((B) > (A) ? (A) : (B))
15 #define MAX(A, B) ((B) > (A) ? (B) : (A))
19 static bool string_equality(const char *s1, const char *s2)
21 if (s1 == NULL || s2 == NULL)
26 return strcmp(s1, s2) == 0;
29 static bool is_mime_type(const bloblist_t *bl, const char *mt)
33 return bl && string_equality(bl->mime_type, mt);
36 static bool is_fileending(const bloblist_t *bl, const char *fe)
40 if (bl == NULL || bl->filename == NULL)
43 assert(bl && bl->filename);
45 size_t fe_len = strlen(fe);
46 size_t fn_len = strlen(bl->filename);
51 assert(fn_len > fe_len);
53 return strcmp(bl->filename + (fn_len - fe_len), fe) == 0;
56 static void add_opt_field(message *msg, const char *name, const char *value)
60 if (msg && name && value) {
61 stringpair_t *pair = new_stringpair(name, value);
65 stringpair_list_t *field = stringpair_list_add(msg->opt_fields, pair);
69 if (msg->opt_fields == NULL)
70 msg->opt_fields = field;
74 static char * combine_short_and_long(const char *shortmsg, const char *longmsg)
79 assert(strcmp(shortmsg, "pEp") != 0);
84 ptext = calloc(1, strlen(shortmsg) + strlen(longmsg) + 12);
89 strcpy(ptext, "Subject: ");
90 strcat(ptext, shortmsg);
91 strcat(ptext, "\n\n");
92 strcat(ptext, longmsg);
97 static int seperate_short_and_long(const char *src, char **shortmsg, char **longmsg)
99 char *_shortmsg = NULL;
100 char *_longmsg = NULL;
109 if (strncasecmp(src, "subject: ", 9) == 0) {
110 char *line_end = strchr(src, '\n');
112 if (line_end == NULL) {
113 _shortmsg = strdup(src + 9);
114 if (_shortmsg == NULL)
119 size_t n = line_end - src;
121 if (*(line_end - 1) == '\r')
122 _shortmsg = strndup(src + 9, n - 10);
124 _shortmsg = strndup(src + 9, n - 9);
126 if (_shortmsg == NULL)
129 while (*(src + n) && (*(src + n) == '\n' || *(src + n) == '\r'))
133 _longmsg = strdup(src + n);
134 if (_longmsg == NULL)
140 _shortmsg = strdup("");
141 if (_shortmsg == NULL)
143 _longmsg = strdup(src);
144 if (_longmsg == NULL)
148 *shortmsg = _shortmsg;
160 static PEP_STATUS copy_fields(message *dst, const message *src)
165 free_timestamp(dst->sent);
168 dst->sent = timestamp_dup(src->sent);
169 if (dst->sent == NULL)
170 return PEP_OUT_OF_MEMORY;
173 free_timestamp(dst->recv);
176 dst->recv = timestamp_dup(src->recv);
177 if (dst->recv == NULL)
178 return PEP_OUT_OF_MEMORY;
181 free_identity(dst->from);
184 dst->from = identity_dup(src->from);
185 if (dst->from == NULL)
186 return PEP_OUT_OF_MEMORY;
189 free_identity_list(dst->to);
191 if (src->to && src->to->ident) {
192 dst->to = identity_list_dup(src->to);
194 return PEP_OUT_OF_MEMORY;
197 free_identity(dst->recv_by);
200 dst->recv_by = identity_dup(src->recv_by);
201 if (dst->recv_by == NULL)
202 return PEP_OUT_OF_MEMORY;
205 free_identity_list(dst->cc);
207 if (src->cc && src->cc->ident) {
208 dst->cc = identity_list_dup(src->cc);
210 return PEP_OUT_OF_MEMORY;
213 free_identity_list(dst->bcc);
215 if (src->bcc && src->bcc->ident) {
216 dst->bcc = identity_list_dup(src->bcc);
217 if (dst->bcc == NULL)
218 return PEP_OUT_OF_MEMORY;
221 free_identity_list(dst->reply_to);
222 dst->reply_to = NULL;
223 if (src->reply_to && src->reply_to->ident) {
224 dst->reply_to = identity_list_dup(src->reply_to);
225 if (dst->reply_to == NULL)
226 return PEP_OUT_OF_MEMORY;
229 free_stringlist(dst->in_reply_to);
230 dst->in_reply_to = NULL;
231 if (src->in_reply_to && src->in_reply_to->value) {
232 dst->in_reply_to = stringlist_dup(src->in_reply_to);
233 if (dst->in_reply_to == NULL)
234 return PEP_OUT_OF_MEMORY;
237 free_stringlist(dst->references);
238 dst->references = NULL;
239 if (src->references) {
240 dst->references = stringlist_dup(src->references);
241 if (dst->references == NULL)
242 return PEP_OUT_OF_MEMORY;
245 free_stringlist(dst->keywords);
246 dst->keywords = NULL;
247 if (src->keywords && src->keywords->value) {
248 dst->keywords = stringlist_dup(src->keywords);
249 if (dst->keywords == NULL)
250 return PEP_OUT_OF_MEMORY;
254 dst->comments = NULL;
256 dst->comments = strdup(src->comments);
257 assert(dst->comments);
258 if (dst->comments == NULL)
259 return PEP_OUT_OF_MEMORY;
262 return PEP_STATUS_OK;
265 static message * clone_to_empty_message(const message * src)
268 message * msg = NULL;
272 msg = calloc(1, sizeof(message));
279 status = copy_fields(msg, src);
280 if (status != PEP_STATUS_OK)
290 static PEP_STATUS encrypt_PGP_MIME(
297 PEP_STATUS status = PEP_STATUS_OK;
298 bool free_ptext = false;
302 char *mimetext = NULL;
304 assert(dst->longmsg == NULL);
305 dst->enc_format = PEP_enc_PGP_MIME;
307 if (src->shortmsg && strcmp(src->shortmsg, "pEp") != 0) {
308 ptext = combine_short_and_long(src->shortmsg, src->longmsg);
313 else if (src->longmsg) {
314 ptext = src->longmsg;
320 message *_src = calloc(1, sizeof(message));
324 _src->longmsg = ptext;
325 _src->longmsg_formatted = src->longmsg_formatted;
326 _src->attachments = src->attachments;
327 _src->enc_format = PEP_enc_none;
328 status = mime_encode_message(_src, true, &mimetext);
329 assert(status == PEP_STATUS_OK);
334 if (mimetext == NULL)
337 status = encrypt_and_sign(session, keys, mimetext, strlen(mimetext),
343 dst->longmsg = strdup("this message was encrypted with p≡p "
344 "http://pEp-project.org");
345 if (dst->longmsg == NULL)
348 char *v = strdup("Version: 1");
352 bloblist_t *_a = new_bloblist(v, 11, "application/pgp-encrypted", NULL);
355 dst->attachments = _a;
357 _ctext = malloc(csize);
361 memcpy(_ctext, ctext, csize);
363 _a = bloblist_add(_a, _ctext, csize, "application/octet-stream",
368 return PEP_STATUS_OK;
371 status = PEP_OUT_OF_MEMORY;
380 static PEP_STATUS encrypt_PGP_in_pieces(
387 PEP_STATUS status = PEP_STATUS_OK;
391 assert(dst->longmsg == NULL);
392 assert(dst->attachments == NULL);
394 dst->enc_format = PEP_enc_pieces;
396 if (src->shortmsg && src->shortmsg[0] && strcmp(src->shortmsg, "pEp") != 0) {
397 char *ptext = combine_short_and_long(src->shortmsg, src->longmsg);
401 status = encrypt_and_sign(session, keys, ptext, strlen(ptext), &ctext,
405 dst->longmsg = strndup(ctext, csize);
406 assert(dst->longmsg);
407 if (dst->longmsg == NULL)
414 else if (src->longmsg && src->longmsg[0]) {
415 char *ptext = src->longmsg;
416 status = encrypt_and_sign(session, keys, ptext, strlen(ptext), &ctext,
419 dst->longmsg = strndup(ctext, csize);
420 assert(dst->longmsg);
421 if (dst->longmsg == NULL)
429 dst->longmsg = strdup("");
430 if (dst->longmsg == NULL)
434 if (src->longmsg_formatted && src->longmsg_formatted[0]) {
435 char *ptext = src->longmsg_formatted;
436 status = encrypt_and_sign(session, keys, ptext, strlen(ptext), &ctext,
439 char *_ctext = malloc(csize);
443 memcpy(_ctext, ctext, csize);
445 bloblist_t *_a = bloblist_add(dst->attachments, _ctext, csize,
446 "application/octet-stream", "PGPexch.htm.pgp");
449 if (dst->attachments == NULL)
450 dst->attachments = _a;
457 if (src->attachments) {
458 if (dst->attachments == NULL) {
459 dst->attachments = new_bloblist(NULL, 0, NULL, NULL);
460 if (dst->attachments == NULL)
464 bloblist_t *_s = src->attachments;
465 bloblist_t *_d = dst->attachments;
467 for (int n = 0; _s && _s->value; _s = _s->next) {
468 size_t psize = _s->size;
469 char *ptext = _s->value;
470 status = encrypt_and_sign(session, keys, ptext, psize, &ctext,
473 char *filename = NULL;
476 size_t len = strlen(_s->filename);
477 filename = calloc(1, len + 5);
478 if (filename == NULL)
481 strcpy(filename, _s->filename);
482 strcpy(filename + len, ".pgp");
485 filename = calloc(1, 20);
486 if (filename == NULL)
491 snprintf(filename, 20, "Attachment%d.pgp", n);
494 char *_ctext = malloc(csize);
498 memcpy(_ctext, ctext, csize);
500 _d = bloblist_add(_d, _ctext, csize, "application/octet-stream",
511 return PEP_STATUS_OK;
514 status = PEP_OUT_OF_MEMORY;
520 static char * keylist_to_string(const stringlist_t *keylist)
523 size_t size = stringlist_length(keylist);
525 const stringlist_t *_kl;
526 for (_kl = keylist; _kl && _kl->value; _kl = _kl->next) {
527 size += strlen(_kl->value);
530 char *result = calloc(1, size);
535 for (_kl = keylist; _kl && _kl->value; _kl = _kl->next) {
536 _r = stpcpy(_r, _kl->value);
537 if (_kl->next && _kl->next->value)
538 _r = stpcpy(_r, ",");
548 static const char * color_to_string(PEP_color color)
551 case PEP_rating_cannot_decrypt:
552 return "cannot_decrypt";
553 case PEP_rating_have_no_key:
554 return "have_no_key";
555 case PEP_rating_unencrypted:
556 return "unencrypted";
557 case PEP_rating_unreliable:
559 case PEP_rating_reliable:
561 case PEP_rating_trusted:
563 case PEP_rating_trusted_and_anonymized:
564 return "trusted_and_anonymized";
565 case PEP_rating_fully_anonymous:
566 return "fully_anonymous";
567 case PEP_rating_under_attack:
568 return "unter_attack";
569 case PEP_rating_b0rken:
576 static void decorate_message(
579 stringlist_t *keylist
584 add_opt_field(msg, "X-pEp-Version", "1.0");
586 if (color != PEP_rating_undefined)
587 add_opt_field(msg, "X-EncStatus", color_to_string(color));
590 char *_keylist = keylist_to_string(keylist);
591 add_opt_field(msg, "X-KeyList", _keylist);
596 static PEP_color _rating(PEP_comm_type ct)
598 if (ct == PEP_ct_unknown)
599 return PEP_rating_undefined;
601 else if (ct == PEP_ct_compromized)
602 return PEP_rating_under_attack;
604 else if (ct >= PEP_ct_confirmed_enc_anon)
605 return PEP_rating_trusted_and_anonymized;
607 else if (ct >= PEP_ct_strong_encryption)
608 return PEP_rating_trusted;
610 else if (ct >= PEP_ct_strong_but_unconfirmed && ct < PEP_ct_confirmed)
611 return PEP_rating_reliable;
613 else if (ct == PEP_ct_no_encryption || ct == PEP_ct_no_encrypted_channel)
614 return PEP_rating_unencrypted;
617 return PEP_rating_unreliable;
620 static bool is_encrypted_attachment(const bloblist_t *blob)
626 if (blob->filename == NULL)
629 ext = strrchr(blob->filename, '.');
633 if (strcmp(blob->mime_type, "application/octet-stream") == 0) {
634 if (strcmp(ext, ".pgp") == 0 || strcmp(ext, ".gpg") == 0 ||
635 strcmp(ext, ".asc") == 0)
638 else if (strcmp(blob->mime_type, "text/plain") == 0) {
639 if (strcmp(ext, ".asc") == 0)
646 static bool is_encrypted_html_attachment(const bloblist_t *blob)
649 assert(blob->filename);
651 if (strncmp(blob->filename, "PGPexch.htm.", 12) == 0) {
652 if (strcmp(blob->filename + 11, ".pgp") == 0 ||
653 strcmp(blob->filename + 11, ".asc") == 0)
660 static char * without_double_ending(const char *filename)
666 ext = strrchr(filename, '.');
670 return strndup(filename, ext - filename);
673 static PEP_color decrypt_color(PEP_STATUS status)
676 case PEP_UNENCRYPTED:
678 case PEP_VERIFY_NO_KEY:
679 case PEP_VERIFIED_AND_TRUSTED:
680 return PEP_rating_unencrypted;
683 return PEP_rating_unreliable;
685 case PEP_DECRYPTED_AND_VERIFIED:
686 return PEP_rating_reliable;
688 case PEP_DECRYPT_NO_KEY:
689 return PEP_rating_have_no_key;
691 case PEP_DECRYPT_WRONG_FORMAT:
692 case PEP_CANNOT_DECRYPT_UNKNOWN:
693 return PEP_rating_cannot_decrypt;
696 return PEP_rating_undefined;
700 static PEP_color key_color(PEP_SESSION session, const char *fpr)
702 PEP_comm_type comm_type = PEP_ct_unknown;
707 PEP_STATUS status = get_key_rating(session, fpr, &comm_type);
708 if (status != PEP_STATUS_OK)
709 return PEP_rating_undefined;
711 return _rating(comm_type);
714 static PEP_color keylist_color(PEP_SESSION session, stringlist_t *keylist)
716 PEP_color color = PEP_rating_reliable;
718 assert(keylist && keylist->value);
719 if (keylist == NULL || keylist->value == NULL)
720 return PEP_rating_unencrypted;
723 for (_kl = keylist; _kl && _kl->value; _kl = _kl->next) {
727 color = key_color(session, _kl->value);
728 if (color == PEP_rating_under_attack)
729 return PEP_rating_under_attack;
731 if (color >= PEP_rating_reliable) {
732 status = least_trust(session, _kl->value, &ct);
733 if (status != PEP_STATUS_OK)
734 return PEP_rating_undefined;
735 if (ct == PEP_ct_unknown)
736 color = PEP_rating_unreliable;
745 static PEP_comm_type _get_comm_type(
747 PEP_comm_type max_comm_type,
751 PEP_STATUS status = update_identity(session, ident);
753 if (max_comm_type == PEP_ct_compromized)
754 return PEP_ct_compromized;
756 if (status == PEP_STATUS_OK) {
757 if (ident->comm_type == PEP_ct_compromized)
758 return PEP_ct_compromized;
760 return MIN(max_comm_type, ident->comm_type);
763 return PEP_ct_unknown;
767 void import_attached_keys(PEP_SESSION session, const message *msg)
773 for (bl = msg->attachments; bl && bl->value; bl = bl->next) {
774 assert(bl && bl->value && bl->size);
776 if (bl->mime_type == NULL ||
777 is_mime_type(bl, "application/octet-stream")) {
778 if (is_fileending(bl, ".pgp") || is_fileending(bl, ".gpg") ||
779 is_fileending(bl, ".key") ||
780 string_equality(bl->filename, "key.asc"))
781 import_key(session, bl->value, bl->size);
783 else if (is_mime_type(bl, "application/pgp-keys")) {
784 import_key(session, bl->value, bl->size);
786 else if (is_mime_type(bl, "text/plain")) {
787 if (is_fileending(bl, ".pgp") || is_fileending(bl, ".gpg") ||
788 is_fileending(bl, ".key") || is_fileending(bl, ".asc"))
789 import_key(session, bl->value, bl->size);
794 void attach_own_key(PEP_SESSION session, message *msg)
803 if (msg->dir == PEP_dir_incoming)
806 assert(msg->from && msg->from->fpr);
807 if (msg->from == NULL || msg->from->fpr == NULL)
810 PEP_STATUS status = export_key(session, msg->from->fpr, &keydata, &size);
811 assert(status == PEP_STATUS_OK);
812 if (status != PEP_STATUS_OK)
816 bl = bloblist_add(msg->attachments, keydata, size, "application/pgp-keys",
818 if (msg->attachments == NULL && bl)
819 msg->attachments = bl;
822 PEP_cryptotech determine_encryption_format(message *msg)
826 if (is_PGP_message_text(msg->longmsg)) {
827 msg->enc_format = PEP_enc_pieces;
828 return PEP_crypt_OpenPGP;
830 else if (msg->attachments && msg->attachments->next &&
831 is_mime_type(msg->attachments, "application/pgp-encrypted") &&
832 is_PGP_message_text(msg->attachments->next->value)
834 msg->enc_format = PEP_enc_PGP_MIME;
835 return PEP_crypt_OpenPGP;
838 msg->enc_format = PEP_enc_none;
839 return PEP_crypt_none;
843 DYNAMIC_API PEP_STATUS encrypt_message(
846 stringlist_t * extra,
848 PEP_enc_format enc_format
851 PEP_STATUS status = PEP_STATUS_OK;
852 message * msg = NULL;
853 stringlist_t * keys = NULL;
858 assert(enc_format != PEP_enc_none);
860 if (!(session && src && dst && enc_format != PEP_enc_none))
861 return PEP_ILLEGAL_VALUE;
863 determine_encryption_format(src);
864 if (src->enc_format != PEP_enc_none)
865 return PEP_ILLEGAL_VALUE;
869 status = myself(session, src->from);
870 if (status != PEP_STATUS_OK)
873 keys = new_stringlist(src->from->fpr);
877 stringlist_t *_k = keys;
880 _k = stringlist_append(_k, extra);
885 bool dest_keys_found = true;
888 for (_il = src->to; _il && _il->ident; _il = _il->next) {
889 PEP_STATUS _status = update_identity(session, _il->ident);
890 if (_status != PEP_STATUS_OK) {
895 if (_il->ident->fpr && _il->ident->fpr[0]) {
896 _k = stringlist_add(_k, _il->ident->fpr);
901 dest_keys_found = false;
902 status = PEP_KEY_NOT_FOUND;
906 for (_il = src->cc; _il && _il->ident; _il = _il->next) {
907 PEP_STATUS _status = update_identity(session, _il->ident);
908 if (_status != PEP_STATUS_OK)
914 if (_il->ident->fpr && _il->ident->fpr[0]) {
915 _k = stringlist_add(_k, _il->ident->fpr);
920 dest_keys_found = false;
921 status = PEP_KEY_NOT_FOUND;
925 if (!dest_keys_found) {
926 free_stringlist(keys);
927 attach_own_key(session, src);
928 return PEP_UNENCRYPTED;
931 msg = clone_to_empty_message(src);
935 switch (enc_format) {
936 case PEP_enc_PGP_MIME:
937 case PEP_enc_PEP: // BUG: should be implemented extra
938 status = encrypt_PGP_MIME(session, src, keys, msg);
939 if (status != PEP_STATUS_OK)
944 status = encrypt_PGP_in_pieces(session, src, keys, msg);
945 if (status == PEP_OUT_OF_MEMORY)
947 if (status != PEP_STATUS_OK) {
948 attach_own_key(session, src);
952 attach_own_key(session, msg);
963 status = PEP_ILLEGAL_VALUE;
968 free_stringlist(keys);
970 if (msg && msg->shortmsg == NULL)
971 msg->shortmsg = strdup("pEp");
974 decorate_message(msg, PEP_rating_undefined, NULL);
980 status = PEP_OUT_OF_MEMORY;
983 free_stringlist(keys);
989 DYNAMIC_API PEP_STATUS decrypt_message(
993 stringlist_t **keylist,
997 PEP_STATUS status = PEP_STATUS_OK;
998 PEP_STATUS decrypt_status = PEP_CANNOT_DECRYPT_UNKNOWN;
1004 stringlist_t *_keylist = NULL;
1012 if (!(session && src && dst && keylist && color))
1013 return PEP_ILLEGAL_VALUE;
1015 import_attached_keys(session, src);
1016 PEP_cryptotech crypto = determine_encryption_format(src);
1020 *color = PEP_rating_undefined;
1022 switch (src->enc_format) {
1024 *color = PEP_rating_unencrypted;
1025 return PEP_UNENCRYPTED;
1027 case PEP_enc_PGP_MIME:
1028 ctext = src->attachments->next->value;
1029 csize = src->attachments->next->size;
1031 status = cryptotech[crypto].decrypt_and_verify(session, ctext,
1032 csize, &ptext, &psize, &_keylist);
1033 if (status > PEP_CANNOT_DECRYPT_UNKNOWN)
1035 decrypt_status = status;
1038 case PEP_enc_pieces:
1039 ctext = src->longmsg;
1040 csize = strlen(ctext);
1042 status = cryptotech[crypto].decrypt_and_verify(session, ctext,
1043 csize, &ptext, &psize, &_keylist);
1044 if (status > PEP_CANNOT_DECRYPT_UNKNOWN)
1046 decrypt_status = status;
1053 *color = decrypt_color(status);
1055 if (*color != PEP_rating_under_attack) {
1056 PEP_color kl_color = PEP_rating_undefined;
1059 kl_color = keylist_color(session, _keylist);
1061 if (kl_color == PEP_rating_under_attack) {
1062 *color = PEP_rating_under_attack;
1064 else if (*color >= PEP_rating_reliable &&
1065 kl_color < PEP_rating_reliable) {
1066 *color = PEP_rating_unreliable;
1068 else if (*color >= PEP_rating_reliable &&
1069 kl_color == PEP_rating_reliable) {
1070 if (!(src->from && src->from->user_id && src->from->user_id[0])) {
1071 *color = PEP_rating_unreliable;
1074 char *fpr = _keylist->value;
1075 pEp_identity *_from = new_identity(src->from->address, fpr,
1076 src->from->user_id, src->from->username);
1079 status = update_identity(session, _from);
1080 if (_from->comm_type != PEP_ct_unknown)
1081 *color = _rating(_from->comm_type);
1082 free_identity(_from);
1083 if (status != PEP_STATUS_OK)
1090 switch (src->enc_format) {
1091 case PEP_enc_PGP_MIME:
1092 status = mime_decode_message(ptext, psize, &msg);
1093 if (status != PEP_STATUS_OK)
1097 case PEP_enc_pieces:
1098 msg = clone_to_empty_message(src);
1102 msg->longmsg = strdup(ptext);
1103 if (msg->longmsg == NULL)
1106 bloblist_t *_m = msg->attachments;
1107 if (_m == NULL && src->attachments && src->attachments->value) {
1108 msg->attachments = new_bloblist(NULL, 0, NULL, NULL);
1109 _m = msg->attachments;
1113 for (_s = src->attachments; _s && _s->value; _s = _s->next) {
1114 if (is_encrypted_attachment(_s)) {
1115 stringlist_t *_keylist = NULL;
1119 status = decrypt_and_verify(session, ctext, csize,
1120 &ptext, &psize, &_keylist);
1121 free_stringlist(_keylist);
1124 if (is_encrypted_html_attachment(_s)) {
1125 msg->longmsg_formatted = strdup(ptext);
1126 if (msg->longmsg_formatted == NULL)
1130 char * mime_type = "application/octet-stream";
1132 without_double_ending(_s->filename);
1133 if (filename == NULL)
1136 char *_ptext = malloc(psize);
1140 memcpy(_ptext, ptext, psize);
1142 _m = bloblist_add(_m, _ptext, psize, mime_type,
1147 if (msg->attachments == NULL)
1148 msg->attachments = _m;
1152 char *copy = malloc(_s->size);
1156 memcpy(copy, _s->value, _s->size);
1157 _m = bloblist_add(_m, copy, _s->size, _s->mime_type, _s->filename);
1163 char *copy = malloc(_s->size);
1167 memcpy(copy, _s->value, _s->size);
1168 _m = bloblist_add(_m, copy, _s->size, _s->mime_type, _s->filename);
1177 // BUG: must implement more
1181 switch (src->enc_format) {
1182 case PEP_enc_PGP_MIME:
1183 case PEP_enc_pieces:
1184 status = copy_fields(msg, src);
1185 if (status != PEP_STATUS_OK)
1188 if (src->shortmsg == NULL || strcmp(src->shortmsg, "pEp") == 0)
1193 int r = seperate_short_and_long(msg->longmsg, &shortmsg,
1198 free(msg->shortmsg);
1201 msg->shortmsg = shortmsg;
1202 msg->longmsg = longmsg;
1205 msg->shortmsg = strdup(src->shortmsg);
1206 if (msg->shortmsg == NULL)
1212 // BUG: must implement more
1216 import_attached_keys(session, msg);
1220 decorate_message(msg, *color, _keylist);
1223 *keylist = _keylist;
1225 return PEP_STATUS_OK;
1228 status = PEP_OUT_OF_MEMORY;
1232 free_stringlist(_keylist);
1237 DYNAMIC_API PEP_STATUS outgoing_message_color(
1238 PEP_SESSION session,
1243 PEP_STATUS status = PEP_STATUS_OK;
1244 PEP_comm_type max_comm_type = PEP_ct_pEp;
1245 bool comm_type_determined = false;
1251 assert(msg->dir == PEP_dir_outgoing);
1254 if (!(session && msg && color))
1255 return PEP_ILLEGAL_VALUE;
1257 if (msg->from == NULL || msg->dir != PEP_dir_outgoing)
1258 return PEP_ILLEGAL_VALUE;
1260 *color = PEP_rating_undefined;
1262 status = myself(session, msg->from);
1263 if (status != PEP_STATUS_OK)
1266 for (il = msg->to; il != NULL; il = il->next) {
1268 update_identity(session, il->ident);
1269 max_comm_type = _get_comm_type(session, max_comm_type,
1271 comm_type_determined = true;
1275 for (il = msg->cc; il != NULL; il = il->next) {
1277 update_identity(session, il->ident);
1278 max_comm_type = _get_comm_type(session, max_comm_type,
1280 comm_type_determined = true;
1284 if (comm_type_determined == false)
1285 *color = PEP_rating_undefined;
1287 *color = MAX(_rating(max_comm_type), PEP_rating_unencrypted);
1289 return PEP_STATUS_OK;
1292 DYNAMIC_API PEP_STATUS identity_color(
1293 PEP_SESSION session,
1294 pEp_identity *ident,
1298 PEP_STATUS status = PEP_STATUS_OK;
1304 if (!(session && ident && color))
1305 return PEP_ILLEGAL_VALUE;
1308 status = myself(session, ident);
1310 status = update_identity(session, ident);
1312 if (status == PEP_STATUS_OK)
1313 *color = _rating(ident->comm_type);