Commit 9edbb96a authored by Brendan Cully's avatar Brendan Cully

Ensure alias file ends with \n before appending new aliases.

Closes #1580.
parent fa9fc104
2008-05-14 15:19 +0200 Samuel Tardieu <[email protected]> (5518355bc6da)
* curs_main.c: Always update status bar after sorting method changes
(closes #2120).
2008-05-12 23:15 -0700 Brendan Cully <[email protected]> (97aa20438c47)
* imap/imap.c: Terminate open IMAP message sets at end of mailbox
even if the last message is inactive. Closes #3002.
2008-05-11 10:52 +0200 Matthias Andree <[email protected]> (09b0363cdf54)
* rfc3676.c: In debug output, cast size_t arguments to long for
......
......@@ -331,8 +331,26 @@ retry_name:
if (mutt_get_field (_("Save to file: "), buf, sizeof (buf), M_FILE) != 0)
return;
mutt_expand_path (buf, sizeof (buf));
if ((rc = fopen (buf, "a")))
if ((rc = fopen (buf, "a+")))
{
/* terminate existing file with \n if necessary */
if (fseek (rc, 0, SEEK_END))
goto fseek_err;
if (ftell(rc) > 0)
{
if (fseek (rc, -1, SEEK_CUR) < 0)
goto fseek_err;
if (fread(buf, 1, 1, rc) < 0)
{
mutt_perror (_("Error reading alias file"));
return;
}
if (fseek (rc, 0, SEEK_END) < 0)
goto fseek_err;
if (buf[0] != '\n')
fputc ('\n', rc);
}
if (mutt_check_alias_name (new->name, NULL))
mutt_quote_filename (buf, sizeof (buf), new->name);
else
......@@ -347,6 +365,13 @@ retry_name:
}
else
mutt_perror (buf);
return;
fseek_err:
mutt_perror (_("Error seeking in alias file"));
fclose(rc);
return;
}
/*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment