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"
34 gchar *fp_read_noconv(FILE *fp)
43 array = g_byte_array_new();
45 while ((n_read = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
46 if (n_read < sizeof(buf) && ferror(fp))
48 g_byte_array_append(array, buf, n_read);
52 FILE_OP_ERROR("file stream", "fread");
53 g_byte_array_free(array, TRUE);
58 g_byte_array_append(array, buf, 1);
59 result = (gchar *)array->data;
60 g_byte_array_free(array, FALSE);
65 gchar *get_part_as_string(MimeInfo *mimeinfo)
67 gchar *textdata = NULL;
68 gchar *filename = NULL;
71 cm_return_val_if_fail(mimeinfo != NULL, 0);
72 procmime_decode_content(mimeinfo);
74 if (mimeinfo->content == MIMECONTENT_MEM)
75 textdata = g_strdup(mimeinfo->data.mem);
77 filename = procmime_get_tmp_file_name(mimeinfo);
78 if (procmime_get_part(filename, mimeinfo) < 0) {
79 printf("error dumping file\n");
82 fp = g_fopen(filename,"rb");
84 printf("error reading file\n");
87 textdata = fp_read_noconv(fp);
93 if (!g_utf8_validate(textdata, -1, NULL)) {
95 codeconv_set_strict(TRUE);
96 if (procmime_mimeinfo_get_parameter(mimeinfo, "charset")) {
97 tmp = conv_codeset_strdup(textdata,
98 procmime_mimeinfo_get_parameter(mimeinfo, "charset"),
102 tmp = conv_codeset_strdup(textdata,
103 conv_get_locale_charset_str_no_utf8(),
106 codeconv_set_strict(FALSE);
108 tmp = conv_codeset_strdup(textdata,
109 conv_get_locale_charset_str_no_utf8(),
121 gchar *pgp_locate_armor_header(gchar *textdata, const gchar *armor_header)
125 pos = strstr(textdata, armor_header);
127 * It's only a valid armor header if it's at the
128 * beginning of the buffer or a new line.
130 if (pos != NULL && (pos == textdata || *(pos-1) == '\n'))
136 #endif /* USE_GPGME */