Bug 1595059 - Prevent copying an address book card without a UID, and fix copying cards from one book to another; r+a=mkmelin
Special thanks to Prettier for causing this.
--- a/mailnews/addrbook/content/abDragDrop.js
+++ b/mailnews/addrbook/content/abDragDrop.js
@@ -223,19 +223,23 @@ var abDirTreeObserver = {
// The data contains the a string of "selected rows", eg.: "1,2".
var rows = dataTransfer
.getData("moz/abcard")
.split(",")
.map(j => parseInt(j, 10));
for (var j = 0; j < rows.length; j++) {
- if (gAbView.getCardFromRow(rows[j]).isMailList) {
+ let card = gAbView.getCardFromRow(rows[j]);
+ if (!card.UID) {
+ Cu.reportError(new Error("Card must have a UID to be dropped here."));
+ return false;
+ }
+ if (card.isMailList) {
draggingMailList = true;
- break;
}
}
// The rest of the cases - allow cards for copy or move, but only allow
// move of mailing lists if we're not going into another mailing list.
if (
draggingMailList &&
(targetDirectory.isMailList ||
--- a/mailnews/addrbook/jsaddrbook/AddrBookDirectory.jsm
+++ b/mailnews/addrbook/jsaddrbook/AddrBookDirectory.jsm
@@ -812,20 +812,24 @@ AddrBookDirectoryInner.prototype = {
// notification should be fired for each one. Let the list handle that.
for (let list of this.childNodes) {
list.deleteCards(cards);
}
deleteCardStatement.finalize();
},
dropCard(card, needToCopyCard) {
+ if (!card.UID) {
+ throw new Error("Card must have a UID to be added to this directory.");
+ }
+
let newCard = new AddrBookCard();
newCard.directoryId = this.uuid;
newCard.localId = this._getNextCardId();
- newCard._uid = needToCopyCard || card.UID || newUID();
+ newCard._uid = needToCopyCard ? newUID() : card.UID;
let insertStatement = this._dbConnection.createStatement(
"INSERT INTO cards (uid, localId) VALUES (:uid, :localId)"
);
insertStatement.params.uid = newCard.UID;
insertStatement.params.localId = newCard.localId;
insertStatement.execute();
insertStatement.finalize();