2005-08-28 [colin] 1.9.13cvs67
[claws.git] / src / imap.c
index 0df9ae7bac0af7cdf13d17409bb603df40316010..cba08c2d03c831be7102a5c25f21d8a1dd1a5885 100644 (file)
@@ -855,6 +855,41 @@ static guint get_size_with_lfs(MsgInfo *info)
        return cnt;
 }
 
+static void strip_crs(const gchar *file) 
+{
+       FILE *fp = NULL, *outfp = NULL;
+       gchar buf[4096];
+       gchar *out = get_tmp_file();
+       if (file == NULL)
+               goto freeout;
+       
+       fp = fopen(file, "rb");
+       if (!fp)
+               goto freeout;
+
+       outfp = fopen(out, "wb");
+       if (!outfp) {
+               fclose(fp);
+               goto freeout;
+       }
+
+       while (fgets(buf, sizeof (buf), fp) != NULL) {
+               while (strstr(buf, "\r")) {
+                       gchar *cr = strstr(buf, "\r") ;
+                       *cr = '\n';
+                       cr++;
+                       *cr = '\0';
+               }
+               fputs(buf, outfp);
+       }
+       
+       fclose(fp);
+       fclose(outfp);
+       rename_force(out, file);
+freeout:
+       g_free(out);
+}
+
 static gchar *imap_fetch_msg_full(Folder *folder, FolderItem *item, gint uid,
                                  gboolean headers, gboolean body)
 {
@@ -890,6 +925,7 @@ static gchar *imap_fetch_msg_full(Folder *folder, FolderItem *item, gint uid,
                if (cached && (cached->size == have_size || !body)) {
                        procmsg_msginfo_free(cached);
                        procmsg_msginfo_free(msginfo);
+                       strip_crs(filename);
                        return filename;
                } else {
                        procmsg_msginfo_free(cached);
@@ -921,6 +957,7 @@ static gchar *imap_fetch_msg_full(Folder *folder, FolderItem *item, gint uid,
                return NULL;
        }
 
+       strip_crs(filename);
        return filename;
 }