/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2004 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Claws Mail team
* This file (C) 2004 Colin Leroy
*
* This program is free software; you can redistribute it and/or modify
*
* 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.
*/
/* Partial download:
time_t recv_time;
time_t now;
gint partial_recv;
+ gchar *sanitized_uid = NULL;
- if (!msginfo->account_server
- || !msginfo->account_login
- || !msginfo->partial_recv)
+ if (!msginfo->extradata)
+ return FALSE;
+
+ sanitized_uid = g_strdup(msginfo->extradata->account_login);
+
+ subst_for_filename(sanitized_uid);
+
+ if (!msginfo->extradata->account_server
+ || !msginfo->extradata->account_login
+ || !msginfo->extradata->partial_recv)
return FALSE;
path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
- "uidl", G_DIR_SEPARATOR_S, msginfo->account_server,
- "-", msginfo->account_login, NULL);
- if ((fp = fopen(path, "rb")) == NULL) {
+ "uidl", G_DIR_SEPARATOR_S, msginfo->extradata->account_server,
+ "-", msginfo->extradata->account_login, NULL);
+ if ((fp = g_fopen(path, "rb")) == NULL) {
if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
g_free(path);
path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
- "uidl-", msginfo->account_server,
- "-", msginfo->account_login, NULL);
- if ((fp = fopen(path, "rb")) == NULL) {
+ "uidl-", msginfo->extradata->account_server,
+ "-", sanitized_uid, NULL);
+ if ((fp = g_fopen(path, "rb")) == NULL) {
if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
+ g_free(sanitized_uid);
g_free(path);
return FALSE;
}
}
+ g_free(sanitized_uid);
g_free(path);
now = time(NULL);
recv_time = RECV_TIME_NONE;
partial_recv = POP3_TOTALLY_RECEIVED;
- if (sscanf(buf, "%s\t%ld\t%s", uidl, &recv_time, tmp) < 2) {
+ if (sscanf(buf, "%s\t%ld\t%s", uidl, (long int *) &recv_time,
+ tmp) < 2) {
if (sscanf(buf, "%s", uidl) != 1)
continue;
else {
recv_time = now;
}
}
- if (!strcmp(uidl, msginfo->partial_recv)) {
+ if (!strcmp(uidl, msginfo->extradata->partial_recv)) {
fclose(fp);
return TRUE;
}
int start = TRUE;
gchar partial_recv[POPBUFSIZE];
int err = -1;
-
gchar *filename;
MsgInfo *tinfo;
+ gchar *sanitized_uid = NULL;
+
filename = procmsg_get_message_file_path(msginfo);
if (!filename) {
g_warning("can't get message file path.\n");
return err;
}
tinfo = procheader_parse_file(filename, msginfo->flags, TRUE, TRUE);
+
+ if (!tinfo->extradata) {
+ g_free(filename);
+ return err;
+ }
+
+ sanitized_uid = g_strdup(tinfo->extradata->account_login);
+ subst_for_filename(sanitized_uid);
- if (!tinfo->account_server
- || !tinfo->account_login
- || !tinfo->partial_recv) {
+ if (!tinfo->extradata->account_server
+ || !tinfo->extradata->account_login
+ || !tinfo->extradata->partial_recv) {
goto bail;
}
path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
- "uidl", G_DIR_SEPARATOR_S, tinfo->account_server,
- "-", tinfo->account_login, NULL);
- if ((fp = fopen(path, "rb")) == NULL) {
+ "uidl", G_DIR_SEPARATOR_S, tinfo->extradata->account_server,
+ "-", sanitized_uid, NULL);
+
+ if ((fp = g_fopen(path, "rb")) == NULL) {
perror("fopen1");
if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
g_free(path);
path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
- "uidl-", tinfo->account_server,
- "-", tinfo->account_login, NULL);
- if ((fp = fopen(path, "rb")) == NULL) {
+ "uidl-", tinfo->extradata->account_server,
+ "-", tinfo->extradata->account_login, NULL);
+ if ((fp = g_fopen(path, "rb")) == NULL) {
if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
g_free(path);
+ goto bail;
}
- goto bail;
}
pathnew = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
- "uidl", G_DIR_SEPARATOR_S, tinfo->account_server,
- "-", tinfo->account_login, ".new", NULL);
- if ((fpnew = fopen(pathnew, "wb")) == NULL) {
+ "uidl", G_DIR_SEPARATOR_S, tinfo->extradata->account_server,
+ "-", sanitized_uid, ".new", NULL);
+
+ g_free(sanitized_uid);
+
+ if ((fpnew = g_fopen(pathnew, "wb")) == NULL) {
perror("fopen2");
fclose(fp);
g_free(pathnew);
sprintf(partial_recv,"0");
if (sscanf(buf, "%s\t%ld\t%s",
- uidl, &recv_time, partial_recv) < 2) {
+ uidl, (long int *) &recv_time, partial_recv) < 2) {
if (sscanf(buf, "%s", uidl) != 1)
continue;
else {
recv_time = now;
}
}
- if (strcmp(tinfo->partial_recv, uidl)) {
+ if (strcmp(tinfo->extradata->partial_recv, uidl)) {
fprintf(fpnew, "%s\t%ld\t%s\n",
- uidl, recv_time, partial_recv);
+ uidl, (long int) recv_time, partial_recv);
} else {
gchar *stat = NULL;
if (download == POP3_PARTIAL_DLOAD_DLOAD) {
stat = g_strdup("0");
fprintf(fpnew, "%s\t%ld\t%s\n",
- uidl, recv_time, stat);
+ uidl, (long int) recv_time, stat);
g_free(stat);
}
}
g_free(path);
g_free(pathnew);
- if ((fp = fopen(filename,"rb")) == NULL) {
+ if ((fp = g_fopen(filename,"rb")) == NULL) {
perror("fopen3");
goto bail;
}
pathnew = g_strdup_printf("%s.new", filename);
- if ((fpnew = fopen(pathnew, "wb")) == NULL) {
+ if ((fpnew = g_fopen(pathnew, "wb")) == NULL) {
perror("fopen4");
fclose(fp);
g_free(pathnew);
goto bail;
}
- while ((len = fread(buf, sizeof(gchar), sizeof(buf)-1, fp)) > 0) {
- buf[len]='\0';
- if (start) {
- start = FALSE;
- fprintf(fpnew, "SC-Marked-For-Download: %d\n",
- download);
-
- if(strlen(buf) > strlen("SC-Marked-For-Download: x\n")
- && !strncmp(buf, "SC-Marked-For-Download:",
- strlen("SC-Marked-For-Download:"))) {
- fprintf(fpnew, "%s",
- buf+strlen("SC-Marked-For-Download: x\n"));
- continue;
- }
+ fprintf(fpnew, "SC-Marked-For-Download: %d\n",
+ download);
+ while (fgets(buf, sizeof(buf)-1, fp) != NULL) {
+ if(strlen(buf) > strlen("SC-Marked-For-Download: x\n")
+ && !strncmp(buf, "SC-Marked-For-Download:",
+ strlen("SC-Marked-For-Download:"))) {
+ fprintf(fpnew, "%s",
+ buf+strlen("SC-Marked-For-Download: x\n"));
+ continue;
+ } else if (strlen(buf) == strlen("SC-Marked-For-Download: x\n")
+ && !strncmp(buf, "SC-Marked-For-Download:",
+ strlen("SC-Marked-For-Download:"))) {
+ continue;
}
fprintf(fpnew, "%s", buf);
}
fclose(fpnew);
fclose(fp);
- unlink(filename);
+ g_unlink(filename);
rename(pathnew, filename);
g_free(pathnew);
msginfo->planned_download = download;
time_t recv_time;
time_t now;
gint partial_recv;
-
+ gchar *sanitized_uid = g_strdup(login);
+
+ subst_for_filename(sanitized_uid);
+
path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
"uidl", G_DIR_SEPARATOR_S,
- server, "-", login, NULL);
- if ((fp = fopen(path, "rb")) == NULL) {
+ server, "-", sanitized_uid, NULL);
+ if ((fp = g_fopen(path, "rb")) == NULL) {
if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
g_free(path);
path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
"uidl-", server,
- "-", login, NULL);
- if ((fp = fopen(path, "rb")) == NULL) {
+ "-", sanitized_uid, NULL);
+ if ((fp = g_fopen(path, "rb")) == NULL) {
if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
+ g_free(sanitized_uid);
g_free(path);
return result;
}
}
+ g_free(sanitized_uid);
g_free(path);
now = time(NULL);
recv_time = RECV_TIME_NONE;
partial_recv = POP3_TOTALLY_RECEIVED;
- if (sscanf(buf, "%s\t%ld\t%s", uidl, &recv_time, tmp) < 2) {
+ if (sscanf(buf, "%s\t%ld\t%s", uidl, (long int *) &recv_time,
+ tmp) < 2) {
if (sscanf(buf, "%s", uidl) != 1)
continue;
else {