Hello all,

So mutt allows the user to rename an attachment, but what this does
is to rename the underlying file. To me at least, this is 1) not
very useful, and 2) a violation of the principle of least
astonishment [1]. So I decided to have a look at the source code, to
see if would be too hard to change.

It wasn't, and indeed I was able to modify the source so it does
what I want it to: renaming an attachment just changed the
"filename" parameter that gets sent with the "Content-Disposition"
header; changes are attached (*).

One problem though: in the compose menu, I want to add, next to the
attached filename's path, the new filename in square brackets. But
for the life of me, I'm unable to discover where lies the code that
prints the attachment list! The "-- Attachments" line is printed in
compose.c:266, but the attachment list is still a mystery. Can
anyone shed some light?

As a final note, I remark that this is my first foray into mutt's
source. So while I hope not to have made any naïve mistakes, that
remains a possibility. In any case, constructive feedback is much
appreciated.

Thanks in advance,
---Óscar Pereira
(*) - Please disregard the changes in spacing/indentation, I
re-indented the source so I could read it more easily; before
submitting a final patch I will re-arrange it properly.

[1] - http://en.wikipedia.org/wiki/Principle_of_least_astonishment

diff -uw checkout/src/mutt/compose.c build/compose.c
--- checkout/src/mutt/compose.c	2014-08-05 21:14:50.456674259 +0100
+++ build/compose.c	2014-08-05 16:35:40.793467130 +0100
@@ -486,6 +486,7 @@
   char helpstr[LONG_STRING];
   char buf[LONG_STRING];
   char fname[_POSIX_PATH_MAX];
+	char *t;
   MUTTMENU *menu;
   ATTACHPTR **idx = NULL;
   short idxlen = 0;
@@ -996,8 +997,16 @@
       
       case OP_COMPOSE_RENAME_FILE:
 	CHECK_COUNT;
-	strfcpy (fname, idx[menu->current]->content->filename, sizeof (fname));
+
+				/* strfcpy (fname, idx[menu->current]->content->filename, sizeof (fname)); */
+				/* path is irrelevant when changing the name of files */
+				if ((t = strrchr (idx[menu->current]->content->filename, '/')))
+					t++;
+				else
+					t = idx[menu->current]->content->filename;
+				strfcpy (fname, t, sizeof (fname));
 	mutt_pretty_mailbox (fname, sizeof (fname));
+
 	if (mutt_get_field (_("Rename to: "), fname, sizeof (fname), M_FILE)
 							== 0 && fname[0])
 	{
@@ -1007,11 +1016,13 @@
 	    break;
 	  }
 
-	  mutt_expand_path (fname, sizeof (fname));
-	  if(mutt_rename_file (idx[menu->current]->content->filename, fname))
-	    break;
+					// XXX check the recv'd filename has no slashes...
+					/* mutt_expand_path (fname, sizeof (fname)); */
+					/* if(mutt_rename_file (idx[menu->current]->content->filename, fname)) */
+					/*   break; */
 	  
-	  mutt_str_replace (&idx[menu->current]->content->filename, fname);
+					/* mutt_str_replace (&idx[menu->current]->content->filename, fname); */
+					mutt_str_replace (&idx[menu->current]->content->d_filename, fname);
 	  menu->redraw = REDRAW_CURRENT;
 
 	  if(idx[menu->current]->content->stamp >= st.st_mtime)

Attachment: pgpOEozlTFbpy.pgp
Description: PGP signature

Reply via email to