2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2007 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/>.
25 #include <glib/gi18n.h>
36 #include "procheader.h"
39 #include "prefs_common.h"
44 static gchar monthstr[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
46 typedef char *(*getlinefunc) (char *, size_t, void *);
47 typedef int (*peekcharfunc) (void *);
48 typedef int (*getcharfunc) (void *);
49 typedef gint (*get_one_field_func) (gchar *, size_t, void *, HeaderEntry[]);
51 static gint string_get_one_field(gchar *buf, size_t len, char **str,
52 HeaderEntry hentry[]);
54 static char *string_getline(char *buf, size_t len, char **str);
55 static int string_peekchar(char **str);
56 static int file_peekchar(FILE *fp);
57 static gint generic_get_one_field(gchar *buf, size_t len, void *data,
60 peekcharfunc peekchar,
62 static MsgInfo *parse_stream(void *data, gboolean isstring, MsgFlags flags,
63 gboolean full, gboolean decrypted);
66 gint procheader_get_one_field(gchar *buf, size_t len, FILE *fp,
69 return generic_get_one_field(buf, len, fp, hentry,
70 (getlinefunc)fgets_crlf, (peekcharfunc)file_peekchar,
74 static gint string_get_one_field(gchar *buf, size_t len, char **str,
77 return generic_get_one_field(buf, len, str, hentry,
78 (getlinefunc)string_getline,
79 (peekcharfunc)string_peekchar,
83 static char *string_getline(char *buf, size_t len, char **str)
85 gboolean is_cr = FALSE;
86 gboolean last_was_cr = FALSE;
91 for (; **str && len > 1; --len) {
92 is_cr = (**str == '\r');
93 if ((*buf++ = *(*str)++) == '\n') {
109 static int string_peekchar(char **str)
114 static int file_peekchar(FILE *fp)
116 return ungetc(getc(fp), fp);
119 static gint generic_get_one_field(gchar *buf, size_t len, void *data,
121 getlinefunc getline, peekcharfunc peekchar,
126 HeaderEntry *hp = NULL;
128 if (hentry != NULL) {
129 /* skip non-required headers */
132 if (getline(buf, len, data) == NULL)
134 if (buf[0] == '\r' || buf[0] == '\n')
136 } while (buf[0] == ' ' || buf[0] == '\t');
138 for (hp = hentry, hnum = 0; hp->name != NULL;
140 if (!g_ascii_strncasecmp(hp->name, buf,
144 } while (hp->name == NULL);
146 if (getline(buf, len, data) == NULL) return -1;
147 if (buf[0] == '\r' || buf[0] == '\n') return -1;
152 nexthead = peekchar(data);
153 /* ([*WSP CRLF] 1*WSP) */
154 if (nexthead == ' ' || nexthead == '\t') {
156 gboolean skiptab = (nexthead == '\t');
157 /* trim previous trailing \n if requesting one header or
158 * unfolding was requested */
159 if ((!hentry && unfold) || (hp && hp->unfold))
162 buflen = strlen(buf);
164 /* concatenate next line */
165 if ((len - buflen) > 2) {
166 if (getline(buf + buflen, len - buflen, data) == NULL)
168 if (skiptab) { /* replace tab with space */
169 *(buf + buflen) = ' ';
174 /* remove trailing new line */
183 gint procheader_get_one_field_asis(gchar *buf, size_t len, FILE *fp)
185 return generic_get_one_field(buf, len, fp, NULL,
186 (getlinefunc)fgets_crlf,
187 (peekcharfunc)file_peekchar,
191 GPtrArray *procheader_get_header_array_asis(FILE *fp)
197 g_return_val_if_fail(fp != NULL, NULL);
199 headers = g_ptr_array_new();
201 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
202 if ((header = procheader_parse_header(buf)) != NULL)
203 g_ptr_array_add(headers, header);
205 if (*buf == ':') continue;
206 for (p = buf; *p && *p != ' '; p++) {
208 header = g_new(Header, 1);
209 header->name = g_strndup(buf, p - buf);
211 conv_unmime_header(tmp, sizeof(tmp), p, NULL);
212 header->body = g_strdup(tmp);
214 g_ptr_array_add(headers, header);
224 void procheader_header_array_destroy(GPtrArray *harray)
229 for (i = 0; i < harray->len; i++) {
230 header = g_ptr_array_index(harray, i);
231 procheader_header_free(header);
234 g_ptr_array_free(harray, TRUE);
237 void procheader_header_free(Header *header)
241 g_free(header->name);
242 g_free(header->body);
247 tests whether two headers' names are equal
248 remove the trailing ':' or ' ' before comparing
251 gboolean procheader_headername_equal(char * hdr1, char * hdr2)
258 if (hdr1[len1 - 1] == ':')
260 if (hdr2[len2 - 1] == ':')
265 return (g_ascii_strncasecmp(hdr1, hdr2, len1) == 0);
269 parse headers, for example :
270 From: dinh@enseirb.fr becomes :
271 header->name = "From:"
272 header->body = "dinh@enseirb.fr"
275 Header * procheader_parse_header(gchar * buf)
280 if ((*buf == ':') || (*buf == ' '))
283 for (p = buf; *p ; p++) {
284 if ((*p == ':') || (*p == ' ')) {
285 header = g_new(Header, 1);
286 header->name = g_strndup(buf, p - buf + 1);
288 while (*p == ' ' || *p == '\t') p++;
289 header->body = conv_unmime_header(p, NULL);
296 void procheader_get_header_fields(FILE *fp, HeaderEntry hentry[])
303 if (hentry == NULL) return;
305 while ((hnum = procheader_get_one_field(buf, sizeof(buf), fp, hentry))
309 p = buf + strlen(hp->name);
310 while (*p == ' ' || *p == '\t') p++;
312 if (hp->body == NULL)
313 hp->body = g_strdup(p);
314 else if (procheader_headername_equal(hp->name, "To") ||
315 procheader_headername_equal(hp->name, "Cc")) {
316 gchar *tp = hp->body;
317 hp->body = g_strconcat(tp, ", ", p, NULL);
323 MsgInfo *procheader_parse_file(const gchar *file, MsgFlags flags,
324 gboolean full, gboolean decrypted)
330 if (stat(file, &s) < 0) {
331 FILE_OP_ERROR(file, "stat");
334 if (!S_ISREG(s.st_mode))
337 if ((fp = g_fopen(file, "rb")) == NULL) {
338 FILE_OP_ERROR(file, "fopen");
342 msginfo = procheader_parse_stream(fp, flags, full, decrypted);
346 msginfo->size = s.st_size;
347 msginfo->mtime = s.st_mtime;
353 MsgInfo *procheader_parse_str(const gchar *str, MsgFlags flags, gboolean full,
356 return parse_stream(&str, TRUE, flags, full, decrypted);
375 H_SC_PLANNED_DOWNLOAD = 14,
376 H_SC_MESSAGE_SIZE = 15,
379 H_DISPOSITION_NOTIFICATION_TO = 18,
380 H_RETURN_RECEIPT_TO = 19,
381 H_SC_PARTIALLY_RETRIEVED = 20,
382 H_SC_ACCOUNT_SERVER = 21,
383 H_SC_ACCOUNT_LOGIN = 22,
385 H_LIST_SUBSCRIBE = 24,
386 H_LIST_UNSUBSCRIBE = 25,
392 static HeaderEntry hentry_full[] = {{"Date:", NULL, FALSE},
393 {"From:", NULL, TRUE},
396 {"Newsgroups:", NULL, TRUE},
397 {"Subject:", NULL, TRUE},
398 {"Message-ID:", NULL, FALSE},
399 {"References:", NULL, FALSE},
400 {"In-Reply-To:", NULL, FALSE},
401 {"Content-Type:", NULL, FALSE},
402 {"Seen:", NULL, FALSE},
403 {"Status:", NULL, FALSE},
404 {"X-Status:", NULL, FALSE},
405 {"From ", NULL, FALSE},
406 {"SC-Marked-For-Download:", NULL, FALSE},
407 {"SC-Message-Size:", NULL, FALSE},
408 {"Face:", NULL, FALSE},
409 {"X-Face:", NULL, FALSE},
410 {"Disposition-Notification-To:", NULL, FALSE},
411 {"Return-Receipt-To:", NULL, FALSE},
412 {"SC-Partially-Retrieved:", NULL, FALSE},
413 {"SC-Account-Server:", NULL, FALSE},
414 {"SC-Account-Login:",NULL, FALSE},
415 {"List-Post:", NULL, TRUE},
416 {"List-Subscribe:", NULL, TRUE},
417 {"List-Unsubscribe:",NULL, TRUE},
418 {"List-Help:", NULL, TRUE},
419 {"List-Archive:", NULL, TRUE},
420 {"List-Owner:", NULL, TRUE},
421 {NULL, NULL, FALSE}};
423 static HeaderEntry hentry_short[] = {{"Date:", NULL, FALSE},
424 {"From:", NULL, TRUE},
427 {"Newsgroups:", NULL, TRUE},
428 {"Subject:", NULL, TRUE},
429 {"Message-ID:", NULL, FALSE},
430 {"References:", NULL, FALSE},
431 {"In-Reply-To:", NULL, FALSE},
432 {"Content-Type:", NULL, FALSE},
433 {"Seen:", NULL, FALSE},
434 {"Status:", NULL, FALSE},
435 {"X-Status:", NULL, FALSE},
436 {"From ", NULL, FALSE},
437 {"SC-Marked-For-Download:", NULL, FALSE},
438 {"SC-Message-Size:",NULL, FALSE},
439 {NULL, NULL, FALSE}};
441 HeaderEntry* procheader_get_headernames(gboolean full)
443 return full ? hentry_full : hentry_short;
446 MsgInfo *procheader_parse_stream(FILE *fp, MsgFlags flags, gboolean full,
449 return parse_stream(fp, FALSE, flags, full, decrypted);
452 static MsgInfo *parse_stream(void *data, gboolean isstring, MsgFlags flags,
453 gboolean full, gboolean decrypted)
461 void *orig_data = data;
463 get_one_field_func get_one_field =
464 isstring ? (get_one_field_func)string_get_one_field
465 : (get_one_field_func)procheader_get_one_field;
467 hentry = procheader_get_headernames(full);
469 if (MSG_IS_QUEUED(flags) || MSG_IS_DRAFT(flags)) {
470 while (get_one_field(buf, sizeof(buf), data, NULL) != -1) {
471 if ((!strncmp(buf, "X-Claws-End-Special-Headers: 1",
472 strlen("X-Claws-End-Special-Headers:"))) ||
473 (!strncmp(buf, "X-Sylpheed-End-Special-Headers: 1",
474 strlen("X-Sylpheed-End-Special-Headers:"))))
476 /* from other mailers */
477 if (!strncmp(buf, "Date: ", 6)
478 || !strncmp(buf, "To: ", 4)
479 || !strncmp(buf, "From: ", 6)
480 || !strncmp(buf, "Subject: ", 9)) {
484 rewind((FILE *)data);
490 msginfo = procmsg_msginfo_new();
492 if (flags.tmp_flags || flags.perm_flags)
493 msginfo->flags = flags;
495 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_NEW | MSG_UNREAD);
497 msginfo->inreplyto = NULL;
499 while ((hnum = get_one_field(buf, sizeof(buf), data, hentry))
501 hp = buf + strlen(hentry[hnum].name);
502 while (*hp == ' ' || *hp == '\t') hp++;
506 if (msginfo->date) break;
508 procheader_date_parse(NULL, hp, 0);
509 if (g_utf8_validate(hp, -1, NULL)) {
510 msginfo->date = g_strdup(hp);
512 gchar *utf = conv_codeset_strdup(
514 conv_get_locale_charset_str_no_utf8(),
517 !g_utf8_validate(utf, -1, NULL)) {
519 utf = g_malloc(strlen(buf)*2+1);
520 conv_localetodisp(utf,
527 if (msginfo->from) break;
528 msginfo->from = conv_unmime_header(hp, NULL);
529 msginfo->fromname = procheader_get_fromname(msginfo->from);
530 remove_return(msginfo->from);
531 remove_return(msginfo->fromname);
534 tmp = conv_unmime_header(hp, NULL);
539 g_strconcat(p, ", ", tmp, NULL);
542 msginfo->to = g_strdup(tmp);
546 tmp = conv_unmime_header(hp, NULL);
551 g_strconcat(p, ", ", tmp, NULL);
554 msginfo->cc = g_strdup(tmp);
558 if (msginfo->newsgroups) {
559 p = msginfo->newsgroups;
560 msginfo->newsgroups =
561 g_strconcat(p, ",", hp, NULL);
564 msginfo->newsgroups = g_strdup(hp);
567 if (msginfo->subject) break;
568 msginfo->subject = conv_unmime_header(hp, NULL);
569 unfold_line(msginfo->subject);
572 if (msginfo->msgid) break;
574 extract_parenthesis(hp, '<', '>');
576 msginfo->msgid = g_strdup(hp);
579 msginfo->references =
580 references_list_prepend(msginfo->references,
584 if (msginfo->inreplyto) break;
586 eliminate_parenthesis(hp, '(', ')');
587 if ((p = strrchr(hp, '<')) != NULL &&
588 strchr(p + 1, '>') != NULL) {
589 extract_parenthesis(p, '<', '>');
592 msginfo->inreplyto = g_strdup(p);
596 if (!g_ascii_strncasecmp(hp, "multipart/", 10))
597 MSG_SET_TMP_FLAGS(msginfo->flags, MSG_MULTIPART);
599 #ifdef ALLOW_HEADER_HINT
601 /* mnews Seen header */
602 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_NEW|MSG_UNREAD);
606 if (!msginfo->extradata)
607 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
608 if (msginfo->extradata->face) break;
609 msginfo->extradata->face = g_strdup(hp);
612 if (!msginfo->extradata)
613 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
614 if (msginfo->extradata->xface) break;
615 msginfo->extradata->xface = g_strdup(hp);
617 case H_DISPOSITION_NOTIFICATION_TO:
618 if (!msginfo->extradata)
619 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
620 if (msginfo->extradata->dispositionnotificationto) break;
621 msginfo->extradata->dispositionnotificationto = g_strdup(hp);
623 case H_RETURN_RECEIPT_TO:
624 if (!msginfo->extradata)
625 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
626 if (msginfo->extradata->returnreceiptto) break;
627 msginfo->extradata->returnreceiptto = g_strdup(hp);
629 /* partial download infos */
630 case H_SC_PARTIALLY_RETRIEVED:
631 if (!msginfo->extradata)
632 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
633 if (msginfo->extradata->partial_recv) break;
634 msginfo->extradata->partial_recv = g_strdup(hp);
636 case H_SC_ACCOUNT_SERVER:
637 if (!msginfo->extradata)
638 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
639 if (msginfo->extradata->account_server) break;
640 msginfo->extradata->account_server = g_strdup(hp);
642 case H_SC_ACCOUNT_LOGIN:
643 if (!msginfo->extradata)
644 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
645 if (msginfo->extradata->account_login) break;
646 msginfo->extradata->account_login = g_strdup(hp);
648 case H_SC_MESSAGE_SIZE:
649 if (msginfo->total_size) break;
650 msginfo->total_size = atoi(hp);
652 case H_SC_PLANNED_DOWNLOAD:
653 msginfo->planned_download = atoi(hp);
655 /* end partial download infos */
656 #ifdef ALLOW_HEADER_HINT
658 if (strchr(hp, 'R') != NULL)
659 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_UNREAD);
660 if (strchr(hp, 'O') != NULL)
661 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_NEW);
662 if (strchr(hp, 'U') != NULL)
663 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_UNREAD);
666 if (strchr(hp, 'D') != NULL)
667 MSG_SET_PERM_FLAGS(msginfo->flags,
669 if (strchr(hp, 'F') != NULL)
670 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_MARKED);
671 if (strchr(hp, 'd') != NULL)
672 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_DELETED);
673 if (strchr(hp, 'r') != NULL)
674 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
675 if (strchr(hp, 'f') != NULL)
676 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
680 if (msginfo->fromspace) break;
681 msginfo->fromspace = g_strdup(hp);
682 remove_return(msginfo->fromspace);
686 if (!msginfo->extradata)
687 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
688 if (msginfo->extradata->list_post) break;
689 msginfo->extradata->list_post = g_strdup(hp);
691 case H_LIST_SUBSCRIBE:
692 if (!msginfo->extradata)
693 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
694 if (msginfo->extradata->list_subscribe) break;
695 msginfo->extradata->list_subscribe = g_strdup(hp);
697 case H_LIST_UNSUBSCRIBE:
698 if (!msginfo->extradata)
699 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
700 if (msginfo->extradata->list_unsubscribe) break;
701 msginfo->extradata->list_unsubscribe = g_strdup(hp);
704 if (!msginfo->extradata)
705 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
706 if (msginfo->extradata->list_help) break;
707 msginfo->extradata->list_help = g_strdup(hp);
710 if (!msginfo->extradata)
711 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
712 if (msginfo->extradata->list_archive) break;
713 msginfo->extradata->list_archive = g_strdup(hp);
716 if (!msginfo->extradata)
717 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
718 if (msginfo->extradata->list_owner) break;
719 msginfo->extradata->list_owner = g_strdup(hp);
727 if (!msginfo->inreplyto && msginfo->references)
729 g_strdup((gchar *)msginfo->references->data);
734 gchar *procheader_get_fromname(const gchar *str)
738 Xstrdup_a(tmp, str, return NULL);
741 extract_quote(tmp, '\"');
743 } else if (strchr(tmp, '<')) {
744 eliminate_parenthesis(tmp, '<', '>');
748 extract_parenthesis(tmp, '<', '>');
751 } else if (strchr(tmp, '(')) {
752 extract_parenthesis(tmp, '(', ')');
757 name = g_strdup(str);
759 name = g_strdup(tmp);
764 static gint procheader_scan_date_string(const gchar *str,
765 gchar *weekday, gint *day,
766 gchar *month, gint *year,
767 gint *hh, gint *mm, gint *ss,
775 result = sscanf(str, "%10s %d %9s %d %2d:%2d:%2d %5s",
776 weekday, day, month, year, hh, mm, ss, zone);
777 if (result == 8) return 0;
780 result = sscanf(str, "%3s,%d %9s %d %2d:%2d:%2d %5s",
781 weekday, day, month, year, hh, mm, ss, zone);
782 if (result == 8) return 0;
784 result = sscanf(str, "%d %9s %d %2d:%2d:%2d %5s",
785 day, month, year, hh, mm, ss, zone);
786 if (result == 7) return 0;
789 result = sscanf(str, "%10s %d %9s %d %2d:%2d:%2d",
790 weekday, day, month, year, hh, mm, ss);
791 if (result == 7) return 0;
793 result = sscanf(str, "%d %9s %d %2d:%2d:%2d",
794 day, month, year, hh, mm, ss);
795 if (result == 6) return 0;
798 result = sscanf(str, "%10s %d %9s %d %2d:%2d %5s",
799 weekday, day, month, year, hh, mm, zone);
800 if (result == 7) return 0;
802 result = sscanf(str, "%d %9s %d %2d:%2d %5s",
803 day, month, year, hh, mm, zone);
804 if (result == 6) return 0;
807 result = sscanf(str, "%10s %d %9s %d %2d:%2d",
808 weekday, day, month, year, hh, mm);
809 if (result == 6) return 0;
811 result = sscanf(str, "%d %9s %d %2d:%2d",
812 day, month, year, hh, mm);
813 if (result == 5) return 0;
817 result = sscanf(str, "%4d-%2d-%2d %2d:%2d:%2d+%2s:%2s",
818 year, &month_n, day, hh, mm, ss, zone1, zone2);
820 if (1 <= month_n && month_n <= 12) {
821 strncpy2(month, monthstr+((month_n-1)*3), 4);
823 strncpy2(zone+1, zone1, 3);
824 strncpy2(zone+3, zone2, 3);
832 result = sscanf(str, "%4d-%2d-%2d %2d:%2d:%2d",
833 year, &month_n, day, hh, mm, ss);
835 if (1 <= month_n && month_n <= 12) {
836 strncpy2(month, monthstr+((month_n-1)*3), 4);
845 * Hiro, most UNIXen support this function:
846 * http://www.mcsr.olemiss.edu/cgi-bin/man-cgi?getdate
848 gboolean procheader_date_parse_to_tm(const gchar *src, struct tm *t, char *zone)
861 memset(t, 0, sizeof *t);
863 if (procheader_scan_date_string(src, weekday, &day, month, &year,
864 &hh, &mm, &ss, zone) < 0) {
865 g_warning("Invalid date: %s\n", src);
869 /* Y2K compliant :) */
878 if ((p = strstr(monthstr, month)) != NULL)
879 dmonth = (gint)(p - monthstr) / 3 + 1;
881 g_warning("Invalid month: %s\n", month);
882 dmonth = G_DATE_BAD_MONTH;
889 t->tm_mon = dmonth - 1;
890 t->tm_year = year - 1900;
900 time_t procheader_date_parse(gchar *dest, const gchar *src, gint len)
908 GDateMonth dmonth = G_DATE_BAD_MONTH;
914 if (procheader_scan_date_string(src, weekday, &day, month, &year,
915 &hh, &mm, &ss, zone) < 0) {
917 strncpy2(dest, src, len);
921 /* Y2K compliant :) */
930 for (p = monthstr; *p != '\0'; p += 3) {
931 if (!g_ascii_strncasecmp(p, month, 3)) {
932 dmonth = (gint)(p - monthstr) / 3 + 1;
941 t.tm_mon = dmonth - 1;
942 t.tm_year = year - 1900;
948 tz_offset = remote_tzoffset_sec(zone);
950 timer += tzoffset_sec(&timer) - tz_offset;
953 procheader_date_get_localtime(dest, len, timer);
958 void procheader_date_get_localtime(gchar *dest, gint len, const time_t timer)
961 gchar *default_format = "%y/%m/%d(%a) %H:%M";
963 const gchar *src_codeset, *dest_codeset;
966 lt = localtime_r(&timer, &buf);
968 if (prefs_common.date_format)
969 fast_strftime(dest, len, prefs_common.date_format, lt);
971 fast_strftime(dest, len, default_format, lt);
973 if (!g_utf8_validate(dest, -1, NULL)) {
974 src_codeset = conv_get_locale_charset_str_no_utf8();
975 dest_codeset = CS_UTF_8;
976 str = conv_codeset_strdup(dest, src_codeset, dest_codeset);
978 strncpy2(dest, str, len);
984 /* Added by Mel Hadasht on 27 Aug 2001 */
985 /* Get a header from msginfo */
986 gint procheader_get_header_from_msginfo(MsgInfo *msginfo, gchar *buf, gint len, gchar *header)
990 HeaderEntry hentry[]={ { NULL, NULL, TRUE },
991 { NULL, NULL, FALSE } };
994 hentry[0].name = header;
996 g_return_val_if_fail(msginfo != NULL, -1);
997 file = procmsg_get_message_file_path(msginfo);
998 if ((fp = g_fopen(file, "rb")) == NULL) {
999 FILE_OP_ERROR(file, "fopen");
1003 val = procheader_get_one_field(buf,len, fp, hentry);
1004 if (fclose(fp) == EOF) {
1005 FILE_OP_ERROR(file, "fclose");