2005-09-14 [paul] 1.9.14cvs26
[claws.git] / src / partial_download.c
index fb28994f4add5f48135c27184f80ebfea4fc21e5..23ee519e104033168ce965b83b0281b2e0a355e9 100644 (file)
@@ -84,13 +84,13 @@ 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,
                                   "-", sanitized_uid, NULL);
-               if ((fp = fopen(path, "rb")) == NULL) {
+               if ((fp = g_fopen(path, "rb")) == NULL) {
                        if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
                        g_free(sanitized_uid);
                        g_free(path);
@@ -108,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 {
@@ -141,10 +142,7 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
        int err = -1;
        gchar *filename;
        MsgInfo *tinfo;
-       gchar *sanitized_uid = g_strdup(tinfo->account_login);
-       
-       subst_for_filename(sanitized_uid);
-       
+       gchar *sanitized_uid = NULL;    
 
        filename = procmsg_get_message_file_path(msginfo);
        if (!filename) {
@@ -153,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) {
@@ -162,14 +163,14 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
                           "uidl", G_DIR_SEPARATOR_S, tinfo->account_server,
                           "-", sanitized_uid, NULL);
 
-       if ((fp = fopen(path, "rb")) == 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);
                }
@@ -182,7 +183,7 @@ static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
        
        g_free(sanitized_uid);
 
-       if ((fpnew = fopen(pathnew, "wb")) == NULL) {
+       if ((fpnew = g_fopen(pathnew, "wb")) == NULL) {
                perror("fopen2");
                fclose(fp);
                g_free(pathnew);
@@ -197,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 {
@@ -206,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) {
@@ -222,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);
                }
        }
@@ -234,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);
@@ -265,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;
@@ -341,13 +342,13 @@ gchar *partial_get_filename(const gchar *server, const gchar *login,
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                           "uidl", G_DIR_SEPARATOR_S, 
                           server, "-", sanitized_uid, 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-", server,
                                   "-", sanitized_uid, NULL);
-               if ((fp = fopen(path, "rb")) == NULL) {
+               if ((fp = g_fopen(path, "rb")) == NULL) {
                        if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
                        g_free(sanitized_uid);
                        g_free(path);
@@ -365,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 {