Tue, 06 Aug 2019 19:50:26 -0400
Rename *_TYPE_*_IFACE to more standard *_TYPE_*.
Using sed of `s/\(TYPE_PROTOCOL_[A-Za-z0-9_]\+\)_IFACE/\1/g`.
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
1 | /* |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
2 | * purple - Sametime Protocol Plugin |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
3 | * |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
4 | * Purple is the legal property of its developers, whose names are too numerous |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
5 | * to list here. Please refer to the COPYRIGHT file distributed with this |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
6 | * source distribution. |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
7 | * |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
8 | * This program is free software; you can redistribute it and/or modify |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
9 | * it under the terms of the GNU General Public License as published by |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
10 | * the Free Software Foundation; either version 2 of the License, or |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
11 | * (at your option) any later version. |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
12 | * |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
13 | * This program is distributed in the hope that it will be useful, |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
16 | * GNU General Public License for more details. |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
17 | * |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
18 | * You should have received a copy of the GNU General Public License |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
19 | * along with this program; if not, write to the Free Software |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
21 | * |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
22 | */ |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
23 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
24 | #include "internal.h" |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
25 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
26 | #include <glib.h> |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
27 | #include <gmime/gmime.h> |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
28 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
29 | /* purple includes */ |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
30 | #include "image-store.h" |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
31 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
32 | /* plugin includes */ |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
33 | #include "sametime.h" |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
34 | #include "im_mime.h" |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
35 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
36 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
37 | /** generate "cid:908@20582notesbuddy" from "<908@20582notesbuddy>" */ |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
38 | static char * |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
39 | make_cid(const char *cid) |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
40 | { |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
41 | g_return_val_if_fail(cid != NULL, NULL); |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
42 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
43 | return g_strdup_printf("cid:%s", cid); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
44 | } |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
45 | |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
46 | |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
47 | /* Create a MIME parser from some input data. */ |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
48 | static GMimeParser * |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
49 | create_parser(const char *data) |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
50 | { |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
51 | GMimeStream *stream; |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
52 | GMimeFilter *filter; |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
53 | GMimeStream *filtered_stream; |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
54 | GMimeParser *parser; |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
55 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
56 | stream = g_mime_stream_mem_new_with_buffer(data, strlen(data)); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
57 | |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
58 | filtered_stream = g_mime_stream_filter_new(stream); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
59 | g_object_unref(G_OBJECT(stream)); |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
60 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
61 | /* Add a dos2unix filter so in-message newlines are simplified. */ |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
62 | filter = g_mime_filter_dos2unix_new(FALSE); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
63 | g_mime_stream_filter_add(GMIME_STREAM_FILTER(filtered_stream), filter); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
64 | g_object_unref(G_OBJECT(filter)); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
65 | |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
66 | parser = g_mime_parser_new_with_stream(filtered_stream); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
67 | g_object_unref(G_OBJECT(filtered_stream)); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
68 | |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
69 | return parser; |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
70 | } |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
71 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
72 | |
|
39528
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
73 | /* Replace each IMG tag's SRC attribute with an ID attribute. This |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
74 | actually modifies the contents of str */ |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
75 | static void |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
76 | replace_img_src_by_id(GString *str, GHashTable *img_by_cid) |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
77 | { |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
78 | GData *attribs; |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
79 | char *start, *end; |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
80 | char *tmp = str->str; |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
81 | |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
82 | while (*tmp && |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
83 | purple_markup_find_tag("img", tmp, |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
84 | (const char **) &start, (const char **) &end, |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
85 | &attribs)) { |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
86 | |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
87 | char *alt, *align, *border, *src; |
|
39529
025cbbc9e5ae
sametime: Fix parsing of images in messages.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39528
diff
changeset
|
88 | guint img = 0; |
|
39528
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
89 | |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
90 | alt = g_datalist_get_data(&attribs, "alt"); |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
91 | align = g_datalist_get_data(&attribs, "align"); |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
92 | border = g_datalist_get_data(&attribs, "border"); |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
93 | src = g_datalist_get_data(&attribs, "src"); |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
94 | |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
95 | if (src) { |
|
39529
025cbbc9e5ae
sametime: Fix parsing of images in messages.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39528
diff
changeset
|
96 | img = GPOINTER_TO_UINT(g_hash_table_lookup(img_by_cid, src)); |
|
39528
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
97 | } |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
98 | |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
99 | if (img) { |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
100 | GString *atstr; |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
101 | gsize len = (end - start); |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
102 | gsize mov; |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
103 | |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
104 | atstr = g_string_new(""); |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
105 | if (alt) { |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
106 | g_string_append_printf(atstr, " alt=\"%s\"", alt); |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
107 | } |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
108 | if (align) { |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
109 | g_string_append_printf(atstr, " align=\"%s\"", align); |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
110 | } |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
111 | if (border) { |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
112 | g_string_append_printf(atstr, " border=\"%s\"", border); |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
113 | } |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
114 | |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
115 | mov = g_snprintf(start, len, |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
116 | "<img src=\"" PURPLE_IMAGE_STORE_PROTOCOL |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
117 | "%u\"%s", img, atstr->str); |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
118 | while (mov < len) start[mov++] = ' '; |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
119 | |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
120 | g_string_free(atstr, TRUE); |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
121 | } |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
122 | |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
123 | g_datalist_clear(&attribs); |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
124 | tmp = end + 1; |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
125 | } |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
126 | } |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
127 | |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
128 | gchar * |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
129 | im_mime_parse(const char *data) |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
130 | { |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
131 | GHashTable *img_by_cid; |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
132 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
133 | GString *str; |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
134 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
135 | GMimeParser *parser; |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
136 | GMimeObject *doc; |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
137 | int i, count; |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
138 | |
|
39529
025cbbc9e5ae
sametime: Fix parsing of images in messages.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39528
diff
changeset
|
139 | img_by_cid = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
140 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
141 | /* don't want the contained string to ever be NULL */ |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
142 | str = g_string_new(""); |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
143 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
144 | parser = create_parser(data); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
145 | doc = g_mime_parser_construct_part(parser, NULL); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
146 | if (!GMIME_IS_MULTIPART(doc)) { |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
147 | g_object_unref(G_OBJECT(doc)); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
148 | g_object_unref(G_OBJECT(parser)); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
149 | return g_string_free(str, FALSE); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
150 | } |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
151 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
152 | /* handle all the MIME parts */ |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
153 | count = g_mime_multipart_get_count(GMIME_MULTIPART(doc)); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
154 | for (i = 0; i < count; i++) { |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
155 | GMimeObject *obj = g_mime_multipart_get_part(GMIME_MULTIPART(doc), i); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
156 | GMimeContentType *type = g_mime_object_get_content_type(obj); |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
157 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
158 | if (!type) { |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
159 | ; /* feh */ |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
160 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
161 | } else if (g_mime_content_type_is_type(type, "image", "*")) { |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
162 | /* put images into the image store */ |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
163 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
164 | GMimePart *part = GMIME_PART(obj); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
165 | GMimeDataWrapper *wrapper; |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
166 | GMimeStream *stream; |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
167 | GByteArray *bytearray; |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
168 | GBytes *data; |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
169 | char *cid; |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
170 | PurpleImage *image; |
|
39529
025cbbc9e5ae
sametime: Fix parsing of images in messages.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39528
diff
changeset
|
171 | guint imgid; |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
172 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
173 | /* obtain and unencode the data */ |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
174 | bytearray = g_byte_array_new(); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
175 | stream = g_mime_stream_mem_new_with_byte_array(bytearray); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
176 | g_mime_stream_mem_set_owner(GMIME_STREAM_MEM(stream), FALSE); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
177 | wrapper = g_mime_part_get_content(part); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
178 | g_mime_data_wrapper_write_to_stream(wrapper, stream); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
179 | data = g_byte_array_free_to_bytes(bytearray); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
180 | g_clear_object(&stream); |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
181 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
182 | /* look up the content id */ |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
183 | cid = make_cid(g_mime_part_get_content_id(part)); |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
184 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
185 | /* add image to the purple image store */ |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
186 | image = purple_image_new_from_bytes(data); |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
187 | purple_image_set_friendly_filename(image, cid); |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
188 | g_bytes_unref(data); |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
189 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
190 | /* map the cid to the image store identifier */ |
|
39529
025cbbc9e5ae
sametime: Fix parsing of images in messages.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39528
diff
changeset
|
191 | imgid = purple_image_store_add(image); |
|
025cbbc9e5ae
sametime: Fix parsing of images in messages.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39528
diff
changeset
|
192 | g_hash_table_insert(img_by_cid, cid, GUINT_TO_POINTER(imgid)); |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
193 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
194 | } else if (GMIME_IS_TEXT_PART(obj)) { |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
195 | /* concatenate all the text parts together */ |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
196 | char *data; |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
197 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
198 | data = g_mime_text_part_get_text(GMIME_TEXT_PART(obj)); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
199 | g_string_append(str, data); |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
200 | g_free(data); |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
201 | } |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
202 | } |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
203 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
204 | g_object_unref(G_OBJECT(doc)); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
205 | g_object_unref(G_OBJECT(parser)); |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
206 | |
|
39528
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
207 | replace_img_src_by_id(str, img_by_cid); |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
208 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
209 | /* clean up the cid table */ |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
210 | g_hash_table_destroy(img_by_cid); |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
211 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
212 | return g_string_free(str, FALSE); |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
213 | } |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
214 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
215 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
216 | /** generates a random-ish content id string */ |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
217 | static char * |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
218 | im_mime_content_id(void) |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
219 | { |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
220 | return g_strdup_printf("%03x@%05xmeanwhile", |
|
39524
b49e731857a2
sametime: Use GLib random generator.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39523
diff
changeset
|
221 | g_random_int() & 0xfff, g_random_int() & 0xfffff); |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
222 | } |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
223 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
224 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
225 | /** generates a random-ish boundary value */ |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
226 | static char * |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
227 | im_mime_boundary(void) |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
228 | { |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
229 | return g_strdup_printf("related_MW%03x_%04x", |
|
39524
b49e731857a2
sametime: Use GLib random generator.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39523
diff
changeset
|
230 | g_random_int() & 0xfff, g_random_int() & 0xffff); |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
231 | } |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
232 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
233 | /** create MIME image from purple image */ |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
234 | static GMimePart * |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
235 | im_mime_img_to_part(PurpleImage *img) |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
236 | { |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
237 | const gchar *mimetype; |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
238 | GMimePart *part; |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
239 | GByteArray *data; |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
240 | GMimeStream *stream; |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
241 | GMimeDataWrapper *wrapper; |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
242 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
243 | mimetype = purple_image_get_mimetype(img); |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
244 | if (mimetype && g_str_has_prefix(mimetype, "image/")) { |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
245 | mimetype += sizeof("image/") - 1; |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
246 | } |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
247 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
248 | part = g_mime_part_new_with_type("image", mimetype); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
249 | g_mime_object_set_disposition(GMIME_OBJECT(part), |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
250 | GMIME_DISPOSITION_ATTACHMENT); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
251 | g_mime_part_set_content_encoding(part, GMIME_CONTENT_ENCODING_BASE64); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
252 | g_mime_part_set_filename(part, purple_image_get_friendly_filename(img)); |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
253 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
254 | data = g_bytes_unref_to_array(purple_image_get_contents(img)); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
255 | stream = g_mime_stream_mem_new_with_byte_array(data); |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
256 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
257 | wrapper = g_mime_data_wrapper_new_with_stream(stream, |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
258 | GMIME_CONTENT_ENCODING_BINARY); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
259 | g_object_unref(G_OBJECT(stream)); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
260 | |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
261 | g_mime_part_set_content(part, wrapper); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
262 | g_object_unref(G_OBJECT(wrapper)); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
263 | |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
264 | return part; |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
265 | } |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
266 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
267 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
268 | gchar * |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
269 | im_mime_generate(const char *message) |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
270 | { |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
271 | GString *str; |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
272 | GMimeMultipart *doc; |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
273 | GMimeFormatOptions *opts; |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
274 | GMimeTextPart *text; |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
275 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
276 | GData *attr; |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
277 | char *tmp, *start, *end; |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
278 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
279 | str = g_string_new(NULL); |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
280 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
281 | doc = g_mime_multipart_new_with_subtype("related"); |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
282 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
283 | g_mime_object_set_header(GMIME_OBJECT(doc), "Mime-Version", "1.0", NULL); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
284 | g_mime_object_set_disposition(GMIME_OBJECT(doc), GMIME_DISPOSITION_INLINE); |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
285 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
286 | tmp = im_mime_boundary(); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
287 | g_mime_multipart_set_boundary(doc, tmp); |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
288 | g_free(tmp); |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
289 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
290 | tmp = (char *)message; |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
291 | while (*tmp && |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
292 | purple_markup_find_tag("img", tmp, (const char **) &start, |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
293 | (const char **) &end, &attr)) { |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
294 | gchar *uri; |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
295 | PurpleImage *img = NULL; |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
296 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
297 | gsize len = (start - tmp); |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
298 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
299 | /* append the in-between-tags text */ |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
300 | if (len) { |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
301 | g_string_append_len(str, tmp, len); |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
302 | } |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
303 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
304 | uri = g_datalist_get_data(&attr, "src"); |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
305 | if (uri) { |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
306 | img = purple_image_store_get_from_uri(uri); |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
307 | } |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
308 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
309 | if (img) { |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
310 | GMimePart *part; |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
311 | char *cid; |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
312 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
313 | cid = im_mime_content_id(); |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
314 | part = im_mime_img_to_part(img); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
315 | g_mime_part_set_content_id(part, cid); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
316 | g_mime_multipart_add(doc, GMIME_OBJECT(part)); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
317 | g_object_unref(G_OBJECT(part)); |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
318 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
319 | /* append the modified tag */ |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
320 | g_string_append_printf(str, "<img src=\"cid:%s\">", cid); |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
321 | g_free(cid); |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
322 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
323 | } else { |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
324 | /* append the literal image tag, since we couldn't find |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
325 | a relative PurpleImage object */ |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
326 | gsize len = (end - start) + 1; |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
327 | g_string_append_len(str, start, len); |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
328 | } |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
329 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
330 | g_datalist_clear(&attr); |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
331 | tmp = end + 1; |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
332 | } |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
333 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
334 | /* append left-overs */ |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
335 | g_string_append(str, tmp); |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
336 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
337 | /* add the text/html part */ |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
338 | text = g_mime_text_part_new_with_subtype("html"); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
339 | g_mime_object_set_disposition(GMIME_OBJECT(text), |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
340 | GMIME_DISPOSITION_INLINE); |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
341 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
342 | tmp = purple_utf8_ncr_encode(str->str); |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
343 | g_mime_text_part_set_text(text, tmp); |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
344 | g_free(tmp); |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
345 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
346 | g_mime_multipart_insert(doc, 0, GMIME_OBJECT(text)); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
347 | g_object_unref(G_OBJECT(text)); |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
348 | g_string_free(str, TRUE); |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
349 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
350 | opts = g_mime_format_options_new(); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
351 | g_mime_format_options_set_newline_format(opts, GMIME_NEWLINE_FORMAT_DOS); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
352 | tmp = g_mime_object_to_string(GMIME_OBJECT(doc), opts); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
353 | g_mime_format_options_free(opts); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
354 | g_object_unref(G_OBJECT(doc)); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
355 | return tmp; |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
356 | } |