2005-09-30 [colin] 1.9.14cvs62
[claws.git] / src / partial_download.c
index 80e0506266ee4414ed988829201d06a1c86e8018..95fde101dd6858183a717b5dd337c9560baf6ad5 100644 (file)
@@ -15,7 +15,7 @@
  *
  * 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:
@@ -47,6 +47,7 @@
 #endif
 
 #include <glib.h>
+#include <glib/gi18n.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdarg.h>
@@ -55,7 +56,6 @@
 #include <time.h>
 #include <errno.h>
 
-#include "intl.h"
 #include "partial_download.h"
 #include "utils.h"
 #include "pop.h"
@@ -72,7 +72,10 @@ int partial_msg_in_uidl_list(MsgInfo *msginfo)
        time_t recv_time;
        time_t now;
        gint partial_recv;
+       gchar *sanitized_uid = g_strdup(msginfo->account_login);
        
+       subst_for_filename(sanitized_uid);
+
        if (!msginfo->account_server
        ||  !msginfo->account_login
        ||  !msginfo->partial_recv)
@@ -81,18 +84,20 @@ int partial_msg_in_uidl_list(MsgInfo *msginfo)
        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) {
+       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) {
+                                  "-", 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);
@@ -103,7 +108,8 @@ int partial_msg_in_uidl_list(MsgInfo *msginfo)
                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 {
@@ -134,9 +140,10 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
        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");
@@ -144,6 +151,9 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
        }
        tinfo = procheader_parse_file(filename, msginfo->flags, TRUE, TRUE);
 
+       sanitized_uid = g_strdup(tinfo->account_login);
+       subst_for_filename(sanitized_uid);
+
        if (!tinfo->account_server
        ||  !tinfo->account_login
        ||  !tinfo->partial_recv) {
@@ -151,25 +161,29 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
        }
        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) {
+                          "-", 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) {
+               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) {
+                          "-", sanitized_uid, ".new", NULL);
+       
+       g_free(sanitized_uid);
+
+       if ((fpnew = g_fopen(pathnew, "wb")) == NULL) {
                perror("fopen2");
                fclose(fp);
                g_free(pathnew);
@@ -184,7 +198,7 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
                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 {
@@ -193,7 +207,7 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
                }
                if (strcmp(tinfo->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) {
@@ -209,7 +223,7 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
                                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);
                }
        }
@@ -221,12 +235,12 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
        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);
@@ -252,7 +266,7 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
        }
        fclose(fpnew);
        fclose(fp);
-       unlink(filename);
+       g_unlink(filename);
        rename(pathnew, filename);
        g_free(pathnew);
        msginfo->planned_download = download;
@@ -321,22 +335,27 @@ gchar *partial_get_filename(const gchar *server, const gchar *login,
        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);
@@ -347,7 +366,8 @@ gchar *partial_get_filename(const gchar *server, const gchar *login,
                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 {