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"
47 static gchar monthstr[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
49 typedef char *(*getlinefunc) (char *, size_t, void *);
50 typedef int (*peekcharfunc) (void *);
51 typedef int (*getcharfunc) (void *);
52 typedef gint (*get_one_field_func) (gchar *, size_t, void *, HeaderEntry[]);
54 static gint string_get_one_field(gchar *buf, size_t len, char **str,
55 HeaderEntry hentry[]);
57 static char *string_getline(char *buf, size_t len, char **str);
58 static int string_peekchar(char **str);
59 static int file_peekchar(FILE *fp);
60 static gint generic_get_one_field(gchar *buf, size_t len, void *data,
63 peekcharfunc peekchar,
65 static MsgInfo *parse_stream(void *data, gboolean isstring, MsgFlags flags,
66 gboolean full, gboolean decrypted);
69 gint procheader_get_one_field(gchar *buf, size_t len, FILE *fp,
72 return generic_get_one_field(buf, len, fp, hentry,
73 (getlinefunc)fgets_crlf, (peekcharfunc)file_peekchar,
77 static gint string_get_one_field(gchar *buf, size_t len, char **str,
80 return generic_get_one_field(buf, len, str, hentry,
81 (getlinefunc)string_getline,
82 (peekcharfunc)string_peekchar,
86 static char *string_getline(char *buf, size_t len, char **str)
88 gboolean is_cr = FALSE;
89 gboolean last_was_cr = FALSE;
94 for (; **str && len > 1; --len) {
95 is_cr = (**str == '\r');
96 if ((*buf++ = *(*str)++) == '\n') {
112 static int string_peekchar(char **str)
117 static int file_peekchar(FILE *fp)
119 return ungetc(getc(fp), fp);
122 static gint generic_get_one_field(gchar *buf, size_t len, void *data,
124 getlinefunc getline, peekcharfunc peekchar,
129 HeaderEntry *hp = NULL;
131 if (hentry != NULL) {
132 /* skip non-required headers */
135 if (getline(buf, len, data) == NULL)
137 if (buf[0] == '\r' || buf[0] == '\n')
139 } while (buf[0] == ' ' || buf[0] == '\t');
141 for (hp = hentry, hnum = 0; hp->name != NULL;
143 if (!g_ascii_strncasecmp(hp->name, buf,
147 } while (hp->name == NULL);
149 if (getline(buf, len, data) == NULL) return -1;
150 if (buf[0] == '\r' || buf[0] == '\n') return -1;
155 nexthead = peekchar(data);
156 /* ([*WSP CRLF] 1*WSP) */
157 if (nexthead == ' ' || nexthead == '\t') {
159 gboolean skiptab = (nexthead == '\t');
160 /* trim previous trailing \n if requesting one header or
161 * unfolding was requested */
162 if ((!hentry && unfold) || (hp && hp->unfold))
165 buflen = strlen(buf);
167 /* concatenate next line */
168 if ((len - buflen) > 2) {
169 if (getline(buf + buflen, len - buflen, data) == NULL)
171 if (skiptab) { /* replace tab with space */
172 *(buf + buflen) = ' ';
177 /* remove trailing new line */
186 gint procheader_get_one_field_asis(gchar *buf, size_t len, FILE *fp)
188 return generic_get_one_field(buf, len, fp, NULL,
189 (getlinefunc)fgets_crlf,
190 (peekcharfunc)file_peekchar,
194 GPtrArray *procheader_get_header_array_asis(FILE *fp)
200 cm_return_val_if_fail(fp != NULL, NULL);
202 headers = g_ptr_array_new();
204 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
205 if ((header = procheader_parse_header(buf)) != NULL)
206 g_ptr_array_add(headers, header);
212 void procheader_header_array_destroy(GPtrArray *harray)
217 for (i = 0; i < harray->len; i++) {
218 header = g_ptr_array_index(harray, i);
219 procheader_header_free(header);
222 g_ptr_array_free(harray, TRUE);
225 void procheader_header_free(Header *header)
229 g_free(header->name);
230 g_free(header->body);
235 tests whether two headers' names are equal
236 remove the trailing ':' or ' ' before comparing
239 gboolean procheader_headername_equal(char * hdr1, char * hdr2)
246 if (hdr1[len1 - 1] == ':')
248 if (hdr2[len2 - 1] == ':')
253 return (g_ascii_strncasecmp(hdr1, hdr2, len1) == 0);
257 parse headers, for example :
258 From: dinh@enseirb.fr becomes :
259 header->name = "From:"
260 header->body = "dinh@enseirb.fr"
262 static gboolean header_is_addr_field(const gchar *hdr)
264 static char *addr_headers[] = {
271 "Followup-and-Reply-To:",
272 "Disposition-Notification-To:",
273 "Return-Receipt-To:",
280 for (i = 0; addr_headers[i] != NULL; i++)
281 if (!strcasecmp(hdr, addr_headers[i]))
287 Header * procheader_parse_header(gchar * buf)
291 gboolean addr_field = FALSE;
293 if ((*buf == ':') || (*buf == ' '))
296 for (p = buf; *p ; p++) {
297 if ((*p == ':') || (*p == ' ')) {
298 header = g_new(Header, 1);
299 header->name = g_strndup(buf, p - buf + 1);
300 addr_field = header_is_addr_field(header->name);
302 while (*p == ' ' || *p == '\t') p++;
303 header->body = conv_unmime_header(p, NULL, addr_field);
310 void procheader_get_header_fields(FILE *fp, HeaderEntry hentry[])
317 if (hentry == NULL) return;
319 while ((hnum = procheader_get_one_field(buf, sizeof(buf), fp, hentry))
323 p = buf + strlen(hp->name);
324 while (*p == ' ' || *p == '\t') p++;
326 if (hp->body == NULL)
327 hp->body = g_strdup(p);
328 else if (procheader_headername_equal(hp->name, "To") ||
329 procheader_headername_equal(hp->name, "Cc")) {
330 gchar *tp = hp->body;
331 hp->body = g_strconcat(tp, ", ", p, NULL);
337 MsgInfo *procheader_parse_file(const gchar *file, MsgFlags flags,
338 gboolean full, gboolean decrypted)
344 if (g_stat(file, &s) < 0) {
345 FILE_OP_ERROR(file, "stat");
348 if (!S_ISREG(s.st_mode))
351 if ((fp = g_fopen(file, "rb")) == NULL) {
352 FILE_OP_ERROR(file, "fopen");
356 msginfo = procheader_parse_stream(fp, flags, full, decrypted);
360 msginfo->size = s.st_size;
361 msginfo->mtime = s.st_mtime;
367 MsgInfo *procheader_parse_str(const gchar *str, MsgFlags flags, gboolean full,
370 return parse_stream(&str, TRUE, flags, full, decrypted);
388 H_SC_PLANNED_DOWNLOAD,
392 H_DISPOSITION_NOTIFICATION_TO,
394 H_SC_PARTIALLY_RETRIEVED,
406 static HeaderEntry hentry_full[] = {
407 {"Date:", NULL, FALSE},
408 {"From:", NULL, TRUE},
411 {"Newsgroups:", NULL, TRUE},
412 {"Subject:", NULL, TRUE},
413 {"Message-ID:", NULL, FALSE},
414 {"References:", NULL, FALSE},
415 {"In-Reply-To:", NULL, FALSE},
416 {"Content-Type:", NULL, FALSE},
417 {"Seen:", NULL, FALSE},
418 {"Status:", NULL, FALSE},
419 {"From ", NULL, FALSE},
420 {"SC-Marked-For-Download:", NULL, FALSE},
421 {"SC-Message-Size:", NULL, FALSE},
422 {"Face:", NULL, FALSE},
423 {"X-Face:", NULL, FALSE},
424 {"Disposition-Notification-To:", NULL, FALSE},
425 {"Return-Receipt-To:", NULL, FALSE},
426 {"SC-Partially-Retrieved:", NULL, FALSE},
427 {"SC-Account-Server:", NULL, FALSE},
428 {"SC-Account-Login:",NULL, FALSE},
429 {"List-Post:", NULL, TRUE},
430 {"List-Subscribe:", NULL, TRUE},
431 {"List-Unsubscribe:",NULL, TRUE},
432 {"List-Help:", NULL, TRUE},
433 {"List-Archive:", NULL, TRUE},
434 {"List-Owner:", NULL, TRUE},
435 {"Resent-From:", NULL, TRUE},
436 {NULL, NULL, FALSE}};
438 static HeaderEntry hentry_short[] = {
439 {"Date:", NULL, FALSE},
440 {"From:", NULL, TRUE},
443 {"Newsgroups:", NULL, TRUE},
444 {"Subject:", NULL, TRUE},
445 {"Message-ID:", NULL, FALSE},
446 {"References:", NULL, FALSE},
447 {"In-Reply-To:", NULL, FALSE},
448 {"Content-Type:", NULL, FALSE},
449 {"Seen:", NULL, FALSE},
450 {"Status:", NULL, FALSE},
451 {"From ", NULL, FALSE},
452 {"SC-Marked-For-Download:", NULL, FALSE},
453 {"SC-Message-Size:",NULL, FALSE},
454 {NULL, NULL, FALSE}};
456 static HeaderEntry* procheader_get_headernames(gboolean full)
458 return full ? hentry_full : hentry_short;
461 MsgInfo *procheader_parse_stream(FILE *fp, MsgFlags flags, gboolean full,
464 return parse_stream(fp, FALSE, flags, full, decrypted);
467 static gboolean avatar_from_some_face(gpointer source, gpointer userdata)
469 AvatarCaptureData *acd = (AvatarCaptureData *)source;
471 if (*(acd->content) == '\0') /* won't be null, but may be empty */
474 if (!strcmp(acd->header, hentry_full[H_FACE].name)) {
475 debug_print("avatar_from_some_face: found 'Face' header\n");
476 procmsg_msginfo_add_avatar(acd->msginfo, AVATAR_FACE, acd->content);
479 else if (!strcmp(acd->header, hentry_full[H_X_FACE].name)) {
480 debug_print("avatar_from_some_face: found 'X-Face' header\n");
481 procmsg_msginfo_add_avatar(acd->msginfo, AVATAR_XFACE, acd->content);
487 static guint avatar_hook_id = 0;
489 static MsgInfo *parse_stream(void *data, gboolean isstring, MsgFlags flags,
490 gboolean full, gboolean decrypted)
498 void *orig_data = data;
500 get_one_field_func get_one_field =
501 isstring ? (get_one_field_func)string_get_one_field
502 : (get_one_field_func)procheader_get_one_field;
504 hentry = procheader_get_headernames(full);
506 if (MSG_IS_QUEUED(flags) || MSG_IS_DRAFT(flags)) {
507 while (get_one_field(buf, sizeof(buf), data, NULL) != -1) {
508 if ((!strncmp(buf, "X-Claws-End-Special-Headers: 1",
509 strlen("X-Claws-End-Special-Headers:"))) ||
510 (!strncmp(buf, "X-Sylpheed-End-Special-Headers: 1",
511 strlen("X-Sylpheed-End-Special-Headers:"))))
513 /* from other mailers */
514 if (!strncmp(buf, "Date: ", 6)
515 || !strncmp(buf, "To: ", 4)
516 || !strncmp(buf, "From: ", 6)
517 || !strncmp(buf, "Subject: ", 9)) {
521 rewind((FILE *)data);
527 msginfo = procmsg_msginfo_new();
529 if (flags.tmp_flags || flags.perm_flags)
530 msginfo->flags = flags;
532 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_NEW | MSG_UNREAD);
534 msginfo->inreplyto = NULL;
536 if (avatar_hook_id == 0 && (prefs_common.enable_avatars & AVATARS_ENABLE_CAPTURE)) {
537 avatar_hook_id = hooks_register_hook(AVATAR_HEADER_UPDATE_HOOKLIST, avatar_from_some_face, NULL);
538 } else if (avatar_hook_id != 0 && !(prefs_common.enable_avatars & AVATARS_ENABLE_CAPTURE)) {
539 hooks_unregister_hook(AVATAR_HEADER_UPDATE_HOOKLIST, avatar_hook_id);
543 while ((hnum = get_one_field(buf, sizeof(buf), data, hentry))
545 hp = buf + strlen(hentry[hnum].name);
546 while (*hp == ' ' || *hp == '\t') hp++;
550 if (msginfo->date) break;
552 procheader_date_parse(NULL, hp, 0);
553 if (g_utf8_validate(hp, -1, NULL)) {
554 msginfo->date = g_strdup(hp);
556 gchar *utf = conv_codeset_strdup(
558 conv_get_locale_charset_str_no_utf8(),
561 !g_utf8_validate(utf, -1, NULL)) {
563 utf = g_malloc(strlen(buf)*2+1);
564 conv_localetodisp(utf,
571 if (msginfo->from) break;
572 msginfo->from = conv_unmime_header(hp, NULL, TRUE);
573 msginfo->fromname = procheader_get_fromname(msginfo->from);
574 remove_return(msginfo->from);
575 remove_return(msginfo->fromname);
578 tmp = conv_unmime_header(hp, NULL, TRUE);
583 g_strconcat(p, ", ", tmp, NULL);
586 msginfo->to = g_strdup(tmp);
590 tmp = conv_unmime_header(hp, NULL, TRUE);
595 g_strconcat(p, ", ", tmp, NULL);
598 msginfo->cc = g_strdup(tmp);
602 if (msginfo->newsgroups) {
603 p = msginfo->newsgroups;
604 msginfo->newsgroups =
605 g_strconcat(p, ",", hp, NULL);
608 msginfo->newsgroups = g_strdup(hp);
611 if (msginfo->subject) break;
612 msginfo->subject = conv_unmime_header(hp, NULL, FALSE);
613 unfold_line(msginfo->subject);
616 if (msginfo->msgid) break;
618 extract_parenthesis(hp, '<', '>');
620 msginfo->msgid = g_strdup(hp);
623 msginfo->references =
624 references_list_prepend(msginfo->references,
628 if (msginfo->inreplyto) break;
630 eliminate_parenthesis(hp, '(', ')');
631 if ((p = strrchr(hp, '<')) != NULL &&
632 strchr(p + 1, '>') != NULL) {
633 extract_parenthesis(p, '<', '>');
636 msginfo->inreplyto = g_strdup(p);
640 if (!g_ascii_strncasecmp(hp, "multipart/", 10))
641 MSG_SET_TMP_FLAGS(msginfo->flags, MSG_MULTIPART);
643 case H_DISPOSITION_NOTIFICATION_TO:
644 if (!msginfo->extradata)
645 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
646 if (msginfo->extradata->dispositionnotificationto) break;
647 msginfo->extradata->dispositionnotificationto = g_strdup(hp);
649 case H_RETURN_RECEIPT_TO:
650 if (!msginfo->extradata)
651 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
652 if (msginfo->extradata->returnreceiptto) break;
653 msginfo->extradata->returnreceiptto = g_strdup(hp);
655 /* partial download infos */
656 case H_SC_PARTIALLY_RETRIEVED:
657 if (!msginfo->extradata)
658 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
659 if (msginfo->extradata->partial_recv) break;
660 msginfo->extradata->partial_recv = g_strdup(hp);
662 case H_SC_ACCOUNT_SERVER:
663 if (!msginfo->extradata)
664 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
665 if (msginfo->extradata->account_server) break;
666 msginfo->extradata->account_server = g_strdup(hp);
668 case H_SC_ACCOUNT_LOGIN:
669 if (!msginfo->extradata)
670 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
671 if (msginfo->extradata->account_login) break;
672 msginfo->extradata->account_login = g_strdup(hp);
674 case H_SC_MESSAGE_SIZE:
675 if (msginfo->total_size) break;
676 msginfo->total_size = atoi(hp);
678 case H_SC_PLANNED_DOWNLOAD:
679 msginfo->planned_download = atoi(hp);
681 /* end partial download infos */
683 if (msginfo->fromspace) break;
684 msginfo->fromspace = g_strdup(hp);
685 remove_return(msginfo->fromspace);
689 if (!msginfo->extradata)
690 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
691 if (msginfo->extradata->list_post) break;
692 msginfo->extradata->list_post = g_strdup(hp);
694 case H_LIST_SUBSCRIBE:
695 if (!msginfo->extradata)
696 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
697 if (msginfo->extradata->list_subscribe) break;
698 msginfo->extradata->list_subscribe = g_strdup(hp);
700 case H_LIST_UNSUBSCRIBE:
701 if (!msginfo->extradata)
702 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
703 if (msginfo->extradata->list_unsubscribe) break;
704 msginfo->extradata->list_unsubscribe = g_strdup(hp);
707 if (!msginfo->extradata)
708 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
709 if (msginfo->extradata->list_help) break;
710 msginfo->extradata->list_help = g_strdup(hp);
713 if (!msginfo->extradata)
714 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
715 if (msginfo->extradata->list_archive) break;
716 msginfo->extradata->list_archive = g_strdup(hp);
719 if (!msginfo->extradata)
720 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
721 if (msginfo->extradata->list_owner) break;
722 msginfo->extradata->list_owner = g_strdup(hp);
725 if (!msginfo->extradata)
726 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
727 if (msginfo->extradata->resent_from) break;
728 msginfo->extradata->resent_from = g_strdup(hp);
734 /* to avoid performance penalty hooklist is invoked only for
735 headers known to be able to generate avatars */
736 if (hnum == H_FROM || hnum == H_X_FACE || hnum == H_FACE) {
737 AvatarCaptureData *acd = g_new0(AvatarCaptureData, 1);
738 /* no extra memory is wasted, hooks are expected to
739 take care of copying members when needed */
740 acd->msginfo = msginfo;
741 acd->header = hentry_full[hnum].name;
743 hooks_invoke(AVATAR_HEADER_UPDATE_HOOKLIST, (gpointer)acd);
748 if (!msginfo->inreplyto && msginfo->references)
750 g_strdup((gchar *)msginfo->references->data);
755 gchar *procheader_get_fromname(const gchar *str)
759 Xstrdup_a(tmp, str, return NULL);
762 extract_quote(tmp, '\"');
764 } else if (strchr(tmp, '<')) {
765 eliminate_parenthesis(tmp, '<', '>');
769 extract_parenthesis(tmp, '<', '>');
772 } else if (strchr(tmp, '(')) {
773 extract_parenthesis(tmp, '(', ')');
778 name = g_strdup(str);
780 name = g_strdup(tmp);
785 static gint procheader_scan_date_string(const gchar *str,
786 gchar *weekday, gint *day,
787 gchar *month, gint *year,
788 gint *hh, gint *mm, gint *ss,
799 result = sscanf(str, "%10s %d %9s %d %2d:%2d:%2d %5s",
800 weekday, day, month, year, hh, mm, ss, zone);
801 if (result == 8) return 0;
804 result = sscanf(str, "%3s,%d %9s %d %2d:%2d:%2d %5s",
805 weekday, day, month, year, hh, mm, ss, zone);
806 if (result == 8) return 0;
808 result = sscanf(str, "%d %9s %d %2d:%2d:%2d %5s",
809 day, month, year, hh, mm, ss, zone);
810 if (result == 7) return 0;
813 result = sscanf(str, "%10s %d %9s %d %2d:%2d:%2d",
814 weekday, day, month, year, hh, mm, ss);
815 if (result == 7) return 0;
817 result = sscanf(str, "%d %9s %d %2d:%2d:%2d",
818 day, month, year, hh, mm, ss);
819 if (result == 6) return 0;
822 result = sscanf(str, "%10s %d %9s %d %2d:%2d %5s",
823 weekday, day, month, year, hh, mm, zone);
824 if (result == 7) return 0;
826 result = sscanf(str, "%d %9s %d %2d:%2d %5s",
827 day, month, year, hh, mm, zone);
828 if (result == 6) return 0;
831 result = sscanf(str, "%10s %d %9s %d %2d:%2d",
832 weekday, day, month, year, hh, mm);
833 if (result == 6) return 0;
835 result = sscanf(str, "%d %9s %d %2d:%2d",
836 day, month, year, hh, mm);
837 if (result == 5) return 0;
841 result = sscanf(str, "%4d-%2d-%2d %2d:%2d:%2d+%2s:%2s",
842 year, &month_n, day, hh, mm, ss, zone1, zone2);
844 if (1 <= month_n && month_n <= 12) {
845 strncpy2(month, monthstr+((month_n-1)*3), 4);
847 strncpy2(zone+1, zone1, 3);
848 strncpy2(zone+3, zone2, 3);
856 result = sscanf(str, "%4d-%2d-%2d %2d:%2d:%2d",
857 year, &month_n, day, hh, mm, ss);
859 if (1 <= month_n && month_n <= 12) {
860 strncpy2(month, monthstr+((month_n-1)*3), 4);
869 * Hiro, most UNIXen support this function:
870 * http://www.mcsr.olemiss.edu/cgi-bin/man-cgi?getdate
872 gboolean procheader_date_parse_to_tm(const gchar *src, struct tm *t, char *zone)
885 memset(t, 0, sizeof *t);
887 if (procheader_scan_date_string(src, weekday, &day, month, &year,
888 &hh, &mm, &ss, zone) < 0) {
889 g_warning("Invalid date: %s\n", src);
893 /* Y2K compliant :) */
902 if ((p = strstr(monthstr, month)) != NULL)
903 dmonth = (gint)(p - monthstr) / 3 + 1;
905 g_warning("Invalid month: %s\n", month);
906 dmonth = G_DATE_BAD_MONTH;
913 t->tm_mon = dmonth - 1;
914 t->tm_year = year - 1900;
924 time_t procheader_date_parse(gchar *dest, const gchar *src, gint len)
932 GDateMonth dmonth = G_DATE_BAD_MONTH;
938 if (procheader_scan_date_string(src, weekday, &day, month, &year,
939 &hh, &mm, &ss, zone) < 0) {
941 strncpy2(dest, src, len);
945 /* Y2K compliant :) */
954 for (p = monthstr; *p != '\0'; p += 3) {
955 if (!g_ascii_strncasecmp(p, month, 3)) {
956 dmonth = (gint)(p - monthstr) / 3 + 1;
965 t.tm_mon = dmonth - 1;
966 t.tm_year = year - 1900;
972 tz_offset = remote_tzoffset_sec(zone);
974 timer += tzoffset_sec(&timer) - tz_offset;
977 procheader_date_get_localtime(dest, len, timer);
982 void procheader_date_get_localtime(gchar *dest, gint len, const time_t timer)
985 gchar *default_format = "%y/%m/%d(%a) %H:%M";
987 const gchar *src_codeset, *dest_codeset;
991 lt = localtime_r(&timer, &buf);
994 lt = localtime_r(&dummy, &buf);
997 if (prefs_common.date_format)
998 fast_strftime(dest, len, prefs_common.date_format, lt);
1000 fast_strftime(dest, len, default_format, lt);
1002 if (!g_utf8_validate(dest, -1, NULL)) {
1003 src_codeset = conv_get_locale_charset_str_no_utf8();
1004 dest_codeset = CS_UTF_8;
1005 str = conv_codeset_strdup(dest, src_codeset, dest_codeset);
1007 strncpy2(dest, str, len);
1013 /* Added by Mel Hadasht on 27 Aug 2001 */
1014 /* Get a header from msginfo */
1015 gint procheader_get_header_from_msginfo(MsgInfo *msginfo, gchar *buf, gint len, gchar *header)
1019 HeaderEntry hentry[]={ { NULL, NULL, TRUE },
1020 { NULL, NULL, FALSE } };
1023 hentry[0].name = header;
1025 cm_return_val_if_fail(msginfo != NULL, -1);
1026 file = procmsg_get_message_file_path(msginfo);
1027 if ((fp = g_fopen(file, "rb")) == NULL) {
1028 FILE_OP_ERROR(file, "fopen");
1032 val = procheader_get_one_field(buf,len, fp, hentry);
1033 if (fclose(fp) == EOF) {
1034 FILE_OP_ERROR(file, "fclose");
1047 HeaderEntry *procheader_entries_from_str(const gchar *str)
1049 HeaderEntry *entries = NULL, *he;
1050 int numh = 0, i = 0;
1051 gchar **names = NULL;
1052 const gchar *s = str;
1057 while (*s != '\0') {
1058 if (*s == ' ') ++numh;
1064 entries = g_new0(HeaderEntry, numh + 1); /* room for last NULL */
1066 ++s; /* skip first space */
1067 names = g_strsplit(s, " ", numh);
1070 he->name = g_strdup_printf("%s:", names[i]);
1080 void procheader_entries_free (HeaderEntry *entries)
1082 if (entries != NULL) {
1083 HeaderEntry *he = entries;
1084 while (he->name != NULL) {
1086 if (he->body != NULL)