|
|
@ -186,6 +186,15 @@ var pEpComposer = { |
|
|
|
this.win.onRecipientsChanged = this.tb_onRecipientsChanged; |
|
|
|
if (this.tb_onAddressColCommand) this.win.onAddressColCommand = this.tb_onAddressColCommand; |
|
|
|
if (this.tb_awDeleteAddressOnClick) this.win.awDeleteAddressOnClick = this.tb_awDeleteAddressOnClick; |
|
|
|
|
|
|
|
let bucket; |
|
|
|
// This changed in https://bugzilla.mozilla.org/show_bug.cgi?id=1688331.
|
|
|
|
if (pEpController.MOZ_APP_VERSION >= 87) { |
|
|
|
bucket = this.win.gAttachmentBucket; |
|
|
|
} else { |
|
|
|
bucket = this.win.GetMsgAttachmentElement(); |
|
|
|
} |
|
|
|
if (bucket) bucket.removeEventListener("attachments-added", this); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
@ -317,6 +326,67 @@ var pEpComposer = { |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
handleEvent(event) { |
|
|
|
if (event.type != "attachments-added") return; |
|
|
|
let bucket; |
|
|
|
// This changed in https://bugzilla.mozilla.org/show_bug.cgi?id=1688331.
|
|
|
|
if (pEpController.MOZ_APP_VERSION >= 87) { |
|
|
|
bucket = this.win.gAttachmentBucket; |
|
|
|
} else { |
|
|
|
bucket = this.win.GetMsgAttachmentElement(); |
|
|
|
} |
|
|
|
if (bucket) { |
|
|
|
this.makeAttachmentNamesUnique(bucket); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
makeAttachmentNamesUnique(bucket) { |
|
|
|
let rowCount = bucket.getRowCount(); |
|
|
|
let attachmentNames = []; |
|
|
|
for (let i = 0; i < rowCount; i++) { |
|
|
|
attachmentNames.push(bucket.getItemAtIndex(i).attachment.name); |
|
|
|
} |
|
|
|
for (let i = 0; i < rowCount; i++) { |
|
|
|
for (let j = i + 1; j < rowCount; 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 < rowCount; k++) { |
|
|
|
if (newName == attachmentNames[k]) { |
|
|
|
found = true; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} while (found); |
|
|
|
|
|
|
|
let item = bucket.getItemAtIndex(j); |
|
|
|
let originalName = item.attachment.name; |
|
|
|
let itemLabel = item.querySelector(".attachmentcell-name"); |
|
|
|
item.attachment.name = newName; |
|
|
|
item.setAttribute("name", newName); |
|
|
|
itemLabel.setAttribute("value", newName); |
|
|
|
|
|
|
|
this.win.gContentChanged = true; |
|
|
|
|
|
|
|
let event = this.win.document.createEvent("CustomEvent"); |
|
|
|
event.initCustomEvent("attachment-renamed", true, true, originalName); |
|
|
|
item.dispatchEvent(event); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
initListener(event) { |
|
|
|
this.composeWindowInitHasRun = true; |
|
|
|
Services.obs.addObserver(this, "pEp-trust-changed"); |
|
|
@ -359,6 +429,10 @@ var pEpComposer = { |
|
|
|
this.win.updateAttachmentPane("hide"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Add a listener.
|
|
|
|
bucket.addEventListener("attachments-added", this); |
|
|
|
this.makeAttachmentNamesUnique(bucket); |
|
|
|
} |
|
|
|
|
|
|
|
// The user can disable protection.
|
|
|
|