aboutsummaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
Diffstat (limited to 'mail')
-rw-r--r--mail/ChangeLog15
-rw-r--r--mail/mail-callbacks.c32
-rw-r--r--mail/mail-ops.c98
3 files changed, 121 insertions, 24 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index 78e34c6da0..c4024ff622 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,3 +1,18 @@
+2000-12-08 Jeffrey Stedfast <fejj@helixcode.com>
+
+ * mail-callbacks.c (save_msg_ok): Check to see if the file already
+ exists, if it does prompt the user to for permission to overwrite
+ the file.
+ (forward_message): g_strdup the cursor_uid if there is only a
+ single message to be forwarded or we'll segfault later.
+
+ * mail-ops.c (do_save_messages): Rewrote yet again. I'm back to
+ almost an identical implementation as the first time I wrote this
+ except now we write the From line which I had forgotten last
+ time. This means that we no longer have to unlink the .ev-summary
+ file created and we also use fewer resources (no need to create a
+ CamelMboxFolder object).
+
2000-12-08 JP Rosevear <jpr@helixcode.com>
* folder-browser.c (on_double_click): the e-table double-click
diff --git a/mail/mail-callbacks.c b/mail/mail-callbacks.c
index ac35067caf..9432ce3ce7 100644
--- a/mail/mail-callbacks.c
+++ b/mail/mail-callbacks.c
@@ -500,7 +500,7 @@ forward_message (FolderBrowser *fb, gboolean attach)
if (attach)
message_list_foreach (fb->message_list, enumerate_msg, uids);
else
- g_ptr_array_add (uids, fb->message_list->cursor_uid);
+ g_ptr_array_add (uids, g_strdup (fb->message_list->cursor_uid));
gtk_signal_connect (GTK_OBJECT (composer), "send",
GTK_SIGNAL_FUNC (composer_send_cb), NULL);
@@ -679,14 +679,36 @@ save_msg_ok (GtkWidget *widget, gpointer user_data)
CamelFolder *folder;
GPtrArray *uids;
char *path;
+ int fd, ret = 0;
/* FIXME: is path an allocated string? */
path = gtk_file_selection_get_filename (GTK_FILE_SELECTION (user_data));
- folder = gtk_object_get_data (GTK_OBJECT (user_data), "folder");
- uids = gtk_object_get_data (GTK_OBJECT (user_data), "uids");
- gtk_object_remove_no_notify (GTK_OBJECT (user_data), "uids");
- mail_do_save_messages (folder, uids, path);
+ fd = open (path, O_RDONLY);
+ if (fd != -1) {
+ GtkWidget *dlg;
+ GtkWidget *text;
+
+ close (fd);
+
+ dlg = gnome_dialog_new (_("Overwrite file?"),
+ GNOME_STOCK_BUTTON_YES,
+ GNOME_STOCK_BUTTON_NO,
+ NULL);
+ text = gtk_label_new (_("A file by that name already exists.\nOverwrite it?"));
+ gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dlg)->vbox), text, TRUE, TRUE, 4);
+ gtk_window_set_policy (GTK_WINDOW (dlg), FALSE, TRUE, FALSE);
+ gtk_widget_show (text);
+
+ ret = gnome_dialog_run_and_close (GNOME_DIALOG (dlg));
+ }
+
+ if (ret == 0) {
+ folder = gtk_object_get_data (GTK_OBJECT (user_data), "folder");
+ uids = gtk_object_get_data (GTK_OBJECT (user_data), "uids");
+ gtk_object_remove_no_notify (GTK_OBJECT (user_data), "uids");
+ mail_do_save_messages (folder, uids, path);
+ }
gtk_widget_destroy (GTK_WIDGET (user_data));
}
diff --git a/mail/mail-ops.c b/mail/mail-ops.c
index dd2ad8040a..0f03fe10ba 100644
--- a/mail/mail-ops.c
+++ b/mail/mail-ops.c
@@ -28,6 +28,7 @@
#include <config.h>
#include <gnome.h>
#include <ctype.h>
+#include <camel/camel-mime-filter-from.h>
#include "mail.h"
#include "mail-threads.h"
#include "mail-tools.h"
@@ -2441,24 +2442,25 @@ static void
do_save_messages (gpointer in_data, gpointer op_data, CamelException *ex)
{
save_messages_input_t *input = (save_messages_input_t *) in_data;
- CamelFolder *dest_folder;
+ CamelStreamFilter *filtered_stream;
+ CamelMimeFilterFrom *from_filter;
+ CamelStream *stream;
time_t last_update = 0;
- char *dir, *name, *url;
- int i;
-
- name = g_basename (input->path);
- dir = g_dirname (input->path);
- url = g_strdup_printf ("mbox://%s", dir);
- g_free (dir);
- dest_folder = mail_tool_get_folder_from_urlname (url, name, CAMEL_STORE_FOLDER_CREATE, ex);
- g_free (url);
+ int fd, fid, i;
- if (camel_exception_is_set (ex))
+ fd = open (input->path, O_WRONLY | O_CREAT | O_TRUNC, 0600);
+ if (fd == -1)
return;
mail_tool_camel_lock_up ();
+ stream = camel_stream_fs_new_with_fd (fd);
+ from_filter = camel_mime_filter_from_new ();
+ filtered_stream = camel_stream_filter_new_with_stream (stream);
+ fid = camel_stream_filter_add (filtered_stream, CAMEL_MIME_FILTER (from_filter));
+
for (i = 0; i < input->uids->len; i++) {
+ CamelMimeMessage *message;
const gboolean last_message = (i+1 == input->uids->len);
time_t now;
@@ -2472,21 +2474,79 @@ do_save_messages (gpointer in_data, gpointer op_data, CamelException *ex)
last_update = now;
}
- camel_folder_copy_message_to (input->folder, input->uids->pdata[i], dest_folder, NULL);
-
+ message = camel_folder_get_message (input->folder, input->uids->pdata[i], ex);
g_free (input->uids->pdata[i]);
+ if (message && !camel_exception_is_set (ex)) {
+ struct _header_address *addr = NULL;
+ struct _header_raw *headers;
+ const char *sender, *str;
+ char *date_str;
+ time_t date;
+ int offset;
+
+ /* first we must write the "From " line */
+ camel_stream_write (stream, "From ", 5);
+ headers = CAMEL_MIME_PART (message)->headers;
+
+ /* try to use the sender header */
+ sender = header_raw_find (&headers, "Sender", NULL);
+ if (!sender) {
+ /* okay, try the field */
+ sender = header_raw_find (&headers, "From", NULL);
+ addr = header_address_decode (sender);
+ sender = NULL;
+ if (addr) {
+ if (addr->type == HEADER_ADDRESS_NAME)
+ sender = addr->v.addr;
+ else
+ sender = NULL;
+ }
+
+ if (!sender)
+ sender = "unknown@nodomain.com";
+ }
+ for ( ; *sender && isspace ((unsigned char) *sender); sender++);
+ camel_stream_write (stream, sender, strlen (sender));
+ if (addr)
+ header_address_unref (addr);
+
+ /* try to use the received header to get the date */
+ str = header_raw_find (&headers, "Received", NULL);
+ if (str) {
+ str = strrchr (str, ';');
+ if (str)
+ str++;
+ }
+
+ /* if there isn't one, try the Date field */
+ if (!str)
+ str = header_raw_find (&headers, "Date", NULL);
+
+ date = header_decode_date (str, &offset);
+ date += ((offset / 100) * (60 * 60)) + (offset % 100) * 60;
+
+ date_str = header_format_date (date, offset);
+ camel_stream_printf (stream, " %s\n", date_str);
+ g_free (date_str);
+
+ /* now write the message data */
+ camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), CAMEL_STREAM (filtered_stream));
+ camel_object_unref (CAMEL_OBJECT (message));
+ } else {
+ break;
+ }
}
+ camel_stream_flush (CAMEL_STREAM (filtered_stream));
+
g_ptr_array_free (input->uids, TRUE);
- camel_object_unref (CAMEL_OBJECT (dest_folder));
+ camel_stream_filter_remove (filtered_stream, fid);
+ camel_object_unref (CAMEL_OBJECT (from_filter));
+ camel_object_unref (CAMEL_OBJECT (filtered_stream));
+ camel_object_unref (CAMEL_OBJECT (stream));
mail_tool_camel_lock_down ();
-
- /* FIXME: temp hack: now to remove the summary file */
- name = g_strdup_printf ("%s.ev-summary", input->path);
- unlink (name);
- g_free (name);
}
static void