Re: .signature without newline bug
* Thu Sep 29 2005 TAKAHASHI Tamotsu <ttakah@xxxxxxxxxxxxxxxxx>
> * Thu Sep 29 2005 Mads Martin Joergensen <mmj@xxxxxxx>
>
> > Make a .signature without a newline in the end.
> >
> > Press reply to a given mail.
> > Quit the editor without saving anything.
> > Mutt thinks the mail have changed. <---- bug
> >
> > If there's a newline at the end of the signature, quitting the editor
> > without saving changes makes mutt abort unmodified message.
>
> Ah, because of fix_end_of_file() in curs_lib.c.
> fix_end_of_file() is used by mutt_edit_file().
> Hmm, maybe fix_end_of_file() should check mtime??
> Or make an option $fix_eof for you?
> Otherwise, it's feature.
Here is a patch to move fix_end_of_file from curs_lib.c to send.c,
and to check mtime before the call.
--
tamo
Index: curs_lib.c
===================================================================
RCS file: /home/roessler/cvs/mutt/curs_lib.c,v
retrieving revision 3.23
diff -p -u -r3.23 curs_lib.c
--- curs_lib.c 17 Sep 2005 20:46:10 -0000 3.23
+++ curs_lib.c 2 Oct 2005 13:38:49 -0000
@@ -156,19 +156,6 @@ void mutt_clear_error (void)
CLEARLINE (LINES-1);
}
-static void fix_end_of_file (const char *data)
-{
- FILE *fp;
- int c;
-
- if ((fp = safe_fopen (data, "a+")) == NULL)
- return;
- fseek (fp,-1,SEEK_END);
- if ((c = fgetc(fp)) != '\n')
- fputc ('\n', fp);
- safe_fclose (&fp);
-}
-
void mutt_edit_file (const char *editor, const char *data)
{
char cmd[LONG_STRING];
@@ -177,7 +164,6 @@ void mutt_edit_file (const char *editor,
mutt_expand_file_fmt (cmd, sizeof (cmd), editor, data);
if (mutt_system (cmd) == -1)
mutt_error (_("Error running \"%s\"!"), cmd);
- fix_end_of_file (data);
keypad (stdscr, TRUE);
clearok (stdscr, TRUE);
}
Index: send.c
===================================================================
RCS file: /home/roessler/cvs/mutt/send.c,v
retrieving revision 3.43
diff -p -u -r3.43 send.c
--- send.c 22 Sep 2005 09:06:13 -0000 3.43
+++ send.c 2 Oct 2005 13:38:52 -0000
@@ -1033,6 +1033,19 @@ static void decode_descriptions (BODY *b
}
}
+static void fix_end_of_file (const char *data)
+{
+ FILE *fp;
+ int c;
+
+ if ((fp = safe_fopen (data, "a+")) == NULL)
+ return;
+ fseek (fp,-1,SEEK_END);
+ if ((c = fgetc(fp)) != '\n')
+ fputc ('\n', fp);
+ safe_fclose (&fp);
+}
+
int mutt_resend_message (FILE *fp, CONTEXT *ctx, HEADER *cur)
{
HEADER *msg = mutt_new_header ();
@@ -1393,7 +1406,16 @@ ci_send_message (int flags, /* send mod
mutt_env_to_idna (msg->env, NULL, NULL);
}
else
+ {
mutt_edit_file (Editor, msg->content->filename);
+ if (stat (msg->content->filename, &st) == 0)
+ {
+ if (mtime != st.st_mtime)
+ fix_end_of_file (msg->content->filename);
+ }
+ else
+ mutt_perror (msg->content->filename);
+ }
mutt_message_hook (NULL, msg, M_SEND2HOOK);
}