4 #include "claws-features.h"
8 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
9 * Copyright (C) 1999-2013 Colin Leroy <colin@colino.net> and
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 #include "pgp_utils.h"
35 gchar *fp_read_noconv(FILE *fp)
44 array = g_byte_array_new();
46 while ((n_read = claws_fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
47 if (n_read < sizeof(buf) && claws_ferror(fp))
49 g_byte_array_append(array, buf, n_read);
52 if (claws_ferror(fp)) {
53 FILE_OP_ERROR("file stream", "claws_fread");
54 g_byte_array_free(array, TRUE);
59 g_byte_array_append(array, buf, 1);
60 result = (gchar *)array->data;
61 g_byte_array_free(array, FALSE);
66 gchar *get_part_as_string(MimeInfo *mimeinfo)
68 gchar *textdata = NULL;
69 gchar *filename = NULL;
72 cm_return_val_if_fail(mimeinfo != NULL, 0);
73 procmime_decode_content(mimeinfo);
75 if (mimeinfo->content == MIMECONTENT_MEM)
76 textdata = g_strdup(mimeinfo->data.mem);
78 filename = procmime_get_tmp_file_name(mimeinfo);
79 if (procmime_get_part(filename, mimeinfo) < 0) {
80 g_warning("error dumping temporary file '%s'", filename);
84 fp = claws_fopen(filename,"rb");
86 g_warning("error opening temporary file '%s'", filename);
90 textdata = fp_read_noconv(fp);
96 if (!g_utf8_validate(textdata, -1, NULL)) {
98 codeconv_set_strict(TRUE);
99 if (procmime_mimeinfo_get_parameter(mimeinfo, "charset")) {
100 tmp = conv_codeset_strdup(textdata,
101 procmime_mimeinfo_get_parameter(mimeinfo, "charset"),
105 tmp = conv_codeset_strdup(textdata,
106 conv_get_locale_charset_str_no_utf8(),
109 codeconv_set_strict(FALSE);
111 tmp = conv_codeset_strdup(textdata,
112 conv_get_locale_charset_str_no_utf8(),
124 gchar *pgp_locate_armor_header(gchar *textdata, const gchar *armor_header)
128 pos = strstr(textdata, armor_header);
130 * It's only a valid armor header if it's at the
131 * beginning of the buffer or a new line.
133 if (pos != NULL && (pos == textdata || *(pos-1) == '\n'))
139 #endif /* USE_GPGME */