When renaming attachment files, keep file extension if not provided

This commit is contained in:
Aurimas Vinckevicius 2013-11-22 17:39:02 -06:00 committed by aurimasv
parent 64fb9efa76
commit 59ef7cba04

View file

@ -388,15 +388,21 @@
// Rename associated file // Rename associated file
if (checkState.value) { if (checkState.value) {
var renamed = item.renameAttachmentFile(newTitle.value); var newFilename = newTitle.value.trim();
if (newFilename.search(/\.\w{1,10}$/) == -1) {
// User did not specify extension. Use current
var oldExt = item.getFilename().match(/\.\w{1,10}$/);
if (oldExt) newFilename += oldExt[0];
}
var renamed = item.renameAttachmentFile(newFilename);
if (renamed == -1) { if (renamed == -1) {
var confirmed = nsIPS.confirm( var confirmed = nsIPS.confirm(
window, window,
'', '',
newTitle.value + ' exists. Overwrite existing file?' newFilename + ' exists. Overwrite existing file?'
); );
if (confirmed) { if (confirmed) {
item.renameAttachmentFile(newTitle.value, true); item.renameAttachmentFile(newFilename, true);
break; break;
} }
// If they said not to overwrite existing file, // If they said not to overwrite existing file,