Browse Source

P4TB-391: Make attachment names unique in the message display.

master
Jörg Knobloch 1 year ago
parent
commit
4c369760f2
2 changed files with 44 additions and 3 deletions
  1. +1
    -0
      addon/content/pepmessengercompose.js
  2. +43
    -3
      addon/content/pepmsghdrview.js

+ 1
- 0
addon/content/pepmessengercompose.js View File

@ -370,6 +370,7 @@ var pEpComposer = {
}
} while (found);
attachmentNames[j] = newName;
let item = bucket.getItemAtIndex(j);
let originalName = item.attachment.name;
let itemLabel = item.querySelector(".attachmentcell-name");


+ 43
- 3
addon/content/pepmsghdrview.js View File

@ -308,10 +308,11 @@ var pEpHdrView = {
},
// Adapted from Enigmail.
hidePgpKeys() {
hidePgpKeysAndMakeAttachmentNamesUnique() {
let attachmentList = this.win.document.getElementById("attachmentList");
if (!attachmentList) return;
if (this.win.currentAttachments.length == 0) return;
let needRefresh = false;
// Remove attachments of type application/pgp-keys.
let attLength = this.win.currentAttachments.length;
@ -320,7 +321,46 @@ var pEpHdrView = {
this.win.currentAttachments.splice(i, 1);
}
}
if (attLength == this.win.currentAttachments.length) return;
if (attLength != this.win.currentAttachments.length) needRefresh = true;
// Make the names unique.
attLength = this.win.currentAttachments.length;
let attachmentNames = [];
for (let i = 0; i < attLength; i++) {
attachmentNames.push(this.win.currentAttachments[i].name);
}
for (let i = 0; i < attLength; i++) {
for (let j = i + 1; j < attLength; j++) {
if (attachmentNames[i] == attachmentNames[j]) {
let name = attachmentNames[i];
let dotPos = name.lastIndexOf(".");
let tryAppend = 1;
let newName;
let found;
do {
tryAppend++;
if (dotPos < 0) {
newName = `${name}(${tryAppend})`;
} else {
newName = `${name.substring(0, dotPos)}(${tryAppend})${name.substring(dotPos)}`;
}
found = false;
for (let k = 0; k < attLength; k++) {
if (newName == attachmentNames[k]) {
found = true;
break;
}
}
} while (found);
attachmentNames[j] = newName;
this.win.currentAttachments[j].name = newName;
needRefresh = true;
}
}
}
if (!needRefresh) return;
// Delete attachment display.
while (attachmentList.hasChildNodes()) {
@ -355,7 +395,7 @@ var pEpHdrView = {
return false;
};
this.hidePgpKeys();
this.hidePgpKeysAndMakeAttachmentNamesUnique();
// Update the privacy information and subject.
// Body and attachments are handled via the PGP MIME Proxy.


Loading…
Cancel
Save