core cleanup: factor out purple MIME code
[siplcs.git] / src / core / sipe-mime.c
blobae796e60dccd97137f987bd39de4d1cc82555f7e
1 /**
2 * @file sipe-mime.c
4 * pidgin-sipe
6 * Copyright (C) 2010 SIPE Project <http://sipe.sourceforge.net/>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "glib.h"
25 #include "mime.h"
27 #include "sipe-backend-debug.h"
28 #include "sipe-mime.h"
30 void sipe_mime_parts_foreach(const gchar *type,
31 const gchar *body,
32 sipe_mime_parts_cb callback,
33 gpointer user_data)
35 gchar *doc = g_strdup_printf("Content-Type: %s\r\n\r\n%s", type, body);
36 PurpleMimeDocument *mime = purple_mime_document_parse(doc);
38 if (mime) {
39 GList* parts = purple_mime_document_get_parts(mime);
41 while (parts) {
42 const gchar *content_type = purple_mime_part_get_field(parts->data,
43 "Content-Type");
44 if (content_type) {
45 const gchar *content = purple_mime_part_get_data(parts->data);
46 gsize length = purple_mime_part_get_length(parts->data);
48 (*callback)(user_data, content_type, content, length);
50 parts = parts->next;
52 purple_mime_document_free(mime);
54 g_free(doc);
58 Local Variables:
59 mode: c
60 c-file-style: "bsd"
61 indent-tabs-mode: t
62 tab-width: 8
63 End: