/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2002 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#endif
#include <glib.h>
+#include <glib/gi18n.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
+#include <sys/stat.h>
-#include "intl.h"
#include "procheader.h"
#include "procmsg.h"
#include "codeconv.h"
#define BUFFSIZE 8192
-gint procheader_get_one_field(gchar *buf, gint len, FILE *fp,
+typedef char *(*getlinefunc) (char *, size_t, void *);
+typedef int (*peekcharfunc) (void *);
+typedef int (*getcharfunc) (void *);
+typedef gint (*get_one_field_func) (gchar *, size_t, void *, HeaderEntry[]);
+
+static gint string_get_one_field(gchar *buf, size_t len, char **str,
+ HeaderEntry hentry[]);
+
+static char *string_getline(char *buf, size_t len, char **str);
+static int string_peekchar(char **str);
+static int file_peekchar(FILE *fp);
+static gint generic_get_one_field(gchar *buf, size_t len, void *data,
+ HeaderEntry hentry[],
+ getlinefunc getline,
+ peekcharfunc peekchar,
+ gboolean unfold);
+static MsgInfo *parse_stream(void *data, gboolean isstring, MsgFlags flags,
+ gboolean full, gboolean decrypted);
+
+
+gint procheader_get_one_field(gchar *buf, size_t len, FILE *fp,
HeaderEntry hentry[])
+{
+ return generic_get_one_field(buf, len, fp, hentry,
+ (getlinefunc)fgets, (peekcharfunc)file_peekchar,
+ TRUE);
+}
+
+static gint string_get_one_field(gchar *buf, size_t len, char **str,
+ HeaderEntry hentry[])
+{
+ return generic_get_one_field(buf, len, str, hentry,
+ (getlinefunc)string_getline,
+ (peekcharfunc)string_peekchar,
+ TRUE);
+}
+
+static char *string_getline(char *buf, size_t len, char **str)
+{
+ if (!*str || !**str)
+ return NULL;
+
+ for (; **str && len > 1; --len)
+ if ((*buf++ = *(*str)++) == '\n')
+ break;
+ *buf = '\0';
+
+ return buf;
+}
+
+static int string_peekchar(char **str)
+{
+ return **str;
+}
+
+static int file_peekchar(FILE *fp)
+{
+ return ungetc(getc(fp), fp);
+}
+
+static gint generic_get_one_field(gchar *buf, size_t len, void *data,
+ HeaderEntry *hentry,
+ getlinefunc getline, peekcharfunc peekchar,
+ gboolean unfold)
{
gint nexthead;
gint hnum = 0;
/* skip non-required headers */
do {
do {
- if (fgets(buf, len, fp) == NULL)
+ if (getline(buf, len, data) == NULL)
return -1;
if (buf[0] == '\r' || buf[0] == '\n')
return -1;
for (hp = hentry, hnum = 0; hp->name != NULL;
hp++, hnum++) {
- if (!strncasecmp(hp->name, buf,
+ if (!g_ascii_strncasecmp(hp->name, buf,
strlen(hp->name)))
break;
}
} while (hp->name == NULL);
} else {
- if (fgets(buf, len, fp) == NULL) return -1;
+ if (getline(buf, len, data) == NULL) return -1;
if (buf[0] == '\r' || buf[0] == '\n') return -1;
}
- /* unfold the specified folded line */
- if (hp && hp->unfold) {
- gboolean folded = FALSE;
- gchar *bufp = buf + strlen(buf);
-
- for (; bufp > buf &&
- (*(bufp - 1) == '\n' || *(bufp - 1) == '\r');
- bufp--)
- *(bufp - 1) = '\0';
-
- while (1) {
- nexthead = fgetc(fp);
-
- /* folded */
- if (nexthead == ' ' || nexthead == '\t')
- folded = TRUE;
- else if (nexthead == EOF)
- break;
- else if (folded == TRUE) {
- if (nexthead == '\r' || nexthead == '\n') {
- folded = FALSE;
- continue;
- }
-
- if ((len - (bufp - buf)) <= 2) break;
-
- /* replace return code on the tail end
- with space */
- *bufp++ = ' ';
- *bufp++ = nexthead;
- *bufp = '\0';
- /* concatenate next line */
- if (fgets(bufp, len - (bufp - buf), fp)
- == NULL) break;
- bufp += strlen(bufp);
-
- for (; bufp > buf &&
- (*(bufp - 1) == '\n' || *(bufp - 1) == '\r');
- bufp--)
- *(bufp - 1) = '\0';
-
- folded = FALSE;
- } else {
- ungetc(nexthead, fp);
- break;
- }
- }
-
- return hnum;
- }
-
+ /* unfold line */
while (1) {
- nexthead = fgetc(fp);
+ nexthead = peekchar(data);
+ /* ([*WSP CRLF] 1*WSP) */
if (nexthead == ' ' || nexthead == '\t') {
- size_t buflen = strlen(buf);
-
+ size_t buflen;
+ /* trim previous trailing \n if requesting one header or
+ * unfolding was requested */
+ if ((!hentry && unfold) || (hp && hp->unfold))
+ strretchomp(buf);
+
+ buflen = strlen(buf);
+
/* concatenate next line */
if ((len - buflen) > 2) {
- gchar *p = buf + buflen;
-
- *p++ = nexthead;
- *p = '\0';
- buflen++;
- if (fgets(p, len - buflen, fp) == NULL)
+ if (getline(buf + buflen, len - buflen, data) == NULL)
break;
} else
break;
} else {
- if (nexthead != EOF)
- ungetc(nexthead, fp);
+ /* remove trailing new line */
+ strretchomp(buf);
break;
}
}
- /* remove trailing return code */
- strretchomp(buf);
-
return hnum;
}
-gchar *procheader_get_unfolded_line(gchar *buf, gint len, FILE *fp)
+gint procheader_get_one_field_asis(gchar *buf, size_t len, FILE *fp)
+{
+ return generic_get_one_field(buf, len, fp, NULL,
+ (getlinefunc)fgets,
+ (peekcharfunc)file_peekchar,
+ FALSE);
+}
+
+#if 0
+gchar *procheader_get_unfolded_line(gchar *buf, size_t len, FILE *fp)
{
gboolean folded = FALSE;
gint nexthead;
else if (nexthead == EOF)
break;
else if (folded == TRUE) {
- if (nexthead == '\r' || nexthead == '\n') {
+ if ((len - (bufp - buf)) <= 2) break;
+
+ if (nexthead == '\n') {
folded = FALSE;
continue;
}
- if ((len - (bufp - buf)) <= 2) break;
-
/* replace return code on the tail end
with space */
*bufp++ = ' ';
return buf;
}
+#endif
+#if 0
GSList *procheader_get_header_list_from_file(const gchar *file)
{
FILE *fp;
GSList *hlist;
- if ((fp = fopen(file, "rb")) == NULL) {
+ if ((fp = g_fopen(file, "rb")) == NULL) {
FILE_OP_ERROR(file, "fopen");
return NULL;
}
return hlist;
}
+#endif
+#if 0
GPtrArray *procheader_get_header_array(FILE *fp)
{
gchar buf[BUFFSIZE];
return headers;
}
+#endif
GPtrArray *procheader_get_header_array_asis(FILE *fp)
{
headers = g_ptr_array_new();
- while (procheader_get_one_field(buf, sizeof(buf), fp, NULL) != -1) {
+ while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
if ((header = procheader_parse_header(buf)) != NULL)
g_ptr_array_add(headers, header);
/*
return headers;
}
+#if 0
void procheader_header_list_destroy(GSList *hlist)
{
Header *header;
hlist = g_slist_remove(hlist, header);
}
}
+#endif
void procheader_header_array_destroy(GPtrArray *harray)
{
if (len1 != len2)
return 0;
- return (g_strncasecmp(hdr1, hdr2, len1) == 0);
+ return (g_ascii_strncasecmp(hdr1, hdr2, len1) == 0);
}
/*
Header * procheader_parse_header(gchar * buf)
{
- gchar tmp[BUFFSIZE];
gchar *p = buf;
Header * header;
header->name = g_strndup(buf, p - buf + 1);
p++;
while (*p == ' ' || *p == '\t') p++;
- conv_unmime_header(tmp, sizeof(tmp), p, NULL);
- header->body = g_strdup(tmp);
+ header->body = conv_unmime_header(p, NULL);
return header;
}
}
MsgInfo *procheader_parse_file(const gchar *file, MsgFlags flags,
gboolean full, gboolean decrypted)
{
+ struct stat s;
FILE *fp;
MsgInfo *msginfo;
- if ((fp = fopen(file, "rb")) == NULL) {
+ if (stat(file, &s) < 0) {
+ FILE_OP_ERROR(file, "stat");
+ return NULL;
+ }
+ if (!S_ISREG(s.st_mode))
+ return NULL;
+
+ if ((fp = g_fopen(file, "rb")) == NULL) {
FILE_OP_ERROR(file, "fopen");
return NULL;
}
msginfo = procheader_parse_stream(fp, flags, full, decrypted);
fclose(fp);
+
+ if (msginfo) {
+ msginfo->size = s.st_size;
+ msginfo->mtime = s.st_mtime;
+ }
+
return msginfo;
}
MsgInfo *procheader_parse_str(const gchar *str, MsgFlags flags, gboolean full,
gboolean decrypted)
{
- FILE *fp;
- MsgInfo *msginfo;
-
- if ((fp = str_open_as_stream(str)) == NULL)
- return NULL;
-
- msginfo = procheader_parse_stream(fp, flags, full, decrypted);
- fclose(fp);
- return msginfo;
+ return parse_stream(&str, TRUE, flags, full, decrypted);
}
enum
H_STATUS = 11,
H_X_STATUS = 12,
H_FROM_SPACE = 13,
- H_X_FACE = 14,
- H_DISPOSITION_NOTIFICATION_TO = 15,
- H_RETURN_RECEIPT_TO = 16
+ H_SC_PLANNED_DOWNLOAD = 14,
+ H_SC_MESSAGE_SIZE = 15,
+ H_FACE = 16,
+ H_X_FACE = 17,
+ H_DISPOSITION_NOTIFICATION_TO = 18,
+ H_RETURN_RECEIPT_TO = 19,
+ H_SC_PARTIALLY_RETRIEVED = 20,
+ H_SC_ACCOUNT_SERVER = 21,
+ H_SC_ACCOUNT_LOGIN = 22,
};
-MsgInfo *procheader_parse_stream(FILE *fp, MsgFlags flags, gboolean full,
+static HeaderEntry hentry_full[] = {{"Date:", NULL, FALSE},
+ {"From:", NULL, TRUE},
+ {"To:", NULL, TRUE},
+ {"Cc:", NULL, TRUE},
+ {"Newsgroups:", NULL, TRUE},
+ {"Subject:", NULL, TRUE},
+ {"Message-ID:", NULL, FALSE},
+ {"References:", NULL, FALSE},
+ {"In-Reply-To:", NULL, FALSE},
+ {"Content-Type:", NULL, FALSE},
+ {"Seen:", NULL, FALSE},
+ {"Status:", NULL, FALSE},
+ {"X-Status:", NULL, FALSE},
+ {"From ", NULL, FALSE},
+ {"SC-Marked-For-Download:", NULL, FALSE},
+ {"SC-Message-Size:", NULL, FALSE},
+ {"Face:", NULL, FALSE},
+ {"X-Face:", NULL, FALSE},
+ {"Disposition-Notification-To:", NULL, FALSE},
+ {"Return-Receipt-To:", NULL, FALSE},
+ {"SC-Partially-Retrieved:", NULL, FALSE},
+ {"SC-Account-Server:", NULL, FALSE},
+ {"SC-Account-Login:",NULL, FALSE},
+ {NULL, NULL, FALSE}};
+
+static HeaderEntry hentry_short[] = {{"Date:", NULL, FALSE},
+ {"From:", NULL, TRUE},
+ {"To:", NULL, TRUE},
+ {"Cc:", NULL, TRUE},
+ {"Newsgroups:", NULL, TRUE},
+ {"Subject:", NULL, TRUE},
+ {"Message-ID:", NULL, FALSE},
+ {"References:", NULL, FALSE},
+ {"In-Reply-To:", NULL, FALSE},
+ {"Content-Type:", NULL, FALSE},
+ {"Seen:", NULL, FALSE},
+ {"Status:", NULL, FALSE},
+ {"X-Status:", NULL, FALSE},
+ {"From ", NULL, FALSE},
+ {"SC-Marked-For-Download:", NULL, FALSE},
+ {"SC-Message-Size:",NULL, FALSE},
+ {NULL, NULL, FALSE}};
+
+HeaderEntry* procheader_get_headernames(gboolean full)
+{
+ return full ? hentry_full : hentry_short;
+}
+
+MsgInfo *procheader_parse_stream(FILE *fp, MsgFlags flags, gboolean full,
gboolean decrypted)
{
- static HeaderEntry hentry_full[] = {{"Date:", NULL, FALSE},
- {"From:", NULL, TRUE},
- {"To:", NULL, TRUE},
- {"Cc:", NULL, TRUE},
- {"Newsgroups:", NULL, TRUE},
- {"Subject:", NULL, TRUE},
- {"Message-Id:", NULL, FALSE},
- {"References:", NULL, FALSE},
- {"In-Reply-To:", NULL, FALSE},
- {"Content-Type:", NULL, FALSE},
- {"Seen:", NULL, FALSE},
- {"Status:", NULL, FALSE},
- {"X-Status:", NULL, FALSE},
- {"From ", NULL, FALSE},
- {"X-Face:", NULL, FALSE},
- {"Disposition-Notification-To:", NULL, FALSE},
- {"Return-Receipt-To:", NULL, FALSE},
- {NULL, NULL, FALSE}};
-
- static HeaderEntry hentry_short[] = {{"Date:", NULL, FALSE},
- {"From:", NULL, TRUE},
- {"To:", NULL, TRUE},
- {"Cc:", NULL, TRUE},
- {"Newsgroups:", NULL, TRUE},
- {"Subject:", NULL, TRUE},
- {"Message-Id:", NULL, FALSE},
- {"References:", NULL, FALSE},
- {"In-Reply-To:", NULL, FALSE},
- {"Content-Type:", NULL, FALSE},
- {"Seen:", NULL, FALSE},
- {"Status:", NULL, FALSE},
- {"X-Status:", NULL, FALSE},
- {"From ", NULL, FALSE},
- {NULL, NULL, FALSE}};
+ return parse_stream(fp, FALSE, flags, full, decrypted);
+}
+static MsgInfo *parse_stream(void *data, gboolean isstring, MsgFlags flags,
+ gboolean full, gboolean decrypted)
+{
MsgInfo *msginfo;
- gchar buf[BUFFSIZE], tmp[BUFFSIZE];
- gchar *reference = NULL;
- gchar *p;
+ gchar buf[BUFFSIZE];
+ gchar *p, *tmp;
gchar *hp;
HeaderEntry *hentry;
gint hnum;
+ get_one_field_func get_one_field =
+ isstring ? (get_one_field_func)string_get_one_field
+ : (get_one_field_func)procheader_get_one_field;
- hentry = full ? hentry_full : hentry_short;
+ hentry = procheader_get_headernames(full);
if (MSG_IS_QUEUED(flags) || MSG_IS_DRAFT(flags)) {
- while (fgets(buf, sizeof(buf), fp) != NULL)
- if (buf[0] == '\r' || buf[0] == '\n') break;
+ while (get_one_field(buf, sizeof(buf), data, NULL) != -1)
+ ; /* loop */
}
msginfo = procmsg_msginfo_new();
else
MSG_SET_PERM_FLAGS(msginfo->flags, MSG_NEW | MSG_UNREAD);
- if (decrypted)
- MSG_UNSET_TMP_FLAGS(msginfo->flags, MSG_MIME);
-
msginfo->inreplyto = NULL;
- while ((hnum = procheader_get_one_field(buf, sizeof(buf), fp, hentry))
+ while ((hnum = get_one_field(buf, sizeof(buf), data, hentry))
!= -1) {
hp = buf + strlen(hentry[hnum].name);
while (*hp == ' ' || *hp == '\t') hp++;
break;
case H_FROM:
if (msginfo->from) break;
- conv_unmime_header(tmp, sizeof(tmp), hp, NULL);
- msginfo->from = g_strdup(tmp);
- msginfo->fromname = procheader_get_fromname(tmp);
+ msginfo->from = conv_unmime_header(hp, NULL);
+ msginfo->fromname = procheader_get_fromname(msginfo->from);
+ replace_returns(msginfo->from);
+ replace_returns(msginfo->fromname);
break;
case H_TO:
- conv_unmime_header(tmp, sizeof(tmp), hp, NULL);
+ tmp = conv_unmime_header(hp, NULL);
if (msginfo->to) {
p = msginfo->to;
msginfo->to =
g_free(p);
} else
msginfo->to = g_strdup(tmp);
+ g_free(tmp);
break;
case H_CC:
- conv_unmime_header(tmp, sizeof(tmp), hp, NULL);
+ tmp = conv_unmime_header(hp, NULL);
if (msginfo->cc) {
p = msginfo->cc;
msginfo->cc =
g_free(p);
} else
msginfo->cc = g_strdup(tmp);
+ g_free(tmp);
break;
case H_NEWSGROUPS:
if (msginfo->newsgroups) {
g_strconcat(p, ",", hp, NULL);
g_free(p);
} else
- msginfo->newsgroups = g_strdup(buf + 12);
+ msginfo->newsgroups = g_strdup(hp);
break;
case H_SUBJECT:
if (msginfo->subject) break;
- conv_unmime_header(tmp, sizeof(tmp), hp, NULL);
- msginfo->subject = g_strdup(tmp);
+ msginfo->subject = conv_unmime_header(hp, NULL);
+ replace_returns(msginfo->subject);
break;
case H_MSG_ID:
if (msginfo->msgid) break;
msginfo->msgid = g_strdup(hp);
break;
case H_REFERENCES:
+ msginfo->references =
+ references_list_prepend(msginfo->references,
+ hp);
+ break;
case H_IN_REPLY_TO:
- if (!reference) {
- msginfo->references = g_strdup(hp);
- eliminate_parenthesis(hp, '(', ')');
- if ((p = strrchr(hp, '<')) != NULL &&
- strchr(p + 1, '>') != NULL) {
- extract_parenthesis(p, '<', '>');
- remove_space(p);
- if (*p != '\0')
- reference = g_strdup(p);
- }
+ if (msginfo->inreplyto) break;
+
+ eliminate_parenthesis(hp, '(', ')');
+ if ((p = strrchr(hp, '<')) != NULL &&
+ strchr(p + 1, '>') != NULL) {
+ extract_parenthesis(p, '<', '>');
+ remove_space(p);
+ if (*p != '\0')
+ msginfo->inreplyto = g_strdup(p);
}
break;
case H_CONTENT_TYPE:
- if (decrypted) {
- if (!strncasecmp(hp, "multipart", 9) &&
- strncasecmp(hp, "multipart/signed", 16)) {
- MSG_SET_TMP_FLAGS(msginfo->flags,
- MSG_MIME);
- }
- }
- else if (!strncasecmp(hp, "multipart/encrypted", 19)) {
- MSG_SET_TMP_FLAGS(msginfo->flags,
- MSG_ENCRYPTED);
- }
- else if (!strncasecmp(hp, "multipart", 9))
- MSG_SET_TMP_FLAGS(msginfo->flags, MSG_MIME);
+ if (!g_ascii_strncasecmp(hp, "multipart/", 10))
+ MSG_SET_TMP_FLAGS(msginfo->flags, MSG_MULTIPART);
break;
#ifdef ALLOW_HEADER_HINT
case H_SEEN:
MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_NEW|MSG_UNREAD);
break;
#endif
+ case H_FACE:
+ if (msginfo->face) break;
+ msginfo->face = g_strdup(hp);
+ break;
case H_X_FACE:
if (msginfo->xface) break;
msginfo->xface = g_strdup(hp);
case H_DISPOSITION_NOTIFICATION_TO:
if (msginfo->dispositionnotificationto) break;
msginfo->dispositionnotificationto = g_strdup(hp);
- MSG_SET_PERM_FLAGS(msginfo->flags, MSG_RETRCPT_PENDING);
break;
case H_RETURN_RECEIPT_TO:
if (msginfo->returnreceiptto) break;
msginfo->returnreceiptto = g_strdup(hp);
- MSG_SET_PERM_FLAGS(msginfo->flags, MSG_RETRCPT_PENDING);
+ break;
+ case H_SC_PARTIALLY_RETRIEVED:
+ if (msginfo->partial_recv) break;
+ msginfo->partial_recv = g_strdup(hp);
+ break;
+ case H_SC_ACCOUNT_SERVER:
+ if (msginfo->account_server) break;
+ msginfo->account_server = g_strdup(hp);
+ break;
+ case H_SC_ACCOUNT_LOGIN:
+ if (msginfo->account_login) break;
+ msginfo->account_login = g_strdup(hp);
+ break;
+ case H_SC_MESSAGE_SIZE:
+ if (msginfo->total_size) break;
+ msginfo->total_size = atoi(hp);
+ break;
+ case H_SC_PLANNED_DOWNLOAD:
+ msginfo->planned_download = atoi(hp);
break;
#ifdef ALLOW_HEADER_HINT
case H_STATUS:
break;
}
}
- msginfo->inreplyto = reference;
+
+ if (!msginfo->inreplyto && msginfo->references)
+ msginfo->inreplyto =
+ g_strdup((gchar *)msginfo->references->data);
return msginfo;
}
day, month, year, hh, mm, ss, zone);
if (result == 7) return 0;
+ *zone = '\0';
+ result = sscanf(str, "%10s %d %9s %d %2d:%2d:%2d",
+ weekday, day, month, year, hh, mm, ss);
+ if (result == 7) return 0;
+
+ result = sscanf(str, "%d %9s %d %2d:%2d:%2d",
+ day, month, year, hh, mm, ss);
+ if (result == 6) return 0;
+
*ss = 0;
result = sscanf(str, "%10s %d %9s %d %2d:%2d %5s",
weekday, day, month, year, hh, mm, zone);
day, month, year, hh, mm, zone);
if (result == 6) return 0;
+ *zone = '\0';
+ result = sscanf(str, "%10s %d %9s %d %2d:%2d",
+ weekday, day, month, year, hh, mm);
+ if (result == 6) return 0;
+
+ result = sscanf(str, "%d %9s %d %2d:%2d",
+ day, month, year, hh, mm);
+ if (result == 5) return 0;
+
return -1;
}
gint year;
gint hh, mm, ss;
gchar zone[6];
- GDateMonth dmonth;
+ GDateMonth dmonth = G_DATE_BAD_MONTH;
struct tm t;
gchar *p;
time_t timer;
+ time_t tz_offset;
if (procheader_scan_date_string(src, weekday, &day, month, &year,
&hh, &mm, &ss, zone) < 0) {
- g_warning("Invalid date: %s\n", src);
if (dest && len > 0)
strncpy2(dest, src, len);
return 0;
}
/* Y2K compliant :) */
- if (year < 100) {
- if (year < 70)
+ if (year < 1000) {
+ if (year < 50)
year += 2000;
else
year += 1900;
}
month[3] = '\0';
- if ((p = strstr(monthstr, month)) != NULL)
- dmonth = (gint)(p - monthstr) / 3 + 1;
- else {
- g_warning("Invalid month: %s\n", month);
- dmonth = G_DATE_BAD_MONTH;
+ for (p = monthstr; *p != '\0'; p += 3) {
+ if (!g_ascii_strncasecmp(p, month, 3)) {
+ dmonth = (gint)(p - monthstr) / 3 + 1;
+ break;
+ }
}
t.tm_sec = ss;
t.tm_isdst = -1;
timer = mktime(&t);
- timer += tzoffset_sec(&timer) - remote_tzoffset_sec(zone);
+ tz_offset = remote_tzoffset_sec(zone);
+ if (tz_offset != -1)
+ timer += tzoffset_sec(&timer) - tz_offset;
if (dest)
procheader_date_get_localtime(dest, len, timer);
{
struct tm *lt;
gchar *default_format = "%y/%m/%d(%a) %H:%M";
+ gchar *str;
+ const gchar *src_codeset, *dest_codeset;
lt = localtime(&timer);
strftime(dest, len, prefs_common.date_format, lt);
else
strftime(dest, len, default_format, lt);
+
+ src_codeset = conv_get_locale_charset_str();
+ dest_codeset = CS_UTF_8;
+ str = conv_codeset_strdup(dest, src_codeset, dest_codeset);
+ if (str) {
+ g_snprintf(dest, len, "%s", str);
+ strncpy2(dest, str, len);
+ g_free(str);
+ }
}
-gint get_header_from_msginfo(MsgInfo *msginfo, gchar *buf, gint len,gchar *header)
+/* Added by Mel Hadasht on 27 Aug 2001 */
+/* Get a header from msginfo */
+gint procheader_get_header_from_msginfo(MsgInfo *msginfo, gchar *buf, gint len, gchar *header)
{
gchar *file;
FILE *fp;
- HeaderEntry hentry[]={{header,NULL,TRUE},
- {NULL,NULL,FALSE}};
+ HeaderEntry hentry[]={ { NULL, NULL, TRUE },
+ { NULL, NULL, FALSE } };
gint val;
+
+ hentry[0].name = header;
g_return_val_if_fail(msginfo != NULL, -1);
file = procmsg_get_message_file_path(msginfo);
- if ((fp = fopen(file, "rb")) == NULL) {
+ if ((fp = g_fopen(file, "rb")) == NULL) {
FILE_OP_ERROR(file, "fopen");
g_free(file);
return -1;
}
- val=procheader_get_one_field(buf,len, fp, hentry);
+ val = procheader_get_one_field(buf,len, fp, hentry);
if (fclose(fp) == EOF) {
FILE_OP_ERROR(file, "fclose");
- unlink(file);
+ g_unlink(file);
+ g_free(file);
return -1;
}
+
+ g_free(file);
if (val == -1)
return -1;