Lines 46-53
extern Tracker *tracker;
Link Here
|
46 |
static GMimeStream *new_gmime_stream_from_file (const gchar *path, gint flags, off_t start, off_t end); |
46 |
static GMimeStream *new_gmime_stream_from_file (const gchar *path, gint flags, off_t start, off_t end); |
47 |
|
47 |
|
48 |
static GSList * add_gmime_references (GSList *list, GMimeMessage *message, const gchar *header); |
48 |
static GSList * add_gmime_references (GSList *list, GMimeMessage *message, const gchar *header); |
49 |
static GSList * add_recipients (GSList *list, GMimeMessage *message, const gchar *type); |
49 |
static GSList * add_recipients (GSList *list, GMimeMessage *message, GMimeRecipientType type); |
50 |
static void find_attachment (GMimeObject *obj, gpointer data); |
50 |
static void find_attachment (GMimeObject *parent, GMimeObject *obj, gpointer data); |
51 |
|
51 |
|
52 |
|
52 |
|
53 |
|
53 |
|
Lines 491-496
email_free_mail_message (MailMessage *ma
Link Here
|
491 |
g_slice_free (MailMessage, mail_msg); |
491 |
g_slice_free (MailMessage, mail_msg); |
492 |
} |
492 |
} |
493 |
|
493 |
|
|
|
494 |
static GMimeObject * |
495 |
handle_multipart_alternative (GMimeMultipart *multipart, gboolean want_plain, gboolean *is_html) |
496 |
{ |
497 |
GMimeObject *mime_part, *text_part = NULL; |
498 |
GMimeContentType *type; |
499 |
int count, i; |
500 |
|
501 |
count = g_mime_multipart_get_count (multipart); |
502 |
for (i = 0; i < count ; i++) { |
503 |
mime_part = g_mime_multipart_get_part (multipart, i); |
504 |
|
505 |
type = g_mime_object_get_content_type (GMIME_OBJECT (mime_part)); |
506 |
if (g_mime_content_type_is_type (type, "text", "*")) { |
507 |
if (!text_part || !g_ascii_strcasecmp (type->subtype, want_plain ? "plain" : "html")) { |
508 |
*is_html = !g_ascii_strcasecmp (type->subtype, "html"); |
509 |
text_part = mime_part; |
510 |
} |
511 |
} |
512 |
} |
513 |
|
514 |
return text_part; |
515 |
} |
516 |
|
517 |
static GMimeObject * |
518 |
handle_multipart_mixed (GMimeMultipart *multipart, gboolean want_plain, gboolean *is_html) |
519 |
{ |
520 |
GMimeObject *mime_part, *text_part = NULL; |
521 |
GMimeContentType *type, *first_type = NULL; |
522 |
GList *subpart; |
523 |
int count, i; |
524 |
|
525 |
count = g_mime_multipart_get_count (multipart); |
526 |
for (i = 0; i < count ; i++) { |
527 |
mime_part = g_mime_multipart_get_part (multipart, i); |
528 |
|
529 |
type = g_mime_object_get_content_type (mime_part); |
530 |
if (GMIME_IS_MULTIPART (mime_part)) { |
531 |
multipart = GMIME_MULTIPART (mime_part); |
532 |
if (g_mime_content_type_is_type (type, "multipart", "alternative")) { |
533 |
mime_part = handle_multipart_alternative (multipart, want_plain, is_html); |
534 |
if (mime_part) |
535 |
return mime_part; |
536 |
} else { |
537 |
mime_part = handle_multipart_mixed (multipart, want_plain, is_html); |
538 |
if (mime_part && !text_part) |
539 |
text_part = mime_part; |
540 |
} |
541 |
} else if (g_mime_content_type_is_type (type, "text", "*")) { |
542 |
if (!g_ascii_strcasecmp (type->subtype, want_plain ? "plain" : "html")) { |
543 |
/* we got what we came for */ |
544 |
*is_html = !g_ascii_strcasecmp (type->subtype, "html"); |
545 |
return mime_part; |
546 |
} |
547 |
|
548 |
/* if we haven't yet found a text part or if it is a type we can |
549 |
1514 * understand and it is the first of that type, save it */ |
550 |
if (!text_part || (!g_ascii_strcasecmp (type->subtype, "plain") && (first_type && |
551 |
g_ascii_strcasecmp (type->subtype, first_type->subtype) != 0))) { |
552 |
*is_html = !g_ascii_strcasecmp (type->subtype, "html"); |
553 |
text_part = mime_part; |
554 |
first_type = type; |
555 |
} |
556 |
} |
557 |
|
558 |
subpart = subpart->next; |
559 |
} |
560 |
|
561 |
return text_part; |
562 |
} |
563 |
|
564 |
static char * |
565 |
tracker_mime_message_get_body (const GMimeMessage *message, gboolean want_plain, gboolean *is_html) |
566 |
{ |
567 |
GMimeObject *mime_part = NULL; |
568 |
GMimeContentType *type; |
569 |
GMimeMultipart *multipart; |
570 |
char *body = NULL; |
571 |
|
572 |
g_return_val_if_fail (GMIME_IS_MESSAGE (message), NULL); |
573 |
g_return_val_if_fail (is_html != NULL, NULL); |
574 |
|
575 |
type = g_mime_object_get_content_type (message->mime_part); |
576 |
if (GMIME_IS_MULTIPART (message->mime_part)) { |
577 |
/* let's see if we can find a body in the multipart */ |
578 |
multipart = GMIME_MULTIPART (message->mime_part); |
579 |
if (g_mime_content_type_is_type (type, "multipart", "alternative")) |
580 |
mime_part = handle_multipart_alternative (multipart, want_plain, is_html); |
581 |
else |
582 |
mime_part = handle_multipart_mixed (multipart, want_plain, is_html); |
583 |
} else if (g_mime_content_type_is_type (type, "text", "*")) { |
584 |
/* this *has* to be the message body */ |
585 |
if (g_mime_content_type_is_type (type, "text", "html")) |
586 |
*is_html = TRUE; |
587 |
else |
588 |
*is_html = FALSE; |
589 |
|
590 |
mime_part = message->mime_part; |
591 |
} |
592 |
|
593 |
if (mime_part != NULL) { |
594 |
GMimeDataWrapper *data_wrapper; |
595 |
GMimeStream *mime_stream; |
596 |
gint64 len; |
597 |
|
598 |
data_wrapper = g_mime_part_get_content_object (GMIME_PART (mime_part)); |
599 |
|
600 |
mime_stream = g_mime_data_wrapper_get_stream (data_wrapper); |
601 |
len = g_mime_stream_length (mime_stream); |
602 |
body = g_malloc0 (len + 1); |
603 |
g_mime_stream_read (mime_stream, body, len); |
604 |
g_object_unref (mime_stream); |
605 |
g_object_unref (data_wrapper); |
606 |
} |
607 |
|
608 |
return body; |
609 |
} |
610 |
|
611 |
|
494 |
|
612 |
|
495 |
MailMessage * |
613 |
MailMessage * |
496 |
email_mail_file_parse_next (MailFile *mf, ReadMailHelperFct read_mail_helper, gpointer read_mail_user_data) |
614 |
email_mail_file_parse_next (MailFile *mf, ReadMailHelperFct read_mail_helper, gpointer read_mail_user_data) |
Lines 539-545
email_mail_file_parse_next (MailFile *mf
Link Here
|
539 |
|
657 |
|
540 |
mail_msg->subject = g_strdup (g_mime_message_get_subject (g_m_message)); |
658 |
mail_msg->subject = g_strdup (g_mime_message_get_subject (g_m_message)); |
541 |
|
659 |
|
542 |
mail_msg->body = g_mime_message_get_body (g_m_message, TRUE, &is_html); |
660 |
mail_msg->body = tracker_mime_message_get_body (g_m_message, TRUE, &is_html); |
543 |
mail_msg->content_type = g_strdup (is_html ? "text/html" : "text/plain"); |
661 |
mail_msg->content_type = g_strdup (is_html ? "text/html" : "text/plain"); |
544 |
|
662 |
|
545 |
if (read_mail_helper) { |
663 |
if (read_mail_helper) { |
Lines 549-555
email_mail_file_parse_next (MailFile *mf
Link Here
|
549 |
mail_msg->attachments = NULL; |
667 |
mail_msg->attachments = NULL; |
550 |
|
668 |
|
551 |
/* find then save attachments in sys tmp directory of Tracker and save entries in MailMessage struct */ |
669 |
/* find then save attachments in sys tmp directory of Tracker and save entries in MailMessage struct */ |
552 |
g_mime_message_foreach_part (g_m_message, find_attachment, mail_msg); |
670 |
g_mime_message_foreach (g_m_message, find_attachment, mail_msg); |
553 |
|
671 |
|
554 |
g_object_unref (g_m_message); |
672 |
g_object_unref (g_m_message); |
555 |
|
673 |
|
Lines 786-808
email_decode_mail_attachment_to_file (co
Link Here
|
786 |
return FALSE; |
904 |
return FALSE; |
787 |
} |
905 |
} |
788 |
|
906 |
|
789 |
filtered_stream = g_mime_stream_filter_new_with_stream (stream_src); |
907 |
filtered_stream = g_mime_stream_filter_new (stream_src); |
790 |
|
908 |
|
791 |
switch (encoding) { |
909 |
switch (encoding) { |
792 |
case MIME_ENCODING_BASE64: |
910 |
case MIME_ENCODING_BASE64: |
793 |
filter = g_mime_filter_basic_new_type (GMIME_FILTER_BASIC_BASE64_DEC); |
911 |
filter = g_mime_filter_basic_new (GMIME_CONTENT_ENCODING_BASE64, FALSE); |
794 |
g_mime_stream_filter_add (GMIME_STREAM_FILTER (filtered_stream), filter); |
912 |
g_mime_stream_filter_add (GMIME_STREAM_FILTER (filtered_stream), filter); |
795 |
g_object_unref (filter); |
913 |
g_object_unref (filter); |
796 |
break; |
914 |
break; |
797 |
|
915 |
|
798 |
case MIME_ENCODING_QUOTEDPRINTABLE: |
916 |
case MIME_ENCODING_QUOTEDPRINTABLE: |
799 |
filter = g_mime_filter_basic_new_type (GMIME_FILTER_BASIC_QP_DEC); |
917 |
filter = g_mime_filter_basic_new (GMIME_CONTENT_ENCODING_QUOTEDPRINTABLE, FALSE); |
800 |
g_mime_stream_filter_add (GMIME_STREAM_FILTER (filtered_stream), filter); |
918 |
g_mime_stream_filter_add (GMIME_STREAM_FILTER (filtered_stream), filter); |
801 |
g_object_unref (filter); |
919 |
g_object_unref (filter); |
802 |
break; |
920 |
break; |
803 |
|
921 |
|
804 |
case MIME_ENCODING_UUENCODE: |
922 |
case MIME_ENCODING_UUENCODE: |
805 |
filter = g_mime_filter_basic_new_type (GMIME_FILTER_BASIC_UU_ENC); |
923 |
filter = g_mime_filter_basic_new (GMIME_CONTENT_ENCODING_UUENCODE, TRUE); |
806 |
g_mime_stream_filter_add (GMIME_STREAM_FILTER (filtered_stream), filter); |
924 |
g_mime_stream_filter_add (GMIME_STREAM_FILTER (filtered_stream), filter); |
807 |
g_object_unref (filter); |
925 |
g_object_unref (filter); |
808 |
break; |
926 |
break; |
Lines 913-919
new_gmime_stream_from_file (const gchar
Link Here
|
913 |
static GSList * |
1031 |
static GSList * |
914 |
add_gmime_references (GSList *list, GMimeMessage *message, const gchar *header) |
1032 |
add_gmime_references (GSList *list, GMimeMessage *message, const gchar *header) |
915 |
{ |
1033 |
{ |
916 |
const gchar *tmp = g_mime_message_get_header (message, header); |
1034 |
const gchar *tmp = g_mime_object_get_header (GMIME_OBJECT (message), header); |
917 |
|
1035 |
|
918 |
if (tmp) { |
1036 |
if (tmp) { |
919 |
GMimeReferences *refs; |
1037 |
GMimeReferences *refs; |
Lines 937-951
add_gmime_references (GSList *list, GMim
Link Here
|
937 |
|
1055 |
|
938 |
|
1056 |
|
939 |
static GSList * |
1057 |
static GSList * |
940 |
add_recipients (GSList *list, GMimeMessage *message, const gchar *type) |
1058 |
add_recipients (GSList *list, GMimeMessage *message, GMimeRecipientType type) |
941 |
{ |
1059 |
{ |
942 |
const InternetAddressList *addrs_list; |
1060 |
InternetAddressList *addrs_list; |
|
|
1061 |
int i, count; |
943 |
|
1062 |
|
944 |
for (addrs_list = g_mime_message_get_recipients (message, type); addrs_list; addrs_list = addrs_list->next) { |
1063 |
addrs_list = g_mime_message_get_recipients (message, type); |
|
|
1064 |
count = internet_address_list_length (addrs_list); |
1065 |
for (i = 0; i < count; i++) { |
1066 |
InternetAddress *addr; |
945 |
MailPerson *mp = email_allocate_mail_person (); |
1067 |
MailPerson *mp = email_allocate_mail_person (); |
946 |
|
1068 |
|
947 |
mp->name = g_strdup (addrs_list->address->name); |
1069 |
addr = internet_address_list_get_address (addrs_list, i); |
948 |
mp->addr = g_strdup (addrs_list->address->value.addr); |
1070 |
|
|
|
1071 |
mp->name = g_strdup (internet_address_get_name (addr)); |
1072 |
mp->addr = g_strdup (internet_address_to_string (addr, FALSE)); |
949 |
|
1073 |
|
950 |
list = g_slist_prepend (list, mp); |
1074 |
list = g_slist_prepend (list, mp); |
951 |
} |
1075 |
} |
Lines 955-961
add_recipients (GSList *list, GMimeMessa
Link Here
|
955 |
|
1079 |
|
956 |
|
1080 |
|
957 |
static void |
1081 |
static void |
958 |
find_attachment (GMimeObject *obj, gpointer data) |
1082 |
find_attachment (GMimeObject *parent, GMimeObject *obj, gpointer data) |
959 |
{ |
1083 |
{ |
960 |
GMimePart *part; |
1084 |
GMimePart *part; |
961 |
MailMessage *mail_msg; |
1085 |
MailMessage *mail_msg; |
Lines 969-976
find_attachment (GMimeObject *obj, gpoin
Link Here
|
969 |
GMimeMessage *g_msg = g_mime_message_part_get_message (GMIME_MESSAGE_PART (obj)); |
1093 |
GMimeMessage *g_msg = g_mime_message_part_get_message (GMIME_MESSAGE_PART (obj)); |
970 |
|
1094 |
|
971 |
if (g_msg) { |
1095 |
if (g_msg) { |
972 |
g_mime_message_foreach_part (g_msg, find_attachment, data); |
1096 |
g_mime_message_foreach (g_msg, find_attachment, data); |
973 |
g_object_unref (g_msg); |
1097 |
g_object_unref (obj); |
974 |
} |
1098 |
} |
975 |
return; |
1099 |
return; |
976 |
|
1100 |
|
Lines 987-1006
find_attachment (GMimeObject *obj, gpoin
Link Here
|
987 |
|
1111 |
|
988 |
mail_msg = data; |
1112 |
mail_msg = data; |
989 |
|
1113 |
|
990 |
content_disposition = g_mime_part_get_content_disposition (part); |
1114 |
content_disposition = g_mime_object_get_disposition (obj); |
991 |
|
1115 |
|
992 |
/* test whether it is a mail attachment */ |
1116 |
/* test whether it is a mail attachment */ |
993 |
if (content_disposition && |
1117 |
if (content_disposition && |
994 |
(strcmp (content_disposition, GMIME_DISPOSITION_ATTACHMENT) == 0 || |
1118 |
(strcmp (content_disposition, GMIME_DISPOSITION_ATTACHMENT) == 0 || |
995 |
strcmp (content_disposition, GMIME_DISPOSITION_INLINE) == 0)) { |
1119 |
strcmp (content_disposition, GMIME_DISPOSITION_INLINE) == 0)) { |
996 |
|
1120 |
|
997 |
const GMimeContentType *content_type; |
1121 |
GMimeContentType *content_type; |
998 |
MailAttachment *ma; |
1122 |
MailAttachment *ma; |
999 |
const gchar *filename; |
1123 |
const gchar *filename; |
1000 |
gchar *attachment_uri; |
1124 |
gchar *attachment_uri; |
1001 |
gint fd; |
1125 |
gint fd; |
1002 |
|
1126 |
|
1003 |
if (! (content_type = g_mime_part_get_content_type (part))) |
1127 |
if (! (content_type = g_mime_object_get_content_type (obj))) |
1004 |
return; |
1128 |
return; |
1005 |
|
1129 |
|
1006 |
filename = g_mime_part_get_filename (part); |
1130 |
filename = g_mime_part_get_filename (part); |