2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "claws-features.h"
26 #include <glib/gi18n.h>
37 #include "procheader.h"
40 #include "prefs_common.h"
45 static gchar monthstr[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
47 typedef char *(*getlinefunc) (char *, size_t, void *);
48 typedef int (*peekcharfunc) (void *);
49 typedef int (*getcharfunc) (void *);
50 typedef gint (*get_one_field_func) (gchar *, size_t, void *, HeaderEntry[]);
52 static gint string_get_one_field(gchar *buf, size_t len, char **str,
53 HeaderEntry hentry[]);
55 static char *string_getline(char *buf, size_t len, char **str);
56 static int string_peekchar(char **str);
57 static int file_peekchar(FILE *fp);
58 static gint generic_get_one_field(gchar *buf, size_t len, void *data,
61 peekcharfunc peekchar,
63 static MsgInfo *parse_stream(void *data, gboolean isstring, MsgFlags flags,
64 gboolean full, gboolean decrypted);
67 gint procheader_get_one_field(gchar *buf, size_t len, FILE *fp,
70 return generic_get_one_field(buf, len, fp, hentry,
71 (getlinefunc)fgets_crlf, (peekcharfunc)file_peekchar,
75 static gint string_get_one_field(gchar *buf, size_t len, char **str,
78 return generic_get_one_field(buf, len, str, hentry,
79 (getlinefunc)string_getline,
80 (peekcharfunc)string_peekchar,
84 static char *string_getline(char *buf, size_t len, char **str)
86 gboolean is_cr = FALSE;
87 gboolean last_was_cr = FALSE;
92 for (; **str && len > 1; --len) {
93 is_cr = (**str == '\r');
94 if ((*buf++ = *(*str)++) == '\n') {
110 static int string_peekchar(char **str)
115 static int file_peekchar(FILE *fp)
117 return ungetc(getc(fp), fp);
120 static gint generic_get_one_field(gchar *buf, size_t len, void *data,
122 getlinefunc getline, peekcharfunc peekchar,
127 HeaderEntry *hp = NULL;
129 if (hentry != NULL) {
130 /* skip non-required headers */
133 if (getline(buf, len, data) == NULL)
135 if (buf[0] == '\r' || buf[0] == '\n')
137 } while (buf[0] == ' ' || buf[0] == '\t');
139 for (hp = hentry, hnum = 0; hp->name != NULL;
141 if (!g_ascii_strncasecmp(hp->name, buf,
145 } while (hp->name == NULL);
147 if (getline(buf, len, data) == NULL) return -1;
148 if (buf[0] == '\r' || buf[0] == '\n') return -1;
153 nexthead = peekchar(data);
154 /* ([*WSP CRLF] 1*WSP) */
155 if (nexthead == ' ' || nexthead == '\t') {
157 gboolean skiptab = (nexthead == '\t');
158 /* trim previous trailing \n if requesting one header or
159 * unfolding was requested */
160 if ((!hentry && unfold) || (hp && hp->unfold))
163 buflen = strlen(buf);
165 /* concatenate next line */
166 if ((len - buflen) > 2) {
167 if (getline(buf + buflen, len - buflen, data) == NULL)
169 if (skiptab) { /* replace tab with space */
170 *(buf + buflen) = ' ';
175 /* remove trailing new line */
184 gint procheader_get_one_field_asis(gchar *buf, size_t len, FILE *fp)
186 return generic_get_one_field(buf, len, fp, NULL,
187 (getlinefunc)fgets_crlf,
188 (peekcharfunc)file_peekchar,
192 GPtrArray *procheader_get_header_array_asis(FILE *fp)
198 cm_return_val_if_fail(fp != NULL, NULL);
200 headers = g_ptr_array_new();
202 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
203 if ((header = procheader_parse_header(buf)) != NULL)
204 g_ptr_array_add(headers, header);
210 void procheader_header_array_destroy(GPtrArray *harray)
215 for (i = 0; i < harray->len; i++) {
216 header = g_ptr_array_index(harray, i);
217 procheader_header_free(header);
220 g_ptr_array_free(harray, TRUE);
223 void procheader_header_free(Header *header)
227 g_free(header->name);
228 g_free(header->body);
233 tests whether two headers' names are equal
234 remove the trailing ':' or ' ' before comparing
237 gboolean procheader_headername_equal(char * hdr1, char * hdr2)
244 if (hdr1[len1 - 1] == ':')
246 if (hdr2[len2 - 1] == ':')
251 return (g_ascii_strncasecmp(hdr1, hdr2, len1) == 0);
255 parse headers, for example :
256 From: dinh@enseirb.fr becomes :
257 header->name = "From:"
258 header->body = "dinh@enseirb.fr"
260 static gboolean header_is_addr_field(const gchar *hdr)
262 static char *addr_headers[] = {
269 "Followup-and-Reply-To:",
270 "Disposition-Notification-To:",
271 "Return-Receipt-To:",
278 for (i = 0; addr_headers[i] != NULL; i++)
279 if (!strcasecmp(hdr, addr_headers[i]))
285 Header * procheader_parse_header(gchar * buf)
289 gboolean addr_field = FALSE;
291 if ((*buf == ':') || (*buf == ' '))
294 for (p = buf; *p ; p++) {
295 if ((*p == ':') || (*p == ' ')) {
296 header = g_new(Header, 1);
297 header->name = g_strndup(buf, p - buf + 1);
298 addr_field = header_is_addr_field(header->name);
300 while (*p == ' ' || *p == '\t') p++;
301 header->body = conv_unmime_header(p, NULL, addr_field);
308 void procheader_get_header_fields(FILE *fp, HeaderEntry hentry[])
315 if (hentry == NULL) return;
317 while ((hnum = procheader_get_one_field(buf, sizeof(buf), fp, hentry))
321 p = buf + strlen(hp->name);
322 while (*p == ' ' || *p == '\t') p++;
324 if (hp->body == NULL)
325 hp->body = g_strdup(p);
326 else if (procheader_headername_equal(hp->name, "To") ||
327 procheader_headername_equal(hp->name, "Cc")) {
328 gchar *tp = hp->body;
329 hp->body = g_strconcat(tp, ", ", p, NULL);
335 MsgInfo *procheader_parse_file(const gchar *file, MsgFlags flags,
336 gboolean full, gboolean decrypted)
342 if (g_stat(file, &s) < 0) {
343 FILE_OP_ERROR(file, "stat");
346 if (!S_ISREG(s.st_mode))
349 if ((fp = g_fopen(file, "rb")) == NULL) {
350 FILE_OP_ERROR(file, "fopen");
354 msginfo = procheader_parse_stream(fp, flags, full, decrypted);
358 msginfo->size = s.st_size;
359 msginfo->mtime = s.st_mtime;
365 MsgInfo *procheader_parse_str(const gchar *str, MsgFlags flags, gboolean full,
368 return parse_stream(&str, TRUE, flags, full, decrypted);
387 H_SC_PLANNED_DOWNLOAD = 14,
388 H_SC_MESSAGE_SIZE = 15,
391 H_DISPOSITION_NOTIFICATION_TO = 18,
392 H_RETURN_RECEIPT_TO = 19,
393 H_SC_PARTIALLY_RETRIEVED = 20,
394 H_SC_ACCOUNT_SERVER = 21,
395 H_SC_ACCOUNT_LOGIN = 22,
397 H_LIST_SUBSCRIBE = 24,
398 H_LIST_UNSUBSCRIBE = 25,
404 static HeaderEntry hentry_full[] = {{"Date:", NULL, FALSE},
405 {"From:", NULL, TRUE},
408 {"Newsgroups:", NULL, TRUE},
409 {"Subject:", NULL, TRUE},
410 {"Message-ID:", NULL, FALSE},
411 {"References:", NULL, FALSE},
412 {"In-Reply-To:", NULL, FALSE},
413 {"Content-Type:", NULL, FALSE},
414 {"Seen:", NULL, FALSE},
415 {"Status:", NULL, FALSE},
416 {"X-Status:", NULL, FALSE},
417 {"From ", NULL, FALSE},
418 {"SC-Marked-For-Download:", NULL, FALSE},
419 {"SC-Message-Size:", NULL, FALSE},
420 {"Face:", NULL, FALSE},
421 {"X-Face:", NULL, FALSE},
422 {"Disposition-Notification-To:", NULL, FALSE},
423 {"Return-Receipt-To:", NULL, FALSE},
424 {"SC-Partially-Retrieved:", NULL, FALSE},
425 {"SC-Account-Server:", NULL, FALSE},
426 {"SC-Account-Login:",NULL, FALSE},
427 {"List-Post:", NULL, TRUE},
428 {"List-Subscribe:", NULL, TRUE},
429 {"List-Unsubscribe:",NULL, TRUE},
430 {"List-Help:", NULL, TRUE},
431 {"List-Archive:", NULL, TRUE},
432 {"List-Owner:", NULL, TRUE},
433 {NULL, NULL, FALSE}};
435 static HeaderEntry hentry_short[] = {{"Date:", NULL, FALSE},
436 {"From:", NULL, TRUE},
439 {"Newsgroups:", NULL, TRUE},
440 {"Subject:", NULL, TRUE},
441 {"Message-ID:", NULL, FALSE},
442 {"References:", NULL, FALSE},
443 {"In-Reply-To:", NULL, FALSE},
444 {"Content-Type:", NULL, FALSE},
445 {"Seen:", NULL, FALSE},
446 {"Status:", NULL, FALSE},
447 {"X-Status:", NULL, FALSE},
448 {"From ", NULL, FALSE},
449 {"SC-Marked-For-Download:", NULL, FALSE},
450 {"SC-Message-Size:",NULL, FALSE},
451 {NULL, NULL, FALSE}};
453 static HeaderEntry* procheader_get_headernames(gboolean full)
455 return full ? hentry_full : hentry_short;
458 MsgInfo *procheader_parse_stream(FILE *fp, MsgFlags flags, gboolean full,
461 return parse_stream(fp, FALSE, flags, full, decrypted);
464 static MsgInfo *parse_stream(void *data, gboolean isstring, MsgFlags flags,
465 gboolean full, gboolean decrypted)
473 void *orig_data = data;
475 get_one_field_func get_one_field =
476 isstring ? (get_one_field_func)string_get_one_field
477 : (get_one_field_func)procheader_get_one_field;
479 hentry = procheader_get_headernames(full);
481 if (MSG_IS_QUEUED(flags) || MSG_IS_DRAFT(flags)) {
482 while (get_one_field(buf, sizeof(buf), data, NULL) != -1) {
483 if ((!strncmp(buf, "X-Claws-End-Special-Headers: 1",
484 strlen("X-Claws-End-Special-Headers:"))) ||
485 (!strncmp(buf, "X-Sylpheed-End-Special-Headers: 1",
486 strlen("X-Sylpheed-End-Special-Headers:"))))
488 /* from other mailers */
489 if (!strncmp(buf, "Date: ", 6)
490 || !strncmp(buf, "To: ", 4)
491 || !strncmp(buf, "From: ", 6)
492 || !strncmp(buf, "Subject: ", 9)) {
496 rewind((FILE *)data);
502 msginfo = procmsg_msginfo_new();
504 if (flags.tmp_flags || flags.perm_flags)
505 msginfo->flags = flags;
507 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_NEW | MSG_UNREAD);
509 msginfo->inreplyto = NULL;
511 while ((hnum = get_one_field(buf, sizeof(buf), data, hentry))
513 hp = buf + strlen(hentry[hnum].name);
514 while (*hp == ' ' || *hp == '\t') hp++;
518 if (msginfo->date) break;
520 procheader_date_parse(NULL, hp, 0);
521 if (g_utf8_validate(hp, -1, NULL)) {
522 msginfo->date = g_strdup(hp);
524 gchar *utf = conv_codeset_strdup(
526 conv_get_locale_charset_str_no_utf8(),
529 !g_utf8_validate(utf, -1, NULL)) {
531 utf = g_malloc(strlen(buf)*2+1);
532 conv_localetodisp(utf,
539 if (msginfo->from) break;
540 msginfo->from = conv_unmime_header(hp, NULL, TRUE);
541 msginfo->fromname = procheader_get_fromname(msginfo->from);
542 remove_return(msginfo->from);
543 remove_return(msginfo->fromname);
546 tmp = conv_unmime_header(hp, NULL, TRUE);
551 g_strconcat(p, ", ", tmp, NULL);
554 msginfo->to = g_strdup(tmp);
558 tmp = conv_unmime_header(hp, NULL, TRUE);
563 g_strconcat(p, ", ", tmp, NULL);
566 msginfo->cc = g_strdup(tmp);
570 if (msginfo->newsgroups) {
571 p = msginfo->newsgroups;
572 msginfo->newsgroups =
573 g_strconcat(p, ",", hp, NULL);
576 msginfo->newsgroups = g_strdup(hp);
579 if (msginfo->subject) break;
580 msginfo->subject = conv_unmime_header(hp, NULL, FALSE);
581 unfold_line(msginfo->subject);
584 if (msginfo->msgid) break;
586 extract_parenthesis(hp, '<', '>');
588 msginfo->msgid = g_strdup(hp);
591 msginfo->references =
592 references_list_prepend(msginfo->references,
596 if (msginfo->inreplyto) break;
598 eliminate_parenthesis(hp, '(', ')');
599 if ((p = strrchr(hp, '<')) != NULL &&
600 strchr(p + 1, '>') != NULL) {
601 extract_parenthesis(p, '<', '>');
604 msginfo->inreplyto = g_strdup(p);
608 if (!g_ascii_strncasecmp(hp, "multipart/", 10))
609 MSG_SET_TMP_FLAGS(msginfo->flags, MSG_MULTIPART);
611 #ifdef ALLOW_HEADER_HINT
613 /* mnews Seen header */
614 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_NEW|MSG_UNREAD);
618 if (!msginfo->extradata)
619 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
620 if (msginfo->extradata->face) break;
621 msginfo->extradata->face = g_strdup(hp);
624 if (!msginfo->extradata)
625 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
626 if (msginfo->extradata->xface) break;
627 msginfo->extradata->xface = g_strdup(hp);
629 case H_DISPOSITION_NOTIFICATION_TO:
630 if (!msginfo->extradata)
631 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
632 if (msginfo->extradata->dispositionnotificationto) break;
633 msginfo->extradata->dispositionnotificationto = g_strdup(hp);
635 case H_RETURN_RECEIPT_TO:
636 if (!msginfo->extradata)
637 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
638 if (msginfo->extradata->returnreceiptto) break;
639 msginfo->extradata->returnreceiptto = g_strdup(hp);
641 /* partial download infos */
642 case H_SC_PARTIALLY_RETRIEVED:
643 if (!msginfo->extradata)
644 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
645 if (msginfo->extradata->partial_recv) break;
646 msginfo->extradata->partial_recv = g_strdup(hp);
648 case H_SC_ACCOUNT_SERVER:
649 if (!msginfo->extradata)
650 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
651 if (msginfo->extradata->account_server) break;
652 msginfo->extradata->account_server = g_strdup(hp);
654 case H_SC_ACCOUNT_LOGIN:
655 if (!msginfo->extradata)
656 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
657 if (msginfo->extradata->account_login) break;
658 msginfo->extradata->account_login = g_strdup(hp);
660 case H_SC_MESSAGE_SIZE:
661 if (msginfo->total_size) break;
662 msginfo->total_size = atoi(hp);
664 case H_SC_PLANNED_DOWNLOAD:
665 msginfo->planned_download = atoi(hp);
667 /* end partial download infos */
668 #ifdef ALLOW_HEADER_HINT
670 if (strchr(hp, 'R') != NULL)
671 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_UNREAD);
672 if (strchr(hp, 'O') != NULL)
673 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_NEW);
674 if (strchr(hp, 'U') != NULL)
675 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_UNREAD);
678 if (strchr(hp, 'D') != NULL)
679 MSG_SET_PERM_FLAGS(msginfo->flags,
681 if (strchr(hp, 'F') != NULL)
682 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_MARKED);
683 if (strchr(hp, 'd') != NULL)
684 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_DELETED);
685 if (strchr(hp, 'r') != NULL)
686 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
687 if (strchr(hp, 'f') != NULL)
688 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
692 if (msginfo->fromspace) break;
693 msginfo->fromspace = g_strdup(hp);
694 remove_return(msginfo->fromspace);
698 if (!msginfo->extradata)
699 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
700 if (msginfo->extradata->list_post) break;
701 msginfo->extradata->list_post = g_strdup(hp);
703 case H_LIST_SUBSCRIBE:
704 if (!msginfo->extradata)
705 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
706 if (msginfo->extradata->list_subscribe) break;
707 msginfo->extradata->list_subscribe = g_strdup(hp);
709 case H_LIST_UNSUBSCRIBE:
710 if (!msginfo->extradata)
711 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
712 if (msginfo->extradata->list_unsubscribe) break;
713 msginfo->extradata->list_unsubscribe = g_strdup(hp);
716 if (!msginfo->extradata)
717 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
718 if (msginfo->extradata->list_help) break;
719 msginfo->extradata->list_help = g_strdup(hp);
722 if (!msginfo->extradata)
723 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
724 if (msginfo->extradata->list_archive) break;
725 msginfo->extradata->list_archive = g_strdup(hp);
728 if (!msginfo->extradata)
729 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
730 if (msginfo->extradata->list_owner) break;
731 msginfo->extradata->list_owner = g_strdup(hp);
739 if (!msginfo->inreplyto && msginfo->references)
741 g_strdup((gchar *)msginfo->references->data);
746 gchar *procheader_get_fromname(const gchar *str)
750 Xstrdup_a(tmp, str, return NULL);
753 extract_quote(tmp, '\"');
755 } else if (strchr(tmp, '<')) {
756 eliminate_parenthesis(tmp, '<', '>');
760 extract_parenthesis(tmp, '<', '>');
763 } else if (strchr(tmp, '(')) {
764 extract_parenthesis(tmp, '(', ')');
769 name = g_strdup(str);
771 name = g_strdup(tmp);
776 static gint procheader_scan_date_string(const gchar *str,
777 gchar *weekday, gint *day,
778 gchar *month, gint *year,
779 gint *hh, gint *mm, gint *ss,
790 result = sscanf(str, "%10s %d %9s %d %2d:%2d:%2d %5s",
791 weekday, day, month, year, hh, mm, ss, zone);
792 if (result == 8) return 0;
795 result = sscanf(str, "%3s,%d %9s %d %2d:%2d:%2d %5s",
796 weekday, day, month, year, hh, mm, ss, zone);
797 if (result == 8) return 0;
799 result = sscanf(str, "%d %9s %d %2d:%2d:%2d %5s",
800 day, month, year, hh, mm, ss, zone);
801 if (result == 7) return 0;
804 result = sscanf(str, "%10s %d %9s %d %2d:%2d:%2d",
805 weekday, day, month, year, hh, mm, ss);
806 if (result == 7) return 0;
808 result = sscanf(str, "%d %9s %d %2d:%2d:%2d",
809 day, month, year, hh, mm, ss);
810 if (result == 6) return 0;
813 result = sscanf(str, "%10s %d %9s %d %2d:%2d %5s",
814 weekday, day, month, year, hh, mm, zone);
815 if (result == 7) return 0;
817 result = sscanf(str, "%d %9s %d %2d:%2d %5s",
818 day, month, year, hh, mm, zone);
819 if (result == 6) return 0;
822 result = sscanf(str, "%10s %d %9s %d %2d:%2d",
823 weekday, day, month, year, hh, mm);
824 if (result == 6) return 0;
826 result = sscanf(str, "%d %9s %d %2d:%2d",
827 day, month, year, hh, mm);
828 if (result == 5) return 0;
832 result = sscanf(str, "%4d-%2d-%2d %2d:%2d:%2d+%2s:%2s",
833 year, &month_n, day, hh, mm, ss, zone1, zone2);
835 if (1 <= month_n && month_n <= 12) {
836 strncpy2(month, monthstr+((month_n-1)*3), 4);
838 strncpy2(zone+1, zone1, 3);
839 strncpy2(zone+3, zone2, 3);
847 result = sscanf(str, "%4d-%2d-%2d %2d:%2d:%2d",
848 year, &month_n, day, hh, mm, ss);
850 if (1 <= month_n && month_n <= 12) {
851 strncpy2(month, monthstr+((month_n-1)*3), 4);
860 * Hiro, most UNIXen support this function:
861 * http://www.mcsr.olemiss.edu/cgi-bin/man-cgi?getdate
863 gboolean procheader_date_parse_to_tm(const gchar *src, struct tm *t, char *zone)
876 memset(t, 0, sizeof *t);
878 if (procheader_scan_date_string(src, weekday, &day, month, &year,
879 &hh, &mm, &ss, zone) < 0) {
880 g_warning("Invalid date: %s\n", src);
884 /* Y2K compliant :) */
893 if ((p = strstr(monthstr, month)) != NULL)
894 dmonth = (gint)(p - monthstr) / 3 + 1;
896 g_warning("Invalid month: %s\n", month);
897 dmonth = G_DATE_BAD_MONTH;
904 t->tm_mon = dmonth - 1;
905 t->tm_year = year - 1900;
915 time_t procheader_date_parse(gchar *dest, const gchar *src, gint len)
923 GDateMonth dmonth = G_DATE_BAD_MONTH;
929 if (procheader_scan_date_string(src, weekday, &day, month, &year,
930 &hh, &mm, &ss, zone) < 0) {
932 strncpy2(dest, src, len);
936 /* Y2K compliant :) */
945 for (p = monthstr; *p != '\0'; p += 3) {
946 if (!g_ascii_strncasecmp(p, month, 3)) {
947 dmonth = (gint)(p - monthstr) / 3 + 1;
956 t.tm_mon = dmonth - 1;
957 t.tm_year = year - 1900;
963 tz_offset = remote_tzoffset_sec(zone);
965 timer += tzoffset_sec(&timer) - tz_offset;
968 procheader_date_get_localtime(dest, len, timer);
973 void procheader_date_get_localtime(gchar *dest, gint len, const time_t timer)
976 gchar *default_format = "%y/%m/%d(%a) %H:%M";
978 const gchar *src_codeset, *dest_codeset;
982 lt = localtime_r(&timer, &buf);
985 lt = localtime_r(&dummy, &buf);
988 if (prefs_common.date_format)
989 fast_strftime(dest, len, prefs_common.date_format, lt);
991 fast_strftime(dest, len, default_format, lt);
993 if (!g_utf8_validate(dest, -1, NULL)) {
994 src_codeset = conv_get_locale_charset_str_no_utf8();
995 dest_codeset = CS_UTF_8;
996 str = conv_codeset_strdup(dest, src_codeset, dest_codeset);
998 strncpy2(dest, str, len);
1004 /* Added by Mel Hadasht on 27 Aug 2001 */
1005 /* Get a header from msginfo */
1006 gint procheader_get_header_from_msginfo(MsgInfo *msginfo, gchar *buf, gint len, gchar *header)
1010 HeaderEntry hentry[]={ { NULL, NULL, TRUE },
1011 { NULL, NULL, FALSE } };
1014 hentry[0].name = header;
1016 cm_return_val_if_fail(msginfo != NULL, -1);
1017 file = procmsg_get_message_file_path(msginfo);
1018 if ((fp = g_fopen(file, "rb")) == NULL) {
1019 FILE_OP_ERROR(file, "fopen");
1023 val = procheader_get_one_field(buf,len, fp, hentry);
1024 if (fclose(fp) == EOF) {
1025 FILE_OP_ERROR(file, "fclose");
1038 HeaderEntry *procheader_entries_from_str(const gchar *str)
1040 HeaderEntry *entries = NULL, *he;
1041 int numh = 0, i = 0;
1042 gchar **names = NULL;
1043 const gchar *s = str;
1048 while (*s != '\0') {
1049 if (*s == ' ') ++numh;
1055 entries = g_new0(HeaderEntry, numh + 1); /* room for last NULL */
1057 ++s; /* skip first space */
1058 names = g_strsplit(s, " ", numh);
1061 he->name = g_strdup_printf("%s:", names[i]);
1071 void procheader_entries_free (HeaderEntry *entries)
1073 if (entries != NULL) {
1074 HeaderEntry *he = entries;
1075 while (he->name != NULL) {
1077 if (he->body != NULL)