Andreas Krennmair:
authorak1 <ak1@e385b8ad-14ed-0310-8656-cc95a2468c6d>
Thu, 3 Feb 2005 19:52:19 +0000 (19:52 +0000)
committerak1 <ak1@e385b8ad-14ed-0310-8656-cc95a2468c6d>
Thu, 3 Feb 2005 19:52:19 +0000 (19:52 +0000)
fix stupid bug regarding saving attachments
applied ajg.last-folder patch

git-svn-id: svn://svn.berlios.de/mutt-ng/trunk@48 e385b8ad-14ed-0310-8656-cc95a2468c6d

ChangeLog.mutt-ng
attach.c
enter.c
recvattach.c

index 16a5c6f..e6e70c4 100644 (file)
@@ -1,5 +1,9 @@
 Changes specific to mutt-ng:
 
 Changes specific to mutt-ng:
 
+2005-02-03:
+  * Fixed stupid bug regarding saving attachments
+  * applied ajg.last-folder patch
+
 2005-02-02
   * little change to prevent segfaults on ia64; see #285001 in debian bts for
     more information
 2005-02-02
   * little change to prevent segfaults on ia64; see #285001 in debian bts for
     more information
index a49749b..d4a3ced 100644 (file)
--- a/attach.c
+++ b/attach.c
@@ -729,8 +729,11 @@ mutt_save_attachment_open (char *path, int flags)
 {
   if (flags == M_SAVE_APPEND)
     return fopen (path, "a");
 {
   if (flags == M_SAVE_APPEND)
     return fopen (path, "a");
+    /* be sure not to change the following fopen to safe_fopen
+     * as safe_fopen returns w/ an error if path exists
+     */
   if (flags == M_SAVE_OVERWRITE)
   if (flags == M_SAVE_OVERWRITE)
-    return safe_fopen (path, "w");             /* __FOPEN_CHECKED__ */
+    return fopen (path, "w");          /* __FOPEN_CHECKED__ */
   
   return safe_fopen (path, "w");
 }
   
   return safe_fopen (path, "w");
 }
diff --git a/enter.c b/enter.c
index 356ab21..afc23f6 100644 (file)
--- a/enter.c
+++ b/enter.c
@@ -614,6 +614,12 @@ self_insert:
       /* use the raw keypress */
       ch = LastKey;
 
       /* use the raw keypress */
       ch = LastKey;
 
+      if ((ch == '.') && (flags & (M_FILE | M_EFILE)))
+      {
+        rv = 2;
+        goto bye;
+      }
+      
 #ifdef KEY_ENTER
       /* treat ENTER the same as RETURN */
       if (ch == KEY_ENTER)
 #ifdef KEY_ENTER
       /* treat ENTER the same as RETURN */
       if (ch == KEY_ENTER)
index 4988067..3375b99 100644 (file)
@@ -38,6 +38,7 @@
 #include <errno.h>
 
 static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
 #include <errno.h>
 
 static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
+static char LastSaveFolder[_POSIX_PATH_MAX] = "";
 
 #define CHECK_READONLY if (Context->readonly) \
 {\
 
 #define CHECK_READONLY if (Context->readonly) \
 {\
@@ -55,6 +56,29 @@ static struct mapping_t AttachHelp[] = {
   { NULL }
 };
 
   { NULL }
 };
 
+int mutt_extract_path(char *filename, char *path)
+{
+  char *tmp=safe_malloc(sizeof(char) * _POSIX_PATH_MAX);
+  char *help_ptr;
+  
+  help_ptr = tmp;
+
+  while(*filename != '\0')
+  {
+    if (*filename == '/')
+    {
+      *help_ptr++=*filename++;
+      *help_ptr++='\0';
+      strcat(path, tmp);
+      help_ptr = tmp;
+    }
+    *help_ptr++=*filename++;
+  }
+  safe_free((void **) &tmp);
+    
+  return 0;
+}
+
 void mutt_update_tree (ATTACHPTR **idx, short idxlen)
 {
   char buf[STRING];
 void mutt_update_tree (ATTACHPTR **idx, short idxlen)
 {
   char buf[STRING];
@@ -368,9 +392,11 @@ static int mutt_query_save_attachment (FILE *fp, BODY *body, HEADER *hdr, char *
 {
   char *prompt;
   char buf[_POSIX_PATH_MAX], tfile[_POSIX_PATH_MAX];
 {
   char *prompt;
   char buf[_POSIX_PATH_MAX], tfile[_POSIX_PATH_MAX];
+  char path[_POSIX_PATH_MAX]="";  
   int is_message;
   int append = 0;
   int rc;
   int is_message;
   int append = 0;
   int rc;
+  int ret = -1;
   
   if (body->filename) 
   {
   
   if (body->filename) 
   {
@@ -387,12 +413,27 @@ static int mutt_query_save_attachment (FILE *fp, BODY *body, HEADER *hdr, char *
   else
     buf[0] = 0;
 
   else
     buf[0] = 0;
 
-  prompt = _("Save to file: ");
+  prompt = _("Save to file ('.' for last used folder): ");
   while (prompt)
   {
   while (prompt)
   {
-    if (mutt_get_field (prompt, buf, sizeof (buf), M_FILE | M_CLEAR) != 0
-       || !buf[0])
+    ret = mutt_get_field (prompt, buf, sizeof (buf), M_FILE | M_CLEAR);
+    if (((ret != 0) && (ret != 2)) || (!buf[0]))
+      return -1;
+
+    if (ret == 2)
+    {
+      strfcpy (buf, LastSaveFolder, sizeof (buf));
+      strcat(buf,body->filename);
+      ret = mutt_get_field (_("Save to file: ")
+                , buf, sizeof (buf), M_FILE | M_CLEAR);
+      if ((ret != 0) || (!buf[0]))
       return -1;
       return -1;
+    }  
+    else
+    {
+      mutt_extract_path(buf,path);
+      strfcpy (LastSaveFolder, path, sizeof (LastSaveFolder));
+    }
     
     prompt = NULL;
     mutt_expand_path (buf, sizeof (buf));
     
     prompt = NULL;
     mutt_expand_path (buf, sizeof (buf));