2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2009 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 cm_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);
209 void procheader_header_array_destroy(GPtrArray *harray)
214 for (i = 0; i < harray->len; i++) {
215 header = g_ptr_array_index(harray, i);
216 procheader_header_free(header);
219 g_ptr_array_free(harray, TRUE);
222 void procheader_header_free(Header *header)
226 g_free(header->name);
227 g_free(header->body);
232 tests whether two headers' names are equal
233 remove the trailing ':' or ' ' before comparing
236 gboolean procheader_headername_equal(char * hdr1, char * hdr2)
243 if (hdr1[len1 - 1] == ':')
245 if (hdr2[len2 - 1] == ':')
250 return (g_ascii_strncasecmp(hdr1, hdr2, len1) == 0);
254 parse headers, for example :
255 From: dinh@enseirb.fr becomes :
256 header->name = "From:"
257 header->body = "dinh@enseirb.fr"
260 Header * procheader_parse_header(gchar * buf)
265 if ((*buf == ':') || (*buf == ' '))
268 for (p = buf; *p ; p++) {
269 if ((*p == ':') || (*p == ' ')) {
270 header = g_new(Header, 1);
271 header->name = g_strndup(buf, p - buf + 1);
273 while (*p == ' ' || *p == '\t') p++;
274 header->body = conv_unmime_header(p, NULL);
281 void procheader_get_header_fields(FILE *fp, HeaderEntry hentry[])
288 if (hentry == NULL) return;
290 while ((hnum = procheader_get_one_field(buf, sizeof(buf), fp, hentry))
294 p = buf + strlen(hp->name);
295 while (*p == ' ' || *p == '\t') p++;
297 if (hp->body == NULL)
298 hp->body = g_strdup(p);
299 else if (procheader_headername_equal(hp->name, "To") ||
300 procheader_headername_equal(hp->name, "Cc")) {
301 gchar *tp = hp->body;
302 hp->body = g_strconcat(tp, ", ", p, NULL);
308 MsgInfo *procheader_parse_file(const gchar *file, MsgFlags flags,
309 gboolean full, gboolean decrypted)
315 if (g_stat(file, &s) < 0) {
316 FILE_OP_ERROR(file, "stat");
319 if (!S_ISREG(s.st_mode))
322 if ((fp = g_fopen(file, "rb")) == NULL) {
323 FILE_OP_ERROR(file, "fopen");
327 msginfo = procheader_parse_stream(fp, flags, full, decrypted);
331 msginfo->size = s.st_size;
332 msginfo->mtime = s.st_mtime;
338 MsgInfo *procheader_parse_str(const gchar *str, MsgFlags flags, gboolean full,
341 return parse_stream(&str, TRUE, flags, full, decrypted);
360 H_SC_PLANNED_DOWNLOAD = 14,
361 H_SC_MESSAGE_SIZE = 15,
364 H_DISPOSITION_NOTIFICATION_TO = 18,
365 H_RETURN_RECEIPT_TO = 19,
366 H_SC_PARTIALLY_RETRIEVED = 20,
367 H_SC_ACCOUNT_SERVER = 21,
368 H_SC_ACCOUNT_LOGIN = 22,
370 H_LIST_SUBSCRIBE = 24,
371 H_LIST_UNSUBSCRIBE = 25,
377 static HeaderEntry hentry_full[] = {{"Date:", NULL, FALSE},
378 {"From:", NULL, TRUE},
381 {"Newsgroups:", NULL, TRUE},
382 {"Subject:", NULL, TRUE},
383 {"Message-ID:", NULL, FALSE},
384 {"References:", NULL, FALSE},
385 {"In-Reply-To:", NULL, FALSE},
386 {"Content-Type:", NULL, FALSE},
387 {"Seen:", NULL, FALSE},
388 {"Status:", NULL, FALSE},
389 {"X-Status:", NULL, FALSE},
390 {"From ", NULL, FALSE},
391 {"SC-Marked-For-Download:", NULL, FALSE},
392 {"SC-Message-Size:", NULL, FALSE},
393 {"Face:", NULL, FALSE},
394 {"X-Face:", NULL, FALSE},
395 {"Disposition-Notification-To:", NULL, FALSE},
396 {"Return-Receipt-To:", NULL, FALSE},
397 {"SC-Partially-Retrieved:", NULL, FALSE},
398 {"SC-Account-Server:", NULL, FALSE},
399 {"SC-Account-Login:",NULL, FALSE},
400 {"List-Post:", NULL, TRUE},
401 {"List-Subscribe:", NULL, TRUE},
402 {"List-Unsubscribe:",NULL, TRUE},
403 {"List-Help:", NULL, TRUE},
404 {"List-Archive:", NULL, TRUE},
405 {"List-Owner:", NULL, TRUE},
406 {NULL, NULL, FALSE}};
408 static HeaderEntry hentry_short[] = {{"Date:", NULL, FALSE},
409 {"From:", NULL, TRUE},
412 {"Newsgroups:", NULL, TRUE},
413 {"Subject:", NULL, TRUE},
414 {"Message-ID:", NULL, FALSE},
415 {"References:", NULL, FALSE},
416 {"In-Reply-To:", NULL, FALSE},
417 {"Content-Type:", NULL, FALSE},
418 {"Seen:", NULL, FALSE},
419 {"Status:", NULL, FALSE},
420 {"X-Status:", NULL, FALSE},
421 {"From ", NULL, FALSE},
422 {"SC-Marked-For-Download:", NULL, FALSE},
423 {"SC-Message-Size:",NULL, FALSE},
424 {NULL, NULL, FALSE}};
426 static HeaderEntry* procheader_get_headernames(gboolean full)
428 return full ? hentry_full : hentry_short;
431 MsgInfo *procheader_parse_stream(FILE *fp, MsgFlags flags, gboolean full,
434 return parse_stream(fp, FALSE, flags, full, decrypted);
437 static MsgInfo *parse_stream(void *data, gboolean isstring, MsgFlags flags,
438 gboolean full, gboolean decrypted)
446 void *orig_data = data;
448 get_one_field_func get_one_field =
449 isstring ? (get_one_field_func)string_get_one_field
450 : (get_one_field_func)procheader_get_one_field;
452 hentry = procheader_get_headernames(full);
454 if (MSG_IS_QUEUED(flags) || MSG_IS_DRAFT(flags)) {
455 while (get_one_field(buf, sizeof(buf), data, NULL) != -1) {
456 if ((!strncmp(buf, "X-Claws-End-Special-Headers: 1",
457 strlen("X-Claws-End-Special-Headers:"))) ||
458 (!strncmp(buf, "X-Sylpheed-End-Special-Headers: 1",
459 strlen("X-Sylpheed-End-Special-Headers:"))))
461 /* from other mailers */
462 if (!strncmp(buf, "Date: ", 6)
463 || !strncmp(buf, "To: ", 4)
464 || !strncmp(buf, "From: ", 6)
465 || !strncmp(buf, "Subject: ", 9)) {
469 rewind((FILE *)data);
475 msginfo = procmsg_msginfo_new();
477 if (flags.tmp_flags || flags.perm_flags)
478 msginfo->flags = flags;
480 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_NEW | MSG_UNREAD);
482 msginfo->inreplyto = NULL;
484 while ((hnum = get_one_field(buf, sizeof(buf), data, hentry))
486 hp = buf + strlen(hentry[hnum].name);
487 while (*hp == ' ' || *hp == '\t') hp++;
491 if (msginfo->date) break;
493 procheader_date_parse(NULL, hp, 0);
494 if (g_utf8_validate(hp, -1, NULL)) {
495 msginfo->date = g_strdup(hp);
497 gchar *utf = conv_codeset_strdup(
499 conv_get_locale_charset_str_no_utf8(),
502 !g_utf8_validate(utf, -1, NULL)) {
504 utf = g_malloc(strlen(buf)*2+1);
505 conv_localetodisp(utf,
512 if (msginfo->from) break;
513 msginfo->from = conv_unmime_header(hp, NULL);
514 msginfo->fromname = procheader_get_fromname(msginfo->from);
515 remove_return(msginfo->from);
516 remove_return(msginfo->fromname);
519 tmp = conv_unmime_header(hp, NULL);
524 g_strconcat(p, ", ", tmp, NULL);
527 msginfo->to = g_strdup(tmp);
531 tmp = conv_unmime_header(hp, NULL);
536 g_strconcat(p, ", ", tmp, NULL);
539 msginfo->cc = g_strdup(tmp);
543 if (msginfo->newsgroups) {
544 p = msginfo->newsgroups;
545 msginfo->newsgroups =
546 g_strconcat(p, ",", hp, NULL);
549 msginfo->newsgroups = g_strdup(hp);
552 if (msginfo->subject) break;
553 msginfo->subject = conv_unmime_header(hp, NULL);
554 unfold_line(msginfo->subject);
557 if (msginfo->msgid) break;
559 extract_parenthesis(hp, '<', '>');
561 msginfo->msgid = g_strdup(hp);
564 msginfo->references =
565 references_list_prepend(msginfo->references,
569 if (msginfo->inreplyto) break;
571 eliminate_parenthesis(hp, '(', ')');
572 if ((p = strrchr(hp, '<')) != NULL &&
573 strchr(p + 1, '>') != NULL) {
574 extract_parenthesis(p, '<', '>');
577 msginfo->inreplyto = g_strdup(p);
581 if (!g_ascii_strncasecmp(hp, "multipart/", 10))
582 MSG_SET_TMP_FLAGS(msginfo->flags, MSG_MULTIPART);
584 #ifdef ALLOW_HEADER_HINT
586 /* mnews Seen header */
587 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_NEW|MSG_UNREAD);
591 if (!msginfo->extradata)
592 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
593 if (msginfo->extradata->face) break;
594 msginfo->extradata->face = g_strdup(hp);
597 if (!msginfo->extradata)
598 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
599 if (msginfo->extradata->xface) break;
600 msginfo->extradata->xface = g_strdup(hp);
602 case H_DISPOSITION_NOTIFICATION_TO:
603 if (!msginfo->extradata)
604 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
605 if (msginfo->extradata->dispositionnotificationto) break;
606 msginfo->extradata->dispositionnotificationto = g_strdup(hp);
608 case H_RETURN_RECEIPT_TO:
609 if (!msginfo->extradata)
610 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
611 if (msginfo->extradata->returnreceiptto) break;
612 msginfo->extradata->returnreceiptto = g_strdup(hp);
614 /* partial download infos */
615 case H_SC_PARTIALLY_RETRIEVED:
616 if (!msginfo->extradata)
617 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
618 if (msginfo->extradata->partial_recv) break;
619 msginfo->extradata->partial_recv = g_strdup(hp);
621 case H_SC_ACCOUNT_SERVER:
622 if (!msginfo->extradata)
623 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
624 if (msginfo->extradata->account_server) break;
625 msginfo->extradata->account_server = g_strdup(hp);
627 case H_SC_ACCOUNT_LOGIN:
628 if (!msginfo->extradata)
629 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
630 if (msginfo->extradata->account_login) break;
631 msginfo->extradata->account_login = g_strdup(hp);
633 case H_SC_MESSAGE_SIZE:
634 if (msginfo->total_size) break;
635 msginfo->total_size = atoi(hp);
637 case H_SC_PLANNED_DOWNLOAD:
638 msginfo->planned_download = atoi(hp);
640 /* end partial download infos */
641 #ifdef ALLOW_HEADER_HINT
643 if (strchr(hp, 'R') != NULL)
644 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_UNREAD);
645 if (strchr(hp, 'O') != NULL)
646 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_NEW);
647 if (strchr(hp, 'U') != NULL)
648 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_UNREAD);
651 if (strchr(hp, 'D') != NULL)
652 MSG_SET_PERM_FLAGS(msginfo->flags,
654 if (strchr(hp, 'F') != NULL)
655 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_MARKED);
656 if (strchr(hp, 'd') != NULL)
657 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_DELETED);
658 if (strchr(hp, 'r') != NULL)
659 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
660 if (strchr(hp, 'f') != NULL)
661 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
665 if (msginfo->fromspace) break;
666 msginfo->fromspace = g_strdup(hp);
667 remove_return(msginfo->fromspace);
671 if (!msginfo->extradata)
672 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
673 if (msginfo->extradata->list_post) break;
674 msginfo->extradata->list_post = g_strdup(hp);
676 case H_LIST_SUBSCRIBE:
677 if (!msginfo->extradata)
678 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
679 if (msginfo->extradata->list_subscribe) break;
680 msginfo->extradata->list_subscribe = g_strdup(hp);
682 case H_LIST_UNSUBSCRIBE:
683 if (!msginfo->extradata)
684 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
685 if (msginfo->extradata->list_unsubscribe) break;
686 msginfo->extradata->list_unsubscribe = g_strdup(hp);
689 if (!msginfo->extradata)
690 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
691 if (msginfo->extradata->list_help) break;
692 msginfo->extradata->list_help = g_strdup(hp);
695 if (!msginfo->extradata)
696 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
697 if (msginfo->extradata->list_archive) break;
698 msginfo->extradata->list_archive = g_strdup(hp);
701 if (!msginfo->extradata)
702 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
703 if (msginfo->extradata->list_owner) break;
704 msginfo->extradata->list_owner = g_strdup(hp);
712 if (!msginfo->inreplyto && msginfo->references)
714 g_strdup((gchar *)msginfo->references->data);
719 gchar *procheader_get_fromname(const gchar *str)
723 Xstrdup_a(tmp, str, return NULL);
726 extract_quote(tmp, '\"');
728 } else if (strchr(tmp, '<')) {
729 eliminate_parenthesis(tmp, '<', '>');
733 extract_parenthesis(tmp, '<', '>');
736 } else if (strchr(tmp, '(')) {
737 extract_parenthesis(tmp, '(', ')');
742 name = g_strdup(str);
744 name = g_strdup(tmp);
749 static gint procheader_scan_date_string(const gchar *str,
750 gchar *weekday, gint *day,
751 gchar *month, gint *year,
752 gint *hh, gint *mm, gint *ss,
763 result = sscanf(str, "%10s %d %9s %d %2d:%2d:%2d %5s",
764 weekday, day, month, year, hh, mm, ss, zone);
765 if (result == 8) return 0;
768 result = sscanf(str, "%3s,%d %9s %d %2d:%2d:%2d %5s",
769 weekday, day, month, year, hh, mm, ss, zone);
770 if (result == 8) return 0;
772 result = sscanf(str, "%d %9s %d %2d:%2d:%2d %5s",
773 day, month, year, hh, mm, ss, zone);
774 if (result == 7) return 0;
777 result = sscanf(str, "%10s %d %9s %d %2d:%2d:%2d",
778 weekday, day, month, year, hh, mm, ss);
779 if (result == 7) return 0;
781 result = sscanf(str, "%d %9s %d %2d:%2d:%2d",
782 day, month, year, hh, mm, ss);
783 if (result == 6) return 0;
786 result = sscanf(str, "%10s %d %9s %d %2d:%2d %5s",
787 weekday, day, month, year, hh, mm, zone);
788 if (result == 7) return 0;
790 result = sscanf(str, "%d %9s %d %2d:%2d %5s",
791 day, month, year, hh, mm, zone);
792 if (result == 6) return 0;
795 result = sscanf(str, "%10s %d %9s %d %2d:%2d",
796 weekday, day, month, year, hh, mm);
797 if (result == 6) return 0;
799 result = sscanf(str, "%d %9s %d %2d:%2d",
800 day, month, year, hh, mm);
801 if (result == 5) return 0;
805 result = sscanf(str, "%4d-%2d-%2d %2d:%2d:%2d+%2s:%2s",
806 year, &month_n, day, hh, mm, ss, zone1, zone2);
808 if (1 <= month_n && month_n <= 12) {
809 strncpy2(month, monthstr+((month_n-1)*3), 4);
811 strncpy2(zone+1, zone1, 3);
812 strncpy2(zone+3, zone2, 3);
820 result = sscanf(str, "%4d-%2d-%2d %2d:%2d:%2d",
821 year, &month_n, day, hh, mm, ss);
823 if (1 <= month_n && month_n <= 12) {
824 strncpy2(month, monthstr+((month_n-1)*3), 4);
833 * Hiro, most UNIXen support this function:
834 * http://www.mcsr.olemiss.edu/cgi-bin/man-cgi?getdate
836 gboolean procheader_date_parse_to_tm(const gchar *src, struct tm *t, char *zone)
849 memset(t, 0, sizeof *t);
851 if (procheader_scan_date_string(src, weekday, &day, month, &year,
852 &hh, &mm, &ss, zone) < 0) {
853 g_warning("Invalid date: %s\n", src);
857 /* Y2K compliant :) */
866 if ((p = strstr(monthstr, month)) != NULL)
867 dmonth = (gint)(p - monthstr) / 3 + 1;
869 g_warning("Invalid month: %s\n", month);
870 dmonth = G_DATE_BAD_MONTH;
877 t->tm_mon = dmonth - 1;
878 t->tm_year = year - 1900;
888 time_t procheader_date_parse(gchar *dest, const gchar *src, gint len)
896 GDateMonth dmonth = G_DATE_BAD_MONTH;
902 if (procheader_scan_date_string(src, weekday, &day, month, &year,
903 &hh, &mm, &ss, zone) < 0) {
905 strncpy2(dest, src, len);
909 /* Y2K compliant :) */
918 for (p = monthstr; *p != '\0'; p += 3) {
919 if (!g_ascii_strncasecmp(p, month, 3)) {
920 dmonth = (gint)(p - monthstr) / 3 + 1;
929 t.tm_mon = dmonth - 1;
930 t.tm_year = year - 1900;
936 tz_offset = remote_tzoffset_sec(zone);
938 timer += tzoffset_sec(&timer) - tz_offset;
941 procheader_date_get_localtime(dest, len, timer);
946 void procheader_date_get_localtime(gchar *dest, gint len, const time_t timer)
949 gchar *default_format = "%y/%m/%d(%a) %H:%M";
951 const gchar *src_codeset, *dest_codeset;
955 lt = localtime_r(&timer, &buf);
958 lt = localtime_r(&dummy, &buf);
961 if (prefs_common.date_format)
962 fast_strftime(dest, len, prefs_common.date_format, lt);
964 fast_strftime(dest, len, default_format, lt);
966 if (!g_utf8_validate(dest, -1, NULL)) {
967 src_codeset = conv_get_locale_charset_str_no_utf8();
968 dest_codeset = CS_UTF_8;
969 str = conv_codeset_strdup(dest, src_codeset, dest_codeset);
971 strncpy2(dest, str, len);
977 /* Added by Mel Hadasht on 27 Aug 2001 */
978 /* Get a header from msginfo */
979 gint procheader_get_header_from_msginfo(MsgInfo *msginfo, gchar *buf, gint len, gchar *header)
983 HeaderEntry hentry[]={ { NULL, NULL, TRUE },
984 { NULL, NULL, FALSE } };
987 hentry[0].name = header;
989 cm_return_val_if_fail(msginfo != NULL, -1);
990 file = procmsg_get_message_file_path(msginfo);
991 if ((fp = g_fopen(file, "rb")) == NULL) {
992 FILE_OP_ERROR(file, "fopen");
996 val = procheader_get_one_field(buf,len, fp, hentry);
997 if (fclose(fp) == EOF) {
998 FILE_OP_ERROR(file, "fclose");