2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2011 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"
259 static gboolean header_is_addr_field(const gchar *hdr)
261 static char *addr_headers[] = {
268 "Followup-and-Reply-To:",
269 "Disposition-Notification-To:",
270 "Return-Receipt-To:",
277 for (i = 0; addr_headers[i] != NULL; i++)
278 if (!strcasecmp(hdr, addr_headers[i]))
284 Header * procheader_parse_header(gchar * buf)
288 gboolean addr_field = FALSE;
290 if ((*buf == ':') || (*buf == ' '))
293 for (p = buf; *p ; p++) {
294 if ((*p == ':') || (*p == ' ')) {
295 header = g_new(Header, 1);
296 header->name = g_strndup(buf, p - buf + 1);
297 addr_field = header_is_addr_field(header->name);
299 while (*p == ' ' || *p == '\t') p++;
300 header->body = conv_unmime_header(p, NULL, addr_field);
307 void procheader_get_header_fields(FILE *fp, HeaderEntry hentry[])
314 if (hentry == NULL) return;
316 while ((hnum = procheader_get_one_field(buf, sizeof(buf), fp, hentry))
320 p = buf + strlen(hp->name);
321 while (*p == ' ' || *p == '\t') p++;
323 if (hp->body == NULL)
324 hp->body = g_strdup(p);
325 else if (procheader_headername_equal(hp->name, "To") ||
326 procheader_headername_equal(hp->name, "Cc")) {
327 gchar *tp = hp->body;
328 hp->body = g_strconcat(tp, ", ", p, NULL);
334 MsgInfo *procheader_parse_file(const gchar *file, MsgFlags flags,
335 gboolean full, gboolean decrypted)
341 if (g_stat(file, &s) < 0) {
342 FILE_OP_ERROR(file, "stat");
345 if (!S_ISREG(s.st_mode))
348 if ((fp = g_fopen(file, "rb")) == NULL) {
349 FILE_OP_ERROR(file, "fopen");
353 msginfo = procheader_parse_stream(fp, flags, full, decrypted);
357 msginfo->size = s.st_size;
358 msginfo->mtime = s.st_mtime;
364 MsgInfo *procheader_parse_str(const gchar *str, MsgFlags flags, gboolean full,
367 return parse_stream(&str, TRUE, flags, full, decrypted);
386 H_SC_PLANNED_DOWNLOAD = 14,
387 H_SC_MESSAGE_SIZE = 15,
390 H_DISPOSITION_NOTIFICATION_TO = 18,
391 H_RETURN_RECEIPT_TO = 19,
392 H_SC_PARTIALLY_RETRIEVED = 20,
393 H_SC_ACCOUNT_SERVER = 21,
394 H_SC_ACCOUNT_LOGIN = 22,
396 H_LIST_SUBSCRIBE = 24,
397 H_LIST_UNSUBSCRIBE = 25,
403 static HeaderEntry hentry_full[] = {{"Date:", NULL, FALSE},
404 {"From:", NULL, TRUE},
407 {"Newsgroups:", NULL, TRUE},
408 {"Subject:", NULL, TRUE},
409 {"Message-ID:", NULL, FALSE},
410 {"References:", NULL, FALSE},
411 {"In-Reply-To:", NULL, FALSE},
412 {"Content-Type:", NULL, FALSE},
413 {"Seen:", NULL, FALSE},
414 {"Status:", NULL, FALSE},
415 {"X-Status:", NULL, FALSE},
416 {"From ", NULL, FALSE},
417 {"SC-Marked-For-Download:", NULL, FALSE},
418 {"SC-Message-Size:", NULL, FALSE},
419 {"Face:", NULL, FALSE},
420 {"X-Face:", NULL, FALSE},
421 {"Disposition-Notification-To:", NULL, FALSE},
422 {"Return-Receipt-To:", NULL, FALSE},
423 {"SC-Partially-Retrieved:", NULL, FALSE},
424 {"SC-Account-Server:", NULL, FALSE},
425 {"SC-Account-Login:",NULL, FALSE},
426 {"List-Post:", NULL, TRUE},
427 {"List-Subscribe:", NULL, TRUE},
428 {"List-Unsubscribe:",NULL, TRUE},
429 {"List-Help:", NULL, TRUE},
430 {"List-Archive:", NULL, TRUE},
431 {"List-Owner:", NULL, TRUE},
432 {NULL, NULL, FALSE}};
434 static HeaderEntry hentry_short[] = {{"Date:", NULL, FALSE},
435 {"From:", NULL, TRUE},
438 {"Newsgroups:", NULL, TRUE},
439 {"Subject:", NULL, TRUE},
440 {"Message-ID:", NULL, FALSE},
441 {"References:", NULL, FALSE},
442 {"In-Reply-To:", NULL, FALSE},
443 {"Content-Type:", NULL, FALSE},
444 {"Seen:", NULL, FALSE},
445 {"Status:", NULL, FALSE},
446 {"X-Status:", NULL, FALSE},
447 {"From ", NULL, FALSE},
448 {"SC-Marked-For-Download:", NULL, FALSE},
449 {"SC-Message-Size:",NULL, FALSE},
450 {NULL, NULL, FALSE}};
452 static HeaderEntry* procheader_get_headernames(gboolean full)
454 return full ? hentry_full : hentry_short;
457 MsgInfo *procheader_parse_stream(FILE *fp, MsgFlags flags, gboolean full,
460 return parse_stream(fp, FALSE, flags, full, decrypted);
463 static MsgInfo *parse_stream(void *data, gboolean isstring, MsgFlags flags,
464 gboolean full, gboolean decrypted)
472 void *orig_data = data;
474 get_one_field_func get_one_field =
475 isstring ? (get_one_field_func)string_get_one_field
476 : (get_one_field_func)procheader_get_one_field;
478 hentry = procheader_get_headernames(full);
480 if (MSG_IS_QUEUED(flags) || MSG_IS_DRAFT(flags)) {
481 while (get_one_field(buf, sizeof(buf), data, NULL) != -1) {
482 if ((!strncmp(buf, "X-Claws-End-Special-Headers: 1",
483 strlen("X-Claws-End-Special-Headers:"))) ||
484 (!strncmp(buf, "X-Sylpheed-End-Special-Headers: 1",
485 strlen("X-Sylpheed-End-Special-Headers:"))))
487 /* from other mailers */
488 if (!strncmp(buf, "Date: ", 6)
489 || !strncmp(buf, "To: ", 4)
490 || !strncmp(buf, "From: ", 6)
491 || !strncmp(buf, "Subject: ", 9)) {
495 rewind((FILE *)data);
501 msginfo = procmsg_msginfo_new();
503 if (flags.tmp_flags || flags.perm_flags)
504 msginfo->flags = flags;
506 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_NEW | MSG_UNREAD);
508 msginfo->inreplyto = NULL;
510 while ((hnum = get_one_field(buf, sizeof(buf), data, hentry))
512 hp = buf + strlen(hentry[hnum].name);
513 while (*hp == ' ' || *hp == '\t') hp++;
517 if (msginfo->date) break;
519 procheader_date_parse(NULL, hp, 0);
520 if (g_utf8_validate(hp, -1, NULL)) {
521 msginfo->date = g_strdup(hp);
523 gchar *utf = conv_codeset_strdup(
525 conv_get_locale_charset_str_no_utf8(),
528 !g_utf8_validate(utf, -1, NULL)) {
530 utf = g_malloc(strlen(buf)*2+1);
531 conv_localetodisp(utf,
538 if (msginfo->from) break;
539 msginfo->from = conv_unmime_header(hp, NULL, TRUE);
540 msginfo->fromname = procheader_get_fromname(msginfo->from);
541 remove_return(msginfo->from);
542 remove_return(msginfo->fromname);
545 tmp = conv_unmime_header(hp, NULL, TRUE);
550 g_strconcat(p, ", ", tmp, NULL);
553 msginfo->to = g_strdup(tmp);
557 tmp = conv_unmime_header(hp, NULL, TRUE);
562 g_strconcat(p, ", ", tmp, NULL);
565 msginfo->cc = g_strdup(tmp);
569 if (msginfo->newsgroups) {
570 p = msginfo->newsgroups;
571 msginfo->newsgroups =
572 g_strconcat(p, ",", hp, NULL);
575 msginfo->newsgroups = g_strdup(hp);
578 if (msginfo->subject) break;
579 msginfo->subject = conv_unmime_header(hp, NULL, FALSE);
580 unfold_line(msginfo->subject);
583 if (msginfo->msgid) break;
585 extract_parenthesis(hp, '<', '>');
587 msginfo->msgid = g_strdup(hp);
590 msginfo->references =
591 references_list_prepend(msginfo->references,
595 if (msginfo->inreplyto) break;
597 eliminate_parenthesis(hp, '(', ')');
598 if ((p = strrchr(hp, '<')) != NULL &&
599 strchr(p + 1, '>') != NULL) {
600 extract_parenthesis(p, '<', '>');
603 msginfo->inreplyto = g_strdup(p);
607 if (!g_ascii_strncasecmp(hp, "multipart/", 10))
608 MSG_SET_TMP_FLAGS(msginfo->flags, MSG_MULTIPART);
610 #ifdef ALLOW_HEADER_HINT
612 /* mnews Seen header */
613 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_NEW|MSG_UNREAD);
617 if (!msginfo->extradata)
618 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
619 if (msginfo->extradata->face) break;
620 msginfo->extradata->face = g_strdup(hp);
623 if (!msginfo->extradata)
624 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
625 if (msginfo->extradata->xface) break;
626 msginfo->extradata->xface = g_strdup(hp);
628 case H_DISPOSITION_NOTIFICATION_TO:
629 if (!msginfo->extradata)
630 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
631 if (msginfo->extradata->dispositionnotificationto) break;
632 msginfo->extradata->dispositionnotificationto = g_strdup(hp);
634 case H_RETURN_RECEIPT_TO:
635 if (!msginfo->extradata)
636 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
637 if (msginfo->extradata->returnreceiptto) break;
638 msginfo->extradata->returnreceiptto = g_strdup(hp);
640 /* partial download infos */
641 case H_SC_PARTIALLY_RETRIEVED:
642 if (!msginfo->extradata)
643 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
644 if (msginfo->extradata->partial_recv) break;
645 msginfo->extradata->partial_recv = g_strdup(hp);
647 case H_SC_ACCOUNT_SERVER:
648 if (!msginfo->extradata)
649 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
650 if (msginfo->extradata->account_server) break;
651 msginfo->extradata->account_server = g_strdup(hp);
653 case H_SC_ACCOUNT_LOGIN:
654 if (!msginfo->extradata)
655 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
656 if (msginfo->extradata->account_login) break;
657 msginfo->extradata->account_login = g_strdup(hp);
659 case H_SC_MESSAGE_SIZE:
660 if (msginfo->total_size) break;
661 msginfo->total_size = atoi(hp);
663 case H_SC_PLANNED_DOWNLOAD:
664 msginfo->planned_download = atoi(hp);
666 /* end partial download infos */
667 #ifdef ALLOW_HEADER_HINT
669 if (strchr(hp, 'R') != NULL)
670 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_UNREAD);
671 if (strchr(hp, 'O') != NULL)
672 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_NEW);
673 if (strchr(hp, 'U') != NULL)
674 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_UNREAD);
677 if (strchr(hp, 'D') != NULL)
678 MSG_SET_PERM_FLAGS(msginfo->flags,
680 if (strchr(hp, 'F') != NULL)
681 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_MARKED);
682 if (strchr(hp, 'd') != NULL)
683 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_DELETED);
684 if (strchr(hp, 'r') != NULL)
685 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
686 if (strchr(hp, 'f') != NULL)
687 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
691 if (msginfo->fromspace) break;
692 msginfo->fromspace = g_strdup(hp);
693 remove_return(msginfo->fromspace);
697 if (!msginfo->extradata)
698 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
699 if (msginfo->extradata->list_post) break;
700 msginfo->extradata->list_post = g_strdup(hp);
702 case H_LIST_SUBSCRIBE:
703 if (!msginfo->extradata)
704 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
705 if (msginfo->extradata->list_subscribe) break;
706 msginfo->extradata->list_subscribe = g_strdup(hp);
708 case H_LIST_UNSUBSCRIBE:
709 if (!msginfo->extradata)
710 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
711 if (msginfo->extradata->list_unsubscribe) break;
712 msginfo->extradata->list_unsubscribe = g_strdup(hp);
715 if (!msginfo->extradata)
716 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
717 if (msginfo->extradata->list_help) break;
718 msginfo->extradata->list_help = g_strdup(hp);
721 if (!msginfo->extradata)
722 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
723 if (msginfo->extradata->list_archive) break;
724 msginfo->extradata->list_archive = g_strdup(hp);
727 if (!msginfo->extradata)
728 msginfo->extradata = g_new0(MsgInfoExtraData, 1);
729 if (msginfo->extradata->list_owner) break;
730 msginfo->extradata->list_owner = g_strdup(hp);
738 if (!msginfo->inreplyto && msginfo->references)
740 g_strdup((gchar *)msginfo->references->data);
745 gchar *procheader_get_fromname(const gchar *str)
749 Xstrdup_a(tmp, str, return NULL);
752 extract_quote(tmp, '\"');
754 } else if (strchr(tmp, '<')) {
755 eliminate_parenthesis(tmp, '<', '>');
759 extract_parenthesis(tmp, '<', '>');
762 } else if (strchr(tmp, '(')) {
763 extract_parenthesis(tmp, '(', ')');
768 name = g_strdup(str);
770 name = g_strdup(tmp);
775 static gint procheader_scan_date_string(const gchar *str,
776 gchar *weekday, gint *day,
777 gchar *month, gint *year,
778 gint *hh, gint *mm, gint *ss,
789 result = sscanf(str, "%10s %d %9s %d %2d:%2d:%2d %5s",
790 weekday, day, month, year, hh, mm, ss, zone);
791 if (result == 8) return 0;
794 result = sscanf(str, "%3s,%d %9s %d %2d:%2d:%2d %5s",
795 weekday, day, month, year, hh, mm, ss, zone);
796 if (result == 8) return 0;
798 result = sscanf(str, "%d %9s %d %2d:%2d:%2d %5s",
799 day, month, year, hh, mm, ss, zone);
800 if (result == 7) return 0;
803 result = sscanf(str, "%10s %d %9s %d %2d:%2d:%2d",
804 weekday, day, month, year, hh, mm, ss);
805 if (result == 7) return 0;
807 result = sscanf(str, "%d %9s %d %2d:%2d:%2d",
808 day, month, year, hh, mm, ss);
809 if (result == 6) return 0;
812 result = sscanf(str, "%10s %d %9s %d %2d:%2d %5s",
813 weekday, day, month, year, hh, mm, zone);
814 if (result == 7) return 0;
816 result = sscanf(str, "%d %9s %d %2d:%2d %5s",
817 day, month, year, hh, mm, zone);
818 if (result == 6) return 0;
821 result = sscanf(str, "%10s %d %9s %d %2d:%2d",
822 weekday, day, month, year, hh, mm);
823 if (result == 6) return 0;
825 result = sscanf(str, "%d %9s %d %2d:%2d",
826 day, month, year, hh, mm);
827 if (result == 5) return 0;
831 result = sscanf(str, "%4d-%2d-%2d %2d:%2d:%2d+%2s:%2s",
832 year, &month_n, day, hh, mm, ss, zone1, zone2);
834 if (1 <= month_n && month_n <= 12) {
835 strncpy2(month, monthstr+((month_n-1)*3), 4);
837 strncpy2(zone+1, zone1, 3);
838 strncpy2(zone+3, zone2, 3);
846 result = sscanf(str, "%4d-%2d-%2d %2d:%2d:%2d",
847 year, &month_n, day, hh, mm, ss);
849 if (1 <= month_n && month_n <= 12) {
850 strncpy2(month, monthstr+((month_n-1)*3), 4);
859 * Hiro, most UNIXen support this function:
860 * http://www.mcsr.olemiss.edu/cgi-bin/man-cgi?getdate
862 gboolean procheader_date_parse_to_tm(const gchar *src, struct tm *t, char *zone)
875 memset(t, 0, sizeof *t);
877 if (procheader_scan_date_string(src, weekday, &day, month, &year,
878 &hh, &mm, &ss, zone) < 0) {
879 g_warning("Invalid date: %s\n", src);
883 /* Y2K compliant :) */
892 if ((p = strstr(monthstr, month)) != NULL)
893 dmonth = (gint)(p - monthstr) / 3 + 1;
895 g_warning("Invalid month: %s\n", month);
896 dmonth = G_DATE_BAD_MONTH;
903 t->tm_mon = dmonth - 1;
904 t->tm_year = year - 1900;
914 time_t procheader_date_parse(gchar *dest, const gchar *src, gint len)
922 GDateMonth dmonth = G_DATE_BAD_MONTH;
928 if (procheader_scan_date_string(src, weekday, &day, month, &year,
929 &hh, &mm, &ss, zone) < 0) {
931 strncpy2(dest, src, len);
935 /* Y2K compliant :) */
944 for (p = monthstr; *p != '\0'; p += 3) {
945 if (!g_ascii_strncasecmp(p, month, 3)) {
946 dmonth = (gint)(p - monthstr) / 3 + 1;
955 t.tm_mon = dmonth - 1;
956 t.tm_year = year - 1900;
962 tz_offset = remote_tzoffset_sec(zone);
964 timer += tzoffset_sec(&timer) - tz_offset;
967 procheader_date_get_localtime(dest, len, timer);
972 void procheader_date_get_localtime(gchar *dest, gint len, const time_t timer)
975 gchar *default_format = "%y/%m/%d(%a) %H:%M";
977 const gchar *src_codeset, *dest_codeset;
981 lt = localtime_r(&timer, &buf);
984 lt = localtime_r(&dummy, &buf);
987 if (prefs_common.date_format)
988 fast_strftime(dest, len, prefs_common.date_format, lt);
990 fast_strftime(dest, len, default_format, lt);
992 if (!g_utf8_validate(dest, -1, NULL)) {
993 src_codeset = conv_get_locale_charset_str_no_utf8();
994 dest_codeset = CS_UTF_8;
995 str = conv_codeset_strdup(dest, src_codeset, dest_codeset);
997 strncpy2(dest, str, len);
1003 /* Added by Mel Hadasht on 27 Aug 2001 */
1004 /* Get a header from msginfo */
1005 gint procheader_get_header_from_msginfo(MsgInfo *msginfo, gchar *buf, gint len, gchar *header)
1009 HeaderEntry hentry[]={ { NULL, NULL, TRUE },
1010 { NULL, NULL, FALSE } };
1013 hentry[0].name = header;
1015 cm_return_val_if_fail(msginfo != NULL, -1);
1016 file = procmsg_get_message_file_path(msginfo);
1017 if ((fp = g_fopen(file, "rb")) == NULL) {
1018 FILE_OP_ERROR(file, "fopen");
1022 val = procheader_get_one_field(buf,len, fp, hentry);
1023 if (fclose(fp) == EOF) {
1024 FILE_OP_ERROR(file, "fclose");