2005-07-01 [colin] 1.9.12cvs8
[claws.git] / src / pop.c
index f4a7f167a2291893319d92b91abb69173c72facc..51d9019c3b63c555a7dfbd26883d2e2a792398f4 100644 (file)
--- a/src/pop.c
+++ b/src/pop.c
@@ -22,6 +22,7 @@
 #endif
 
 #include <glib.h>
+#include <glib/gi18n.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdarg.h>
@@ -30,7 +31,6 @@
 #include <time.h>
 #include <errno.h>
 
-#include "intl.h"
 #include "pop.h"
 #include "md5.h"
 #include "prefs_account.h"
@@ -563,13 +563,18 @@ void pop3_get_uidl_table(PrefsAccount *ac_prefs, Pop3Session *session)
        time_t recv_time;
        time_t now;
        gint partial_recv;
+       gchar *sanitized_uid = g_strdup(ac_prefs->userid);
+       
+       subst_for_filename(sanitized_uid);
        
        table = g_hash_table_new(g_str_hash, g_str_equal);
        partial_recv_table = g_hash_table_new(g_str_hash, g_str_equal);
 
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                           "uidl", G_DIR_SEPARATOR_S, ac_prefs->recv_server,
-                          "-", ac_prefs->userid, NULL);
+                          "-", sanitized_uid, NULL);
+                          
+       g_free(sanitized_uid);
        if ((fp = fopen(path, "rb")) == NULL) {
                if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
                g_free(path);
@@ -633,13 +638,20 @@ gint pop3_write_uidl_list(Pop3Session *session)
        FILE *fp;
        Pop3MsgInfo *msg;
        gint n;
+       gchar *sanitized_uid = g_strdup(session->ac_prefs->userid);
+       
+       subst_for_filename(sanitized_uid);
+       
 
        if (!session->uidl_is_valid) return 0;
 
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                           "uidl", G_DIR_SEPARATOR_S,
                           session->ac_prefs->recv_server,
-                          "-", session->ac_prefs->userid, NULL);
+                          "-", sanitized_uid, NULL);
+       
+       g_free(sanitized_uid);
+
        if ((fp = fopen(path, "wb")) == NULL) {
                FILE_OP_ERROR(path, "fopen");
                g_free(path);
@@ -648,10 +660,10 @@ gint pop3_write_uidl_list(Pop3Session *session)
 
        for (n = 1; n <= session->count; n++) {
                msg = &session->msg[n];
-               if (msg->uidl && msg->received && !msg->deleted) {
+               if (msg->uidl && msg->received &&
+                   (!msg->deleted || session->state != POP3_DONE))
                        fprintf(fp, "%s\t%ld\t%d\n", 
                                msg->uidl, msg->recv_time, msg->partial_recv);
-               }
        }
 
        if (fclose(fp) == EOF) FILE_OP_ERROR(path, "fclose");
@@ -687,7 +699,7 @@ static gint pop3_write_msg_to_file(const gchar *file, const gchar *data,
        prev = data;
        while ((cur = (gchar *)my_memmem(prev, len - (prev - data), "\r\n", 2))
               != NULL) {
-               if ((cur > prev && fwrite(prev, cur - prev, 1, fp) < 1) ||
+               if ((cur > prev && fwrite(prev, 1, cur - prev, fp) < 1) ||
                    fputc('\n', fp) == EOF) {
                        FILE_OP_ERROR(file, "fwrite");
                        g_warning("can't write to file: %s\n", file);
@@ -714,7 +726,7 @@ static gint pop3_write_msg_to_file(const gchar *file, const gchar *data,
        }
 
        if (prev - data < len &&
-           fwrite(prev, len - (prev - data), 1, fp) < 1) {
+           fwrite(prev, 1, len - (prev - data), fp) < 1) {
                FILE_OP_ERROR(file, "fwrite");
                g_warning("can't write to file: %s\n", file);
                fclose(fp);
@@ -964,6 +976,7 @@ static gint pop3_session_recv_msg(Session *session, const gchar *msg)
                }
                break;
        case POP3_LOGOUT:
+               pop3_session->state = POP3_DONE;
                session_disconnect(session);
                break;
        case POP3_ERROR: