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"
46 static gchar monthstr[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
48 typedef char *(*getlinefunc) (char *, size_t, void *);
49 typedef int (*peekcharfunc) (void *);
50 typedef int (*getcharfunc) (void *);
51 typedef gint (*get_one_field_func) (gchar *, size_t, void *, HeaderEntry[]);
53 static gint string_get_one_field(gchar *buf, size_t len, char **str,
54 HeaderEntry hentry[]);
56 static char *string_getline(char *buf, size_t len, char **str);
57 static int string_peekchar(char **str);
58 static int file_peekchar(FILE *fp);
59 static gint generic_get_one_field(gchar *buf, size_t len, void *data,
62 peekcharfunc peekchar,
64 static MsgInfo *parse_stream(void *data, gboolean isstring, MsgFlags flags,
65 gboolean full, gboolean decrypted);
68 gint procheader_get_one_field(gchar *buf, size_t len, FILE *fp,
71 return generic_get_one_field(buf, len, fp, hentry,
72 (getlinefunc)fgets_crlf, (peekcharfunc)file_peekchar,
76 static gint string_get_one_field(gchar *buf, size_t len, char **str,
79 return generic_get_one_field(buf, len, str, hentry,
80 (getlinefunc)string_getline,
81 (peekcharfunc)string_peekchar,
85 static char *string_getline(char *buf, size_t len, char **str)
87 gboolean is_cr = FALSE;
88 gboolean last_was_cr = FALSE;
93 for (; **str && len > 1; --len) {
94 is_cr = (**str == '\r');
95 if ((*buf++ = *(*str)++) == '\n') {
111 static int string_peekchar(char **str)
116 static int file_peekchar(FILE *fp)
118 return ungetc(getc(fp), fp);
121 static gint generic_get_one_field(gchar *buf, size_t len, void *data,
123 getlinefunc getline, peekcharfunc peekchar,
128 HeaderEntry *hp = NULL;
130 if (hentry != NULL) {
131 /* skip non-required headers */
134 if (getline(buf, len, data) == NULL)
136 if (buf[0] == '\r' || buf[0] == '\n')
138 } while (buf[0] == ' ' || buf[0] == '\t');
140 for (hp = hentry, hnum = 0; hp->name != NULL;
142 if (!g_ascii_strncasecmp(hp->name, buf,
146 } while (hp->name == NULL);
148 if (getline(buf, len, data) == NULL) return -1;
149 if (buf[0] == '\r' || buf[0] == '\n') return -1;
154 nexthead = peekchar(data);
155 /* ([*WSP CRLF] 1*WSP) */
156 if (nexthead == ' ' || nexthead == '\t') {
158 gboolean skiptab = (nexthead == '\t');
159 /* trim previous trailing \n if requesting one header or
160 * unfolding was requested */
161 if ((!hentry && unfold) || (hp && hp->unfold))
164 buflen = strlen(buf);
166 /* concatenate next line */
167 if ((len - buflen) > 2) {
168 if (getline(buf + buflen, len - buflen, data) == NULL)
170 if (skiptab) { /* replace tab with space */
171 *(buf + buflen) = ' ';
176 /* remove trailing new line */
185 gint procheader_get_one_field_asis(gchar *buf, size_t len, FILE *fp)
187 return generic_get_one_field(buf, len, fp, NULL,
188 (getlinefunc)fgets_crlf,
189 (peekcharfunc)file_peekchar,
193 GPtrArray *procheader_get_header_array_asis(FILE *fp)
199 cm_return_val_if_fail(fp != NULL, NULL);
201 headers = g_ptr_array_new();
203 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
204 if ((header = procheader_parse_header(buf)) != NULL)
205 g_ptr_array_add(headers, header);
211 void procheader_header_array_destroy(GPtrArray *harray)
216 for (i = 0; i < harray->len; i++) {
217 header = g_ptr_array_index(harray, i);
218 procheader_header_free(header);
221 g_ptr_array_free(harray, TRUE);
224 void procheader_header_free(Header *header)
228 g_free(header->name);
229 g_free(header->body);
234 tests whether two headers' names are equal
235 remove the trailing ':' or ' ' before comparing
238 gboolean procheader_headername_equal(char * hdr1, char * hdr2)
245 if (hdr1[len1 - 1] == ':')
247 if (hdr2[len2 - 1] == ':')
252 return (g_ascii_strncasecmp(hdr1, hdr2, len1) == 0);
256 parse headers, for example :
257 From: dinh@enseirb.fr becomes :
258 header->name = "From:"
259 header->body = "dinh@enseirb.fr"
261 static gboolean header_is_addr_field(const gchar *hdr)
263 static char *addr_headers[] = {
270 "Followup-and-Reply-To:",
271 "Disposition-Notification-To:",
272 "Return-Receipt-To:",
279 for (i = 0; addr_headers[i] != NULL; i++)
280 if (!strcasecmp(hdr, addr_headers[i]))
286 Header * procheader_parse_header(gchar * buf)
290 gboolean addr_field = FALSE;
292 if ((*buf == ':') || (*buf == ' '))
295 for (p = buf; *p ; p++) {
296 if ((*p == ':') || (*p == ' ')) {
297 header = g_new(Header, 1);
298 header->name = g_strndup(buf, p - buf + 1);
299 addr_field = header_is_addr_field(header->name);
301 while (*p == ' ' || *p == '\t') p++;
302 header->body = conv_unmime_header(p, NULL, addr_field);
309 void procheader_get_header_fields(FILE *fp, HeaderEntry hentry[])
316 if (hentry == NULL) return;
318 while ((hnum = procheader_get_one_field(buf, sizeof(buf), fp, hentry))
322 p = buf + strlen(hp->name);
323 while (*p == ' ' || *p == '\t') p++;
325 if (hp->body == NULL)
326 hp->body = g_strdup(p);
327 else if (procheader_headername_equal(hp->name, "To") ||
328 procheader_headername_equal(hp->name, "Cc")) {
329 gchar *tp = hp->body;
330 hp->body = g_strconcat(tp, ", ", p, NULL);
336 MsgInfo *procheader_parse_file(const gchar *file, MsgFlags flags,
337 gboolean full, gboolean decrypted)
343 if (g_stat(file, &s) < 0) {
344 FILE_OP_ERROR(file, "stat");
347 if (!S_ISREG(s.st_mode))
350 if ((fp = g_fopen(file, "rb")) == NULL) {
351 FILE_OP_ERROR(file, "fopen");
355 msginfo = procheader_parse_stream(fp, flags, full, decrypted);
359 msginfo->size = s.st_size;
360 msginfo->mtime = s.st_mtime;
366 MsgInfo *procheader_parse_str(const gchar *str, MsgFlags flags, gboolean full,
369 return parse_stream(&str, TRUE, flags, full, decrypted);
388 H_SC_PLANNED_DOWNLOAD = 14,
389 H_SC_MESSAGE_SIZE = 15,
392 H_DISPOSITION_NOTIFICATION_TO = 18,
393 H_RETURN_RECEIPT_TO = 19,
394 H_SC_PARTIALLY_RETRIEVED = 20,
395 H_SC_ACCOUNT_SERVER = 21,
396 H_SC_ACCOUNT_LOGIN = 22,
398 H_LIST_SUBSCRIBE = 24,
399 H_LIST_UNSUBSCRIBE = 25,
405 static HeaderEntry hentry_full[] = {{"Date:", NULL, FALSE},
406 {"From:", NULL, TRUE},
409 {"Newsgroups:", NULL, TRUE},
410 {"Subject:", NULL, TRUE},
411 {"Message-ID:", NULL, FALSE},
412 {"References:", NULL, FALSE},
413 {"In-Reply-To:", NULL, FALSE},
414 {"Content-Type:", NULL, FALSE},
415 {"Seen:", NULL, FALSE},
416 {"Status:", NULL, FALSE},
417 {"X-Status:", NULL, FALSE},
418 {"From ", NULL, FALSE},
419 {"SC-Marked-For-Download:", NULL, FALSE},
420 {"SC-Message-Size:", NULL, FALSE},
421 {"Face:", NULL, FALSE},
422 {"X-Face:", NULL, FALSE},
423 {"Disposition-Notification-To:", NULL, FALSE},
424 {"Return-Receipt-To:", NULL, FALSE},
425 {"SC-Partially-Retrieved:", NULL, FALSE},
426 {"SC-Account-Server:", NULL, FALSE},
427 {"SC-Account-Login:",NULL, FALSE},
428 {"List-Post:", NULL, TRUE},
429 {"List-Subscribe:", NULL, TRUE},
430 {"List-Unsubscribe:",NULL, TRUE},
431 {"List-Help:", NULL, TRUE},
432 {"List-Archive:", NULL, TRUE},
433 {"List-Owner:", NULL, TRUE},
434 {NULL, NULL, FALSE}};
436 static HeaderEntry hentry_short[] = {{"Date:", NULL, FALSE},
437 {"From:", NULL, TRUE},
440 {"Newsgroups:", NULL, TRUE},
441 {"Subject:", NULL, TRUE},
442 {"Message-ID:", NULL, FALSE},
443 {"References:", NULL, FALSE},
444 {"In-Reply-To:", NULL, FALSE},
445 {"Content-Type:", NULL, FALSE},
446 {"Seen:", NULL, FALSE},
447 {"Status:", NULL, FALSE},
448 {"X-Status:", NULL, FALSE},
449 {"From ", NULL, FALSE},
450 {"SC-Marked-For-Download:", NULL, FALSE},
451 {"SC-Message-Size:",NULL, FALSE},
452 {NULL, NULL, FALSE}};
454 static HeaderEntry* procheader_get_headernames(gboolean full)
456 return full ? hentry_full : hentry_short;
459 MsgInfo *procheader_parse_stream(FILE *fp, MsgFlags flags, gboolean full,
462 return parse_stream(fp, FALSE, flags, full, decrypted);
465 static MsgInfo *parse_stream(void *data, gboolean isstring, MsgFlags flags,
466 gboolean full, gboolean decrypted)
469 MsgInfoAvatar *avatar;
475 void *orig_data = data;
477 get_one_field_func get_one_field =
478 isstring ? (get_one_field_func)string_get_one_field
479 : (get_one_field_func)procheader_get_one_field;
481 hentry = procheader_get_headernames(full);
483 if (MSG_IS_QUEUED(flags) || MSG_IS_DRAFT(flags)) {
484 while (get_one_field(buf, sizeof(buf), data, NULL) != -1) {
485 if ((!strncmp(buf, "X-Claws-End-Special-Headers: 1",
486 strlen("X-Claws-End-Special-Headers:"))) ||
487 (!strncmp(buf, "X-Sylpheed-End-Special-Headers: 1",
488 strlen("X-Sylpheed-End-Special-Headers:"))))
490 /* from other mailers */
491 if (!strncmp(buf, "Date: ", 6)
492 || !strncmp(buf, "To: ", 4)
493 || !strncmp(buf, "From: ", 6)
494 || !strncmp(buf, "Subject: ", 9)) {
498 rewind((FILE *)data);
504 msginfo = procmsg_msginfo_new();
506 if (flags.tmp_flags || flags.perm_flags)
507 msginfo->flags = flags;
509 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_NEW | MSG_UNREAD);
511 msginfo->inreplyto = NULL;
513 while ((hnum = get_one_field(buf, sizeof(buf), data, hentry))
515 hp = buf + strlen(hentry[hnum].name);
516 while (*hp == ' ' || *hp == '\t') hp++;
520 if (msginfo->date) break;
522 procheader_date_parse(NULL, hp, 0);
523 if (g_utf8_validate(hp, -1, NULL)) {
524 msginfo->date = g_strdup(hp);
526 gchar *utf = conv_codeset_strdup(
528 conv_get_locale_charset_str_no_utf8(),
531 !g_utf8_validate(utf, -1, NULL)) {
533 utf = g_malloc(strlen(buf)*2+1);
534 conv_localetodisp(utf,
541 if (msginfo->from) break;
542 msginfo->from = conv_unmime_header(hp, NULL, TRUE);
543 msginfo->fromname = procheader_get_fromname(msginfo->from);
544 remove_return(msginfo->from);
545 remove_return(msginfo->fromname);
548 tmp = conv_unmime_header(hp, NULL, TRUE);
553 g_strconcat(p, ", ", tmp, NULL);
556 msginfo->to = g_strdup(tmp);
560 tmp = conv_unmime_header(hp, NULL, TRUE);
565 g_strconcat(p, ", ", tmp, NULL);
568 msginfo->cc = g_strdup(tmp);
572 if (msginfo->newsgroups) {
573 p = msginfo->newsgroups;
574 msginfo->newsgroups =
575 g_strconcat(p, ",", hp, NULL);
578 msginfo->newsgroups = g_strdup(hp);
581 if (msginfo->subject) break;
582 msginfo->subject = conv_unmime_header(hp, NULL, FALSE);
583 unfold_line(msginfo->subject);
586 if (msginfo->msgid) break;
588 extract_parenthesis(hp, '<', '>');
590 msginfo->msgid = g_strdup(hp);
593 msginfo->references =
594 references_list_prepend(msginfo->references,
598 if (msginfo->inreplyto) break;
600 eliminate_parenthesis(hp, '(', ')');
601 if ((p = strrchr(hp, '<')) != NULL &&
602 strchr(p + 1, '>') != NULL) {
603 extract_parenthesis(p, '<', '>');
606 msginfo->inreplyto = g_strdup(p);
610 if (!g_ascii_strncasecmp(hp, "multipart/", 10))
611 MSG_SET_TMP_FLAGS(msginfo->flags, MSG_MULTIPART);
613 #ifdef ALLOW_HEADER_HINT
615 /* mnews Seen header */
616 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_NEW|MSG_UNREAD);
620 if (!msginfo->extradata)
621 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
622 avatar = g_new0(MsgInfoAvatar, 1);
623 avatar->avatar_id = AVATAR_FACE;
624 avatar->avatar_src = g_strdup(hp);
625 msginfo->extradata->avatars = g_slist_append(msginfo->extradata->avatars, avatar);
628 if (!msginfo->extradata)
629 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
630 avatar = g_new0(MsgInfoAvatar, 1);
631 avatar->avatar_id = AVATAR_XFACE;
632 avatar->avatar_src = g_strdup(hp);
633 msginfo->extradata->avatars = g_slist_append(msginfo->extradata->avatars, avatar);
635 case H_DISPOSITION_NOTIFICATION_TO:
636 if (!msginfo->extradata)
637 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
638 if (msginfo->extradata->dispositionnotificationto) break;
639 msginfo->extradata->dispositionnotificationto = g_strdup(hp);
641 case H_RETURN_RECEIPT_TO:
642 if (!msginfo->extradata)
643 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
644 if (msginfo->extradata->returnreceiptto) break;
645 msginfo->extradata->returnreceiptto = g_strdup(hp);
647 /* partial download infos */
648 case H_SC_PARTIALLY_RETRIEVED:
649 if (!msginfo->extradata)
650 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
651 if (msginfo->extradata->partial_recv) break;
652 msginfo->extradata->partial_recv = g_strdup(hp);
654 case H_SC_ACCOUNT_SERVER:
655 if (!msginfo->extradata)
656 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
657 if (msginfo->extradata->account_server) break;
658 msginfo->extradata->account_server = g_strdup(hp);
660 case H_SC_ACCOUNT_LOGIN:
661 if (!msginfo->extradata)
662 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
663 if (msginfo->extradata->account_login) break;
664 msginfo->extradata->account_login = g_strdup(hp);
666 case H_SC_MESSAGE_SIZE:
667 if (msginfo->total_size) break;
668 msginfo->total_size = atoi(hp);
670 case H_SC_PLANNED_DOWNLOAD:
671 msginfo->planned_download = atoi(hp);
673 /* end partial download infos */
674 #ifdef ALLOW_HEADER_HINT
676 if (strchr(hp, 'R') != NULL)
677 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_UNREAD);
678 if (strchr(hp, 'O') != NULL)
679 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_NEW);
680 if (strchr(hp, 'U') != NULL)
681 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_UNREAD);
684 if (strchr(hp, 'D') != NULL)
685 MSG_SET_PERM_FLAGS(msginfo->flags,
687 if (strchr(hp, 'F') != NULL)
688 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_MARKED);
689 if (strchr(hp, 'd') != NULL)
690 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_DELETED);
691 if (strchr(hp, 'r') != NULL)
692 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
693 if (strchr(hp, 'f') != NULL)
694 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
698 if (msginfo->fromspace) break;
699 msginfo->fromspace = g_strdup(hp);
700 remove_return(msginfo->fromspace);
704 if (!msginfo->extradata)
705 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
706 if (msginfo->extradata->list_post) break;
707 msginfo->extradata->list_post = g_strdup(hp);
709 case H_LIST_SUBSCRIBE:
710 if (!msginfo->extradata)
711 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
712 if (msginfo->extradata->list_subscribe) break;
713 msginfo->extradata->list_subscribe = g_strdup(hp);
715 case H_LIST_UNSUBSCRIBE:
716 if (!msginfo->extradata)
717 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
718 if (msginfo->extradata->list_unsubscribe) break;
719 msginfo->extradata->list_unsubscribe = g_strdup(hp);
722 if (!msginfo->extradata)
723 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
724 if (msginfo->extradata->list_help) break;
725 msginfo->extradata->list_help = g_strdup(hp);
728 if (!msginfo->extradata)
729 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
730 if (msginfo->extradata->list_archive) break;
731 msginfo->extradata->list_archive = g_strdup(hp);
734 if (!msginfo->extradata)
735 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
736 if (msginfo->extradata->list_owner) break;
737 msginfo->extradata->list_owner = g_strdup(hp);
745 if (!msginfo->inreplyto && msginfo->references)
747 g_strdup((gchar *)msginfo->references->data);
752 gchar *procheader_get_fromname(const gchar *str)
756 Xstrdup_a(tmp, str, return NULL);
759 extract_quote(tmp, '\"');
761 } else if (strchr(tmp, '<')) {
762 eliminate_parenthesis(tmp, '<', '>');
766 extract_parenthesis(tmp, '<', '>');
769 } else if (strchr(tmp, '(')) {
770 extract_parenthesis(tmp, '(', ')');
775 name = g_strdup(str);
777 name = g_strdup(tmp);
782 static gint procheader_scan_date_string(const gchar *str,
783 gchar *weekday, gint *day,
784 gchar *month, gint *year,
785 gint *hh, gint *mm, gint *ss,
796 result = sscanf(str, "%10s %d %9s %d %2d:%2d:%2d %5s",
797 weekday, day, month, year, hh, mm, ss, zone);
798 if (result == 8) return 0;
801 result = sscanf(str, "%3s,%d %9s %d %2d:%2d:%2d %5s",
802 weekday, day, month, year, hh, mm, ss, zone);
803 if (result == 8) return 0;
805 result = sscanf(str, "%d %9s %d %2d:%2d:%2d %5s",
806 day, month, year, hh, mm, ss, zone);
807 if (result == 7) return 0;
810 result = sscanf(str, "%10s %d %9s %d %2d:%2d:%2d",
811 weekday, day, month, year, hh, mm, ss);
812 if (result == 7) return 0;
814 result = sscanf(str, "%d %9s %d %2d:%2d:%2d",
815 day, month, year, hh, mm, ss);
816 if (result == 6) return 0;
819 result = sscanf(str, "%10s %d %9s %d %2d:%2d %5s",
820 weekday, day, month, year, hh, mm, zone);
821 if (result == 7) return 0;
823 result = sscanf(str, "%d %9s %d %2d:%2d %5s",
824 day, month, year, hh, mm, zone);
825 if (result == 6) return 0;
828 result = sscanf(str, "%10s %d %9s %d %2d:%2d",
829 weekday, day, month, year, hh, mm);
830 if (result == 6) return 0;
832 result = sscanf(str, "%d %9s %d %2d:%2d",
833 day, month, year, hh, mm);
834 if (result == 5) return 0;
838 result = sscanf(str, "%4d-%2d-%2d %2d:%2d:%2d+%2s:%2s",
839 year, &month_n, day, hh, mm, ss, zone1, zone2);
841 if (1 <= month_n && month_n <= 12) {
842 strncpy2(month, monthstr+((month_n-1)*3), 4);
844 strncpy2(zone+1, zone1, 3);
845 strncpy2(zone+3, zone2, 3);
853 result = sscanf(str, "%4d-%2d-%2d %2d:%2d:%2d",
854 year, &month_n, day, hh, mm, ss);
856 if (1 <= month_n && month_n <= 12) {
857 strncpy2(month, monthstr+((month_n-1)*3), 4);
866 * Hiro, most UNIXen support this function:
867 * http://www.mcsr.olemiss.edu/cgi-bin/man-cgi?getdate
869 gboolean procheader_date_parse_to_tm(const gchar *src, struct tm *t, char *zone)
882 memset(t, 0, sizeof *t);
884 if (procheader_scan_date_string(src, weekday, &day, month, &year,
885 &hh, &mm, &ss, zone) < 0) {
886 g_warning("Invalid date: %s\n", src);
890 /* Y2K compliant :) */
899 if ((p = strstr(monthstr, month)) != NULL)
900 dmonth = (gint)(p - monthstr) / 3 + 1;
902 g_warning("Invalid month: %s\n", month);
903 dmonth = G_DATE_BAD_MONTH;
910 t->tm_mon = dmonth - 1;
911 t->tm_year = year - 1900;
921 time_t procheader_date_parse(gchar *dest, const gchar *src, gint len)
929 GDateMonth dmonth = G_DATE_BAD_MONTH;
935 if (procheader_scan_date_string(src, weekday, &day, month, &year,
936 &hh, &mm, &ss, zone) < 0) {
938 strncpy2(dest, src, len);
942 /* Y2K compliant :) */
951 for (p = monthstr; *p != '\0'; p += 3) {
952 if (!g_ascii_strncasecmp(p, month, 3)) {
953 dmonth = (gint)(p - monthstr) / 3 + 1;
962 t.tm_mon = dmonth - 1;
963 t.tm_year = year - 1900;
969 tz_offset = remote_tzoffset_sec(zone);
971 timer += tzoffset_sec(&timer) - tz_offset;
974 procheader_date_get_localtime(dest, len, timer);
979 void procheader_date_get_localtime(gchar *dest, gint len, const time_t timer)
982 gchar *default_format = "%y/%m/%d(%a) %H:%M";
984 const gchar *src_codeset, *dest_codeset;
988 lt = localtime_r(&timer, &buf);
991 lt = localtime_r(&dummy, &buf);
994 if (prefs_common.date_format)
995 fast_strftime(dest, len, prefs_common.date_format, lt);
997 fast_strftime(dest, len, default_format, lt);
999 if (!g_utf8_validate(dest, -1, NULL)) {
1000 src_codeset = conv_get_locale_charset_str_no_utf8();
1001 dest_codeset = CS_UTF_8;
1002 str = conv_codeset_strdup(dest, src_codeset, dest_codeset);
1004 strncpy2(dest, str, len);
1010 /* Added by Mel Hadasht on 27 Aug 2001 */
1011 /* Get a header from msginfo */
1012 gint procheader_get_header_from_msginfo(MsgInfo *msginfo, gchar *buf, gint len, gchar *header)
1016 HeaderEntry hentry[]={ { NULL, NULL, TRUE },
1017 { NULL, NULL, FALSE } };
1020 hentry[0].name = header;
1022 cm_return_val_if_fail(msginfo != NULL, -1);
1023 file = procmsg_get_message_file_path(msginfo);
1024 if ((fp = g_fopen(file, "rb")) == NULL) {
1025 FILE_OP_ERROR(file, "fopen");
1029 val = procheader_get_one_field(buf,len, fp, hentry);
1030 if (fclose(fp) == EOF) {
1031 FILE_OP_ERROR(file, "fclose");
1044 HeaderEntry *procheader_entries_from_str(const gchar *str)
1046 HeaderEntry *entries = NULL, *he;
1047 int numh = 0, i = 0;
1048 gchar **names = NULL;
1049 const gchar *s = str;
1054 while (*s != '\0') {
1055 if (*s == ' ') ++numh;
1061 entries = g_new0(HeaderEntry, numh + 1); /* room for last NULL */
1063 ++s; /* skip first space */
1064 names = g_strsplit(s, " ", numh);
1067 he->name = g_strdup_printf("%s:", names[i]);
1077 void procheader_entries_free (HeaderEntry *entries)
1079 if (entries != NULL) {
1080 HeaderEntry *he = entries;
1081 while (he->name != NULL) {
1083 if (he->body != NULL)