Mon, 12 Sep 2022 22:08:59 -0500
Remove the list_icon vfunc from PurpleProtocol.
This was replaced by the icon-name, icon-resource-path, and icon-search-path
properties.
Testing Done:
Compiled
Reviewed at https://reviews.imfreedom.org/r/1749/
|
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 <glib.h> |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
25 | #include <gmime/gmime.h> |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
26 | |
|
40358
e6fe6fc1f516
move all protocols, purple plugins, and purple tests to use purple.h instead of including files individually
Gary Kramlich <grim@reaperworld.com>
parents:
40196
diff
changeset
|
27 | #include <purple.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 | /* plugin includes */ |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
30 | #include "sametime.h" |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
31 | #include "im_mime.h" |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
32 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
33 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
34 | /** 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
|
35 | static char * |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
36 | make_cid(const char *cid) |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
37 | { |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
38 | 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
|
39 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
40 | return g_strdup_printf("cid:%s", cid); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
41 | } |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
42 | |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
43 | |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
44 | /* 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
|
45 | static GMimeParser * |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
46 | create_parser(const char *data) |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
47 | { |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
48 | GMimeStream *stream; |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
49 | GMimeFilter *filter; |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
50 | GMimeStream *filtered_stream; |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
51 | GMimeParser *parser; |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
52 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
53 | 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
|
54 | |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
55 | 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
|
56 | 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
|
57 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
58 | /* 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
|
59 | filter = g_mime_filter_dos2unix_new(FALSE); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
60 | 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
|
61 | g_object_unref(G_OBJECT(filter)); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
62 | |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
63 | 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
|
64 | g_object_unref(G_OBJECT(filtered_stream)); |
|
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 | return parser; |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
67 | } |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
68 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
69 | |
|
39528
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
70 | /* 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
|
71 | 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
|
72 | static void |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
73 | 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
|
74 | { |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
75 | GData *attribs; |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
76 | 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
|
77 | 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
|
78 | |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
79 | while (*tmp && |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
80 | 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
|
81 | (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
|
82 | &attribs)) { |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
83 | |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
84 | 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
|
85 | 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
|
86 | |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
87 | 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
|
88 | 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
|
89 | 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
|
90 | 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
|
91 | |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
92 | if (src) { |
|
39529
025cbbc9e5ae
sametime: Fix parsing of images in messages.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39528
diff
changeset
|
93 | 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
|
94 | } |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
95 | |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
96 | if (img) { |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
97 | GString *atstr; |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
98 | 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
|
99 | gsize mov; |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
100 | |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
101 | 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
|
102 | if (alt) { |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
103 | 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
|
104 | } |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
105 | if (align) { |
|
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, " 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
|
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 (border) { |
|
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, " 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
|
110 | } |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
111 | |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
112 | 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
|
113 | "<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
|
114 | "%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
|
115 | 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
|
116 | |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
117 | 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
|
118 | } |
|
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_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
|
121 | 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
|
122 | } |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
123 | } |
|
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
124 | |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
125 | gchar * |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
126 | 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
|
127 | { |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
128 | GHashTable *img_by_cid; |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
129 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
130 | GString *str; |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
131 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
132 | GMimeParser *parser; |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
133 | GMimeObject *doc; |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
134 | int i, count; |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
135 | |
|
39529
025cbbc9e5ae
sametime: Fix parsing of images in messages.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39528
diff
changeset
|
136 | 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
|
137 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
138 | /* 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
|
139 | str = g_string_new(""); |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
140 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
141 | parser = create_parser(data); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
142 | 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
|
143 | if (!GMIME_IS_MULTIPART(doc)) { |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
144 | g_object_unref(G_OBJECT(doc)); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
145 | g_object_unref(G_OBJECT(parser)); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
146 | return g_string_free(str, FALSE); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
147 | } |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
148 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
149 | /* handle all the MIME parts */ |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
150 | 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
|
151 | for (i = 0; i < count; i++) { |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
152 | 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
|
153 | 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
|
154 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
155 | if (!type) { |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
156 | ; /* feh */ |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
157 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
158 | } 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
|
159 | /* 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
|
160 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
161 | GMimePart *part = GMIME_PART(obj); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
162 | GMimeDataWrapper *wrapper; |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
163 | GMimeStream *stream; |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
164 | GByteArray *bytearray; |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
165 | GBytes *data; |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
166 | char *cid; |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
167 | PurpleImage *image; |
|
39529
025cbbc9e5ae
sametime: Fix parsing of images in messages.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39528
diff
changeset
|
168 | guint imgid; |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
169 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
170 | /* obtain and unencode the data */ |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
171 | bytearray = g_byte_array_new(); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
172 | 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
|
173 | 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
|
174 | wrapper = g_mime_part_get_content(part); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
175 | 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
|
176 | 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
|
177 | g_clear_object(&stream); |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
178 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
179 | /* look up the content id */ |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
180 | 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
|
181 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
182 | /* 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
|
183 | 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
|
184 | 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
|
185 | g_bytes_unref(data); |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
186 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
187 | /* 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
|
188 | 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
|
189 | 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
|
190 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
191 | } 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
|
192 | /* concatenate all the text parts together */ |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
193 | char *data; |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
194 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
195 | 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
|
196 | 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
|
197 | g_free(data); |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
198 | } |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
199 | } |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
200 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
201 | g_object_unref(G_OBJECT(doc)); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
202 | 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
|
203 | |
|
39528
0fa64a08fd5b
sametime: Finish old todo and split out img editing function.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39526
diff
changeset
|
204 | 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
|
205 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
206 | /* clean up the cid table */ |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
207 | 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
|
208 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
209 | 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
|
210 | } |
|
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 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
213 | /** 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
|
214 | static char * |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
215 | im_mime_content_id(void) |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
216 | { |
|
40196
7690a049a466
Fix sametime mime generation tests on clang.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39529
diff
changeset
|
217 | gint id = g_random_int(); |
|
7690a049a466
Fix sametime mime generation tests on clang.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39529
diff
changeset
|
218 | return g_strdup_printf("%03x@%05xmeanwhile", (id & 0xfff00000) >> 20, |
|
7690a049a466
Fix sametime mime generation tests on clang.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39529
diff
changeset
|
219 | id & 0xfffff); |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
220 | } |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
221 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
222 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
223 | /** 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
|
224 | static char * |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
225 | im_mime_boundary(void) |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
226 | { |
|
40196
7690a049a466
Fix sametime mime generation tests on clang.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39529
diff
changeset
|
227 | gint id = g_random_int(); |
|
7690a049a466
Fix sametime mime generation tests on clang.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39529
diff
changeset
|
228 | return g_strdup_printf("related_MW%03x_%04x", (id & 0xfff0000) >> 16, |
|
7690a049a466
Fix sametime mime generation tests on clang.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39529
diff
changeset
|
229 | id & 0xffff); |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
230 | } |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
231 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
232 | /** create MIME image from purple image */ |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
233 | static GMimePart * |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
234 | 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
|
235 | { |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
236 | const gchar *mimetype; |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
237 | GMimePart *part; |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
238 | GByteArray *data; |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
239 | GMimeStream *stream; |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
240 | GMimeDataWrapper *wrapper; |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
241 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
242 | mimetype = purple_image_get_mimetype(img); |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
243 | 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
|
244 | mimetype += sizeof("image/") - 1; |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
245 | } |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
246 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
247 | 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
|
248 | 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
|
249 | GMIME_DISPOSITION_ATTACHMENT); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
250 | 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
|
251 | 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
|
252 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
253 | 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
|
254 | 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
|
255 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
256 | 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
|
257 | GMIME_CONTENT_ENCODING_BINARY); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
258 | g_object_unref(G_OBJECT(stream)); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
259 | |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
260 | g_mime_part_set_content(part, wrapper); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
261 | g_object_unref(G_OBJECT(wrapper)); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
262 | |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
263 | return part; |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
264 | } |
|
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 | gchar * |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
268 | 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
|
269 | { |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
270 | GString *str; |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
271 | GMimeMultipart *doc; |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
272 | GMimeFormatOptions *opts; |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
273 | GMimeTextPart *text; |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
274 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
275 | GData *attr; |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
276 | char *tmp, *start, *end; |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
277 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
278 | str = g_string_new(NULL); |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
279 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
280 | 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
|
281 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
282 | 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
|
283 | 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
|
284 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
285 | tmp = im_mime_boundary(); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
286 | 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
|
287 | g_free(tmp); |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
288 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
289 | tmp = (char *)message; |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
290 | while (*tmp && |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
291 | 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
|
292 | (const char **) &end, &attr)) { |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
293 | gchar *uri; |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
294 | PurpleImage *img = NULL; |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
295 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
296 | gsize len = (start - tmp); |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
297 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
298 | /* 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
|
299 | if (len) { |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
300 | 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
|
301 | } |
|
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 | 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
|
304 | if (uri) { |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
305 | 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
|
306 | } |
|
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 | if (img) { |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
309 | GMimePart *part; |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
310 | char *cid; |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
311 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
312 | cid = im_mime_content_id(); |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
313 | part = im_mime_img_to_part(img); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
314 | 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
|
315 | 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
|
316 | 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
|
317 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
318 | /* append the modified tag */ |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
319 | 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
|
320 | g_free(cid); |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
321 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
322 | } else { |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
323 | /* 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
|
324 | a relative PurpleImage object */ |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
325 | gsize len = (end - start) + 1; |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
326 | 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
|
327 | } |
|
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 | g_datalist_clear(&attr); |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
330 | tmp = end + 1; |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
331 | } |
|
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 | /* append left-overs */ |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
334 | g_string_append(str, tmp); |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
335 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
336 | /* add the text/html part */ |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
337 | 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
|
338 | 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
|
339 | GMIME_DISPOSITION_INLINE); |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
340 | |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
341 | 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
|
342 | 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
|
343 | g_free(tmp); |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
344 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
345 | 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
|
346 | 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
|
347 | g_string_free(str, TRUE); |
|
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
348 | |
|
39526
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
349 | opts = g_mime_format_options_new(); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
350 | 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
|
351 | 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
|
352 | g_mime_format_options_free(opts); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
353 | g_object_unref(G_OBJECT(doc)); |
|
4f678f514b69
Switch to GMime for sametime.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
39524
diff
changeset
|
354 | return tmp; |
|
39523
415b0705e48b
sametime: Move MIME handling to a separate file.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff
changeset
|
355 | } |