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 2 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, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include <glib/gi18n.h>
32 #include "procheader.h"
35 #include "prefs_common.h"
40 static gchar monthstr[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
42 typedef char *(*getlinefunc) (char *, size_t, void *);
43 typedef int (*peekcharfunc) (void *);
44 typedef int (*getcharfunc) (void *);
45 typedef gint (*get_one_field_func) (gchar *, size_t, void *, HeaderEntry[]);
47 static gint string_get_one_field(gchar *buf, size_t len, char **str,
48 HeaderEntry hentry[]);
50 static char *string_getline(char *buf, size_t len, char **str);
51 static int string_peekchar(char **str);
52 static int file_peekchar(FILE *fp);
53 static gint generic_get_one_field(gchar *buf, size_t len, void *data,
56 peekcharfunc peekchar,
58 static MsgInfo *parse_stream(void *data, gboolean isstring, MsgFlags flags,
59 gboolean full, gboolean decrypted);
62 gint procheader_get_one_field(gchar *buf, size_t len, FILE *fp,
65 return generic_get_one_field(buf, len, fp, hentry,
66 (getlinefunc)fgets_crlf, (peekcharfunc)file_peekchar,
70 static gint string_get_one_field(gchar *buf, size_t len, char **str,
73 return generic_get_one_field(buf, len, str, hentry,
74 (getlinefunc)string_getline,
75 (peekcharfunc)string_peekchar,
79 static char *string_getline(char *buf, size_t len, char **str)
81 gboolean is_cr = FALSE;
82 gboolean last_was_cr = FALSE;
87 for (; **str && len > 1; --len) {
88 is_cr = (**str == '\r');
89 if ((*buf++ = *(*str)++) == '\n') {
105 static int string_peekchar(char **str)
110 static int file_peekchar(FILE *fp)
112 return ungetc(getc(fp), fp);
115 static gint generic_get_one_field(gchar *buf, size_t len, void *data,
117 getlinefunc getline, peekcharfunc peekchar,
122 HeaderEntry *hp = NULL;
124 if (hentry != NULL) {
125 /* skip non-required headers */
128 if (getline(buf, len, data) == NULL)
130 if (buf[0] == '\r' || buf[0] == '\n')
132 } while (buf[0] == ' ' || buf[0] == '\t');
134 for (hp = hentry, hnum = 0; hp->name != NULL;
136 if (!g_ascii_strncasecmp(hp->name, buf,
140 } while (hp->name == NULL);
142 if (getline(buf, len, data) == NULL) return -1;
143 if (buf[0] == '\r' || buf[0] == '\n') return -1;
148 nexthead = peekchar(data);
149 /* ([*WSP CRLF] 1*WSP) */
150 if (nexthead == ' ' || nexthead == '\t') {
152 gboolean skiptab = (nexthead == '\t');
153 /* trim previous trailing \n if requesting one header or
154 * unfolding was requested */
155 if ((!hentry && unfold) || (hp && hp->unfold))
158 buflen = strlen(buf);
160 /* concatenate next line */
161 if ((len - buflen) > 2) {
162 if (getline(buf + buflen, len - buflen, data) == NULL)
164 if (skiptab) { /* replace tab with space */
165 *(buf + buflen) = ' ';
170 /* remove trailing new line */
179 gint procheader_get_one_field_asis(gchar *buf, size_t len, FILE *fp)
181 return generic_get_one_field(buf, len, fp, NULL,
182 (getlinefunc)fgets_crlf,
183 (peekcharfunc)file_peekchar,
187 GPtrArray *procheader_get_header_array_asis(FILE *fp)
193 g_return_val_if_fail(fp != NULL, NULL);
195 headers = g_ptr_array_new();
197 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
198 if ((header = procheader_parse_header(buf)) != NULL)
199 g_ptr_array_add(headers, header);
201 if (*buf == ':') continue;
202 for (p = buf; *p && *p != ' '; p++) {
204 header = g_new(Header, 1);
205 header->name = g_strndup(buf, p - buf);
207 conv_unmime_header(tmp, sizeof(tmp), p, NULL);
208 header->body = g_strdup(tmp);
210 g_ptr_array_add(headers, header);
220 void procheader_header_array_destroy(GPtrArray *harray)
225 for (i = 0; i < harray->len; i++) {
226 header = g_ptr_array_index(harray, i);
227 procheader_header_free(header);
230 g_ptr_array_free(harray, TRUE);
233 void procheader_header_free(Header *header)
237 g_free(header->name);
238 g_free(header->body);
243 tests whether two headers' names are equal
244 remove the trailing ':' or ' ' before comparing
247 gboolean procheader_headername_equal(char * hdr1, char * hdr2)
254 if (hdr1[len1 - 1] == ':')
256 if (hdr2[len2 - 1] == ':')
261 return (g_ascii_strncasecmp(hdr1, hdr2, len1) == 0);
265 parse headers, for example :
266 From: dinh@enseirb.fr becomes :
267 header->name = "From:"
268 header->body = "dinh@enseirb.fr"
271 Header * procheader_parse_header(gchar * buf)
276 if ((*buf == ':') || (*buf == ' '))
279 for (p = buf; *p ; p++) {
280 if ((*p == ':') || (*p == ' ')) {
281 header = g_new(Header, 1);
282 header->name = g_strndup(buf, p - buf + 1);
284 while (*p == ' ' || *p == '\t') p++;
285 header->body = conv_unmime_header(p, NULL);
292 void procheader_get_header_fields(FILE *fp, HeaderEntry hentry[])
299 if (hentry == NULL) return;
301 while ((hnum = procheader_get_one_field(buf, sizeof(buf), fp, hentry))
305 p = buf + strlen(hp->name);
306 while (*p == ' ' || *p == '\t') p++;
308 if (hp->body == NULL)
309 hp->body = g_strdup(p);
310 else if (procheader_headername_equal(hp->name, "To") ||
311 procheader_headername_equal(hp->name, "Cc")) {
312 gchar *tp = hp->body;
313 hp->body = g_strconcat(tp, ", ", p, NULL);
319 MsgInfo *procheader_parse_file(const gchar *file, MsgFlags flags,
320 gboolean full, gboolean decrypted)
326 if (stat(file, &s) < 0) {
327 FILE_OP_ERROR(file, "stat");
330 if (!S_ISREG(s.st_mode))
333 if ((fp = g_fopen(file, "rb")) == NULL) {
334 FILE_OP_ERROR(file, "fopen");
338 msginfo = procheader_parse_stream(fp, flags, full, decrypted);
342 msginfo->size = s.st_size;
343 msginfo->mtime = s.st_mtime;
349 MsgInfo *procheader_parse_str(const gchar *str, MsgFlags flags, gboolean full,
352 return parse_stream(&str, TRUE, flags, full, decrypted);
371 H_SC_PLANNED_DOWNLOAD = 14,
372 H_SC_MESSAGE_SIZE = 15,
375 H_DISPOSITION_NOTIFICATION_TO = 18,
376 H_RETURN_RECEIPT_TO = 19,
377 H_SC_PARTIALLY_RETRIEVED = 20,
378 H_SC_ACCOUNT_SERVER = 21,
379 H_SC_ACCOUNT_LOGIN = 22,
381 H_LIST_SUBSCRIBE = 24,
382 H_LIST_UNSUBSCRIBE = 25,
388 static HeaderEntry hentry_full[] = {{"Date:", NULL, FALSE},
389 {"From:", NULL, TRUE},
392 {"Newsgroups:", NULL, TRUE},
393 {"Subject:", NULL, TRUE},
394 {"Message-ID:", NULL, FALSE},
395 {"References:", NULL, FALSE},
396 {"In-Reply-To:", NULL, FALSE},
397 {"Content-Type:", NULL, FALSE},
398 {"Seen:", NULL, FALSE},
399 {"Status:", NULL, FALSE},
400 {"X-Status:", NULL, FALSE},
401 {"From ", NULL, FALSE},
402 {"SC-Marked-For-Download:", NULL, FALSE},
403 {"SC-Message-Size:", NULL, FALSE},
404 {"Face:", NULL, FALSE},
405 {"X-Face:", NULL, FALSE},
406 {"Disposition-Notification-To:", NULL, FALSE},
407 {"Return-Receipt-To:", NULL, FALSE},
408 {"SC-Partially-Retrieved:", NULL, FALSE},
409 {"SC-Account-Server:", NULL, FALSE},
410 {"SC-Account-Login:",NULL, FALSE},
411 {"List-Post:", NULL, TRUE},
412 {"List-Subscribe:", NULL, TRUE},
413 {"List-Unsubscribe:",NULL, TRUE},
414 {"List-Help:", NULL, TRUE},
415 {"List-Archive:", NULL, TRUE},
416 {"List-Owner:", NULL, TRUE},
417 {NULL, NULL, FALSE}};
419 static HeaderEntry hentry_short[] = {{"Date:", NULL, FALSE},
420 {"From:", NULL, TRUE},
423 {"Newsgroups:", NULL, TRUE},
424 {"Subject:", NULL, TRUE},
425 {"Message-ID:", NULL, FALSE},
426 {"References:", NULL, FALSE},
427 {"In-Reply-To:", NULL, FALSE},
428 {"Content-Type:", NULL, FALSE},
429 {"Seen:", NULL, FALSE},
430 {"Status:", NULL, FALSE},
431 {"X-Status:", NULL, FALSE},
432 {"From ", NULL, FALSE},
433 {"SC-Marked-For-Download:", NULL, FALSE},
434 {"SC-Message-Size:",NULL, FALSE},
435 {NULL, NULL, FALSE}};
437 HeaderEntry* procheader_get_headernames(gboolean full)
439 return full ? hentry_full : hentry_short;
442 MsgInfo *procheader_parse_stream(FILE *fp, MsgFlags flags, gboolean full,
445 return parse_stream(fp, FALSE, flags, full, decrypted);
448 static MsgInfo *parse_stream(void *data, gboolean isstring, MsgFlags flags,
449 gboolean full, gboolean decrypted)
457 void *orig_data = data;
459 get_one_field_func get_one_field =
460 isstring ? (get_one_field_func)string_get_one_field
461 : (get_one_field_func)procheader_get_one_field;
463 hentry = procheader_get_headernames(full);
465 if (MSG_IS_QUEUED(flags) || MSG_IS_DRAFT(flags)) {
466 while (get_one_field(buf, sizeof(buf), data, NULL) != -1) {
467 if ((!strncmp(buf, "X-Claws-End-Special-Headers: 1",
468 strlen("X-Claws-End-Special-Headers:"))) ||
469 (!strncmp(buf, "X-Sylpheed-End-Special-Headers: 1",
470 strlen("X-Sylpheed-End-Special-Headers:"))))
472 /* from other mailers */
473 if (!strncmp(buf, "Date: ", 6)
474 || !strncmp(buf, "To: ", 4)
475 || !strncmp(buf, "From: ", 6)
476 || !strncmp(buf, "Subject: ", 9)) {
480 rewind((FILE *)data);
486 msginfo = procmsg_msginfo_new();
488 if (flags.tmp_flags || flags.perm_flags)
489 msginfo->flags = flags;
491 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_NEW | MSG_UNREAD);
493 msginfo->inreplyto = NULL;
495 while ((hnum = get_one_field(buf, sizeof(buf), data, hentry))
497 hp = buf + strlen(hentry[hnum].name);
498 while (*hp == ' ' || *hp == '\t') hp++;
502 if (msginfo->date) break;
504 procheader_date_parse(NULL, hp, 0);
505 if (g_utf8_validate(hp, -1, NULL)) {
506 msginfo->date = g_strdup(hp);
508 gchar *utf = conv_codeset_strdup(
510 conv_get_locale_charset_str_no_utf8(),
513 !g_utf8_validate(utf, -1, NULL)) {
515 utf = g_malloc(strlen(buf)*2+1);
516 conv_localetodisp(utf,
523 if (msginfo->from) break;
524 msginfo->from = conv_unmime_header(hp, NULL);
525 msginfo->fromname = procheader_get_fromname(msginfo->from);
526 remove_return(msginfo->from);
527 remove_return(msginfo->fromname);
530 tmp = conv_unmime_header(hp, NULL);
535 g_strconcat(p, ", ", tmp, NULL);
538 msginfo->to = g_strdup(tmp);
542 tmp = conv_unmime_header(hp, NULL);
547 g_strconcat(p, ", ", tmp, NULL);
550 msginfo->cc = g_strdup(tmp);
554 if (msginfo->newsgroups) {
555 p = msginfo->newsgroups;
556 msginfo->newsgroups =
557 g_strconcat(p, ",", hp, NULL);
560 msginfo->newsgroups = g_strdup(hp);
563 if (msginfo->subject) break;
564 msginfo->subject = conv_unmime_header(hp, NULL);
565 unfold_line(msginfo->subject);
568 if (msginfo->msgid) break;
570 extract_parenthesis(hp, '<', '>');
572 msginfo->msgid = g_strdup(hp);
575 msginfo->references =
576 references_list_prepend(msginfo->references,
580 if (msginfo->inreplyto) break;
582 eliminate_parenthesis(hp, '(', ')');
583 if ((p = strrchr(hp, '<')) != NULL &&
584 strchr(p + 1, '>') != NULL) {
585 extract_parenthesis(p, '<', '>');
588 msginfo->inreplyto = g_strdup(p);
592 if (!g_ascii_strncasecmp(hp, "multipart/", 10))
593 MSG_SET_TMP_FLAGS(msginfo->flags, MSG_MULTIPART);
595 #ifdef ALLOW_HEADER_HINT
597 /* mnews Seen header */
598 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_NEW|MSG_UNREAD);
602 if (!msginfo->extradata)
603 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
604 if (msginfo->extradata->face) break;
605 msginfo->extradata->face = g_strdup(hp);
608 if (!msginfo->extradata)
609 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
610 if (msginfo->extradata->xface) break;
611 msginfo->extradata->xface = g_strdup(hp);
613 case H_DISPOSITION_NOTIFICATION_TO:
614 if (!msginfo->extradata)
615 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
616 if (msginfo->extradata->dispositionnotificationto) break;
617 msginfo->extradata->dispositionnotificationto = g_strdup(hp);
619 case H_RETURN_RECEIPT_TO:
620 if (!msginfo->extradata)
621 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
622 if (msginfo->extradata->returnreceiptto) break;
623 msginfo->extradata->returnreceiptto = g_strdup(hp);
625 /* partial download infos */
626 case H_SC_PARTIALLY_RETRIEVED:
627 if (!msginfo->extradata)
628 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
629 if (msginfo->extradata->partial_recv) break;
630 msginfo->extradata->partial_recv = g_strdup(hp);
632 case H_SC_ACCOUNT_SERVER:
633 if (!msginfo->extradata)
634 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
635 if (msginfo->extradata->account_server) break;
636 msginfo->extradata->account_server = g_strdup(hp);
638 case H_SC_ACCOUNT_LOGIN:
639 if (!msginfo->extradata)
640 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
641 if (msginfo->extradata->account_login) break;
642 msginfo->extradata->account_login = g_strdup(hp);
644 case H_SC_MESSAGE_SIZE:
645 if (msginfo->total_size) break;
646 msginfo->total_size = atoi(hp);
648 case H_SC_PLANNED_DOWNLOAD:
649 msginfo->planned_download = atoi(hp);
651 /* end partial download infos */
652 #ifdef ALLOW_HEADER_HINT
654 if (strchr(hp, 'R') != NULL)
655 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_UNREAD);
656 if (strchr(hp, 'O') != NULL)
657 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_NEW);
658 if (strchr(hp, 'U') != NULL)
659 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_UNREAD);
662 if (strchr(hp, 'D') != NULL)
663 MSG_SET_PERM_FLAGS(msginfo->flags,
665 if (strchr(hp, 'F') != NULL)
666 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_MARKED);
667 if (strchr(hp, 'd') != NULL)
668 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_DELETED);
669 if (strchr(hp, 'r') != NULL)
670 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
671 if (strchr(hp, 'f') != NULL)
672 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
676 if (msginfo->fromspace) break;
677 msginfo->fromspace = g_strdup(hp);
678 remove_return(msginfo->fromspace);
682 if (!msginfo->extradata)
683 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
684 if (msginfo->extradata->list_post) break;
685 msginfo->extradata->list_post = g_strdup(hp);
687 case H_LIST_SUBSCRIBE:
688 if (!msginfo->extradata)
689 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
690 if (msginfo->extradata->list_subscribe) break;
691 msginfo->extradata->list_subscribe = g_strdup(hp);
693 case H_LIST_UNSUBSCRIBE:
694 if (!msginfo->extradata)
695 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
696 if (msginfo->extradata->list_unsubscribe) break;
697 msginfo->extradata->list_unsubscribe = g_strdup(hp);
700 if (!msginfo->extradata)
701 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
702 if (msginfo->extradata->list_help) break;
703 msginfo->extradata->list_help = g_strdup(hp);
706 if (!msginfo->extradata)
707 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
708 if (msginfo->extradata->list_archive) break;
709 msginfo->extradata->list_archive = g_strdup(hp);
712 if (!msginfo->extradata)
713 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
714 if (msginfo->extradata->list_owner) break;
715 msginfo->extradata->list_owner = g_strdup(hp);
723 if (!msginfo->inreplyto && msginfo->references)
725 g_strdup((gchar *)msginfo->references->data);
730 gchar *procheader_get_fromname(const gchar *str)
734 Xstrdup_a(tmp, str, return NULL);
737 extract_quote(tmp, '\"');
739 } else if (strchr(tmp, '<')) {
740 eliminate_parenthesis(tmp, '<', '>');
744 extract_parenthesis(tmp, '<', '>');
747 } else if (strchr(tmp, '(')) {
748 extract_parenthesis(tmp, '(', ')');
753 name = g_strdup(str);
755 name = g_strdup(tmp);
760 static gint procheader_scan_date_string(const gchar *str,
761 gchar *weekday, gint *day,
762 gchar *month, gint *year,
763 gint *hh, gint *mm, gint *ss,
771 result = sscanf(str, "%10s %d %9s %d %2d:%2d:%2d %5s",
772 weekday, day, month, year, hh, mm, ss, zone);
773 if (result == 8) return 0;
776 result = sscanf(str, "%3s,%d %9s %d %2d:%2d:%2d %5s",
777 weekday, day, month, year, hh, mm, ss, zone);
778 if (result == 8) return 0;
780 result = sscanf(str, "%d %9s %d %2d:%2d:%2d %5s",
781 day, month, year, hh, mm, ss, zone);
782 if (result == 7) return 0;
785 result = sscanf(str, "%10s %d %9s %d %2d:%2d:%2d",
786 weekday, day, month, year, hh, mm, ss);
787 if (result == 7) return 0;
789 result = sscanf(str, "%d %9s %d %2d:%2d:%2d",
790 day, month, year, hh, mm, ss);
791 if (result == 6) return 0;
794 result = sscanf(str, "%10s %d %9s %d %2d:%2d %5s",
795 weekday, day, month, year, hh, mm, zone);
796 if (result == 7) return 0;
798 result = sscanf(str, "%d %9s %d %2d:%2d %5s",
799 day, month, year, hh, mm, zone);
800 if (result == 6) return 0;
803 result = sscanf(str, "%10s %d %9s %d %2d:%2d",
804 weekday, day, month, year, hh, mm);
805 if (result == 6) return 0;
807 result = sscanf(str, "%d %9s %d %2d:%2d",
808 day, month, year, hh, mm);
809 if (result == 5) return 0;
813 result = sscanf(str, "%4d-%2d-%2d %2d:%2d:%2d+%2s:%2s",
814 year, &month_n, day, hh, mm, ss, zone1, zone2);
816 if (1 <= month_n && month_n <= 12) {
817 strncpy2(month, monthstr+((month_n-1)*3), 4);
819 strncpy2(zone+1, zone1, 3);
820 strncpy2(zone+3, zone2, 3);
828 result = sscanf(str, "%4d-%2d-%2d %2d:%2d:%2d",
829 year, &month_n, day, hh, mm, ss);
831 if (1 <= month_n && month_n <= 12) {
832 strncpy2(month, monthstr+((month_n-1)*3), 4);
841 * Hiro, most UNIXen support this function:
842 * http://www.mcsr.olemiss.edu/cgi-bin/man-cgi?getdate
844 gboolean procheader_date_parse_to_tm(const gchar *src, struct tm *t, char *zone)
857 memset(t, 0, sizeof *t);
859 if (procheader_scan_date_string(src, weekday, &day, month, &year,
860 &hh, &mm, &ss, zone) < 0) {
861 g_warning("Invalid date: %s\n", src);
865 /* Y2K compliant :) */
874 if ((p = strstr(monthstr, month)) != NULL)
875 dmonth = (gint)(p - monthstr) / 3 + 1;
877 g_warning("Invalid month: %s\n", month);
878 dmonth = G_DATE_BAD_MONTH;
885 t->tm_mon = dmonth - 1;
886 t->tm_year = year - 1900;
896 time_t procheader_date_parse(gchar *dest, const gchar *src, gint len)
904 GDateMonth dmonth = G_DATE_BAD_MONTH;
910 if (procheader_scan_date_string(src, weekday, &day, month, &year,
911 &hh, &mm, &ss, zone) < 0) {
913 strncpy2(dest, src, len);
917 /* Y2K compliant :) */
926 for (p = monthstr; *p != '\0'; p += 3) {
927 if (!g_ascii_strncasecmp(p, month, 3)) {
928 dmonth = (gint)(p - monthstr) / 3 + 1;
937 t.tm_mon = dmonth - 1;
938 t.tm_year = year - 1900;
944 tz_offset = remote_tzoffset_sec(zone);
946 timer += tzoffset_sec(&timer) - tz_offset;
949 procheader_date_get_localtime(dest, len, timer);
954 void procheader_date_get_localtime(gchar *dest, gint len, const time_t timer)
957 gchar *default_format = "%y/%m/%d(%a) %H:%M";
959 const gchar *src_codeset, *dest_codeset;
962 lt = localtime_r(&timer, &buf);
964 if (prefs_common.date_format)
965 fast_strftime(dest, len, prefs_common.date_format, lt);
967 fast_strftime(dest, len, default_format, lt);
969 if (!g_utf8_validate(dest, -1, NULL)) {
970 src_codeset = conv_get_locale_charset_str_no_utf8();
971 dest_codeset = CS_UTF_8;
972 str = conv_codeset_strdup(dest, src_codeset, dest_codeset);
974 strncpy2(dest, str, len);
980 /* Added by Mel Hadasht on 27 Aug 2001 */
981 /* Get a header from msginfo */
982 gint procheader_get_header_from_msginfo(MsgInfo *msginfo, gchar *buf, gint len, gchar *header)
986 HeaderEntry hentry[]={ { NULL, NULL, TRUE },
987 { NULL, NULL, FALSE } };
990 hentry[0].name = header;
992 g_return_val_if_fail(msginfo != NULL, -1);
993 file = procmsg_get_message_file_path(msginfo);
994 if ((fp = g_fopen(file, "rb")) == NULL) {
995 FILE_OP_ERROR(file, "fopen");
999 val = procheader_get_one_field(buf,len, fp, hentry);
1000 if (fclose(fp) == EOF) {
1001 FILE_OP_ERROR(file, "fclose");