msghdrviewoverlay.js

来自「现在很火的邮件客户端软件thunderbird的源码」· JavaScript 代码 · 共 1,653 行 · 第 1/5 页

JS
1,653
字号
function ClearAttachmentMenu(popup) {   if ( popup )   {      while ( popup.childNodes[0].localName == 'menu' )       popup.removeChild(popup.childNodes[0]);   } }// Public method used to determine the number of attachments for the currently displayed message...function GetNumberOfAttachmentsForDisplayedMessage(){  return currentAttachments.length;}// private method used to build up a menu list of attachmentsfunction addAttachmentToPopup(popup, attachment, attachmentIndex) {   if (popup)  {     var item = document.createElement('menu');    if ( item )     {           if (!gMessengerBundle)        gMessengerBundle = document.getElementById("bundle_messenger");      // insert the item just before the separator...the separator is the 2nd to last element in the popup.      item.setAttribute('class', 'menu-iconic');      setApplicationIconForAttachment(attachment,item, false);            var numItemsInPopup = popup.childNodes.length;      // find the separator      var indexOfSeparator = 0;      while (popup.childNodes[indexOfSeparator].localName != 'menuseparator')        indexOfSeparator++;            var formattedDisplayNameString = gMessengerBundle.getFormattedString("attachmentDisplayNameFormat",                                       [attachmentIndex, attachment.displayName]);      item.setAttribute('label', formattedDisplayNameString);       item.setAttribute('accesskey', attachmentIndex);       // each attachment in the list gets its own menupopup with options for saving, deleting, detaching, etc.       var openpopup = document.createElement('menupopup');       openpopup = item.appendChild(openpopup);      // Due to Bug #314228, we must append our menupopup to the new attachment menu item      // before we inserting the attachment menu into the popup. If we don't, our attachment      // menu items will not show up.      item = popup.insertBefore(item, popup.childNodes[indexOfSeparator]);      var menuitementry = document.createElement('menuitem');      menuitementry.attachment = cloneAttachment(attachment);      menuitementry.setAttribute('oncommand', 'openAttachment(this.attachment)');      if (!gSaveLabel)        gSaveLabel = gMessengerBundle.getString("saveLabel");      if (!gSaveLabelAccesskey)        gSaveLabelAccesskey = gMessengerBundle.getString("saveLabelAccesskey");      if (!gOpenLabel)        gOpenLabel = gMessengerBundle.getString("openLabel");      if (!gOpenLabelAccesskey)        gOpenLabelAccesskey = gMessengerBundle.getString("openLabelAccesskey");      if (!gDetachLabel)        gDetachLabel = gMessengerBundle.getString("detachLabel");      if (!gDetachLabelAccesskey)        gDetachLabelAccesskey = gMessengerBundle.getString("detachLabelAccesskey");      if (!gDeleteLabel)        gDeleteLabel = gMessengerBundle.getString("deleteLabel");      if (!gDeleteLabelAccesskey)        gDeleteLabelAccesskey = gMessengerBundle.getString("deleteLabelAccesskey");      // we should also check if an attachment has been detached...      // but that uses X-Mozilla-External-Attachment-URL, which      // we'd need to check for somehow.      var signedOrEncrypted = false;      if ("content-type" in currentHeaderData)      {        var contentType = currentHeaderData["content-type"].headerValue;        signedOrEncrypted = contentType.indexOf("application/x-pkcs7-mime") >= 0 ||             contentType.indexOf("application/x-pkcs7-signature") >= 0;      }      var canDetach = !(/news-message:/.test(attachment.uri)) &&           !signedOrEncrypted &&          (!(/imap-message/.test(attachment.uri)) || MailOfflineMgr.isOnline());      menuitementry.setAttribute('label', gOpenLabel);       menuitementry.setAttribute('accesskey', gOpenLabelAccesskey);       menuitementry = openpopup.appendChild(menuitementry);      if (attachment.contentType == 'text/x-moz-deleted')        menuitementry.setAttribute('disabled', true);       var menuseparator = document.createElement('menuseparator');      openpopup.appendChild(menuseparator);            menuitementry = document.createElement('menuitem');      menuitementry.attachment = cloneAttachment(attachment);      menuitementry.setAttribute('oncommand', 'saveAttachment(this.attachment)');       menuitementry.setAttribute('label', gSaveLabel);       menuitementry.setAttribute('accesskey', gSaveLabelAccesskey);       if (attachment.contentType == 'text/x-moz-deleted')        menuitementry.setAttribute('disabled', true);       menuitementry = openpopup.appendChild(menuitementry);      var menuseparator = document.createElement('menuseparator');      openpopup.appendChild(menuseparator);      menuitementry = document.createElement('menuitem');      menuitementry.attachment = cloneAttachment(attachment);      menuitementry.setAttribute('oncommand', 'detachAttachment(this.attachment, true)');       menuitementry.setAttribute('label', gDetachLabel);       menuitementry.setAttribute('accesskey', gDetachLabelAccesskey);       if (attachment.contentType == 'text/x-moz-deleted' || !canDetach)        menuitementry.setAttribute('disabled', true);       menuitementry = openpopup.appendChild(menuitementry);      menuitementry = document.createElement('menuitem');      menuitementry.attachment = cloneAttachment(attachment);      menuitementry.setAttribute('oncommand', 'detachAttachment(this.attachment, false)');       menuitementry.setAttribute('label', gDeleteLabel);       menuitementry.setAttribute('accesskey', gDeleteLabelAccesskey);       if (attachment.contentType == 'text/x-moz-deleted' || !canDetach)        menuitementry.setAttribute('disabled', true);       menuitementry = openpopup.appendChild(menuitementry);    }  // if we created a menu item for this attachment...  } // if we have a popup} function HandleAllAttachments(action){ try  {   // convert our attachment data into some c++ friendly structs   var attachmentContentTypeArray = new Array();   var attachmentUrlArray = new Array();   var attachmentDisplayNameArray = new Array();   var attachmentMessageUriArray = new Array();   // populate these arrays..   var actionIndex = 0;   for (index in currentAttachments)   {     // exclude all attachments already deleted     var attachment = currentAttachments[index];     if ( attachment.contentType != 'text/x-moz-deleted' )     {       attachmentContentTypeArray[actionIndex] = attachment.contentType;       attachmentUrlArray[actionIndex] = attachment.url;       attachmentDisplayNameArray[actionIndex] = encodeURI(attachment.displayName);       attachmentMessageUriArray[actionIndex] = attachment.uri;       ++actionIndex;     }   }   // okay the list has been built... now call our action code...   if ( action == 'save' )     messenger.saveAllAttachments(attachmentContentTypeArray.length,                                  attachmentContentTypeArray, attachmentUrlArray,                                  attachmentDisplayNameArray, attachmentMessageUriArray);   else if ( action == 'detach' )     messenger.detachAllAttachments(attachmentContentTypeArray.length,                                    attachmentContentTypeArray, attachmentUrlArray,                                    attachmentDisplayNameArray, attachmentMessageUriArray,                                    true); // save   else if ( action == 'delete' )     messenger.detachAllAttachments(attachmentContentTypeArray.length,                                    attachmentContentTypeArray, attachmentUrlArray,                                    attachmentDisplayNameArray, attachmentMessageUriArray,                                    false); // don't save   else     dump ("** unknown HandleAllAttachments action: " + action + "**\n");   }   catch (ex)   {   dump ("** failed to handle all attachments **\n");   }}function ClearAttachmentList() {   // we also have to disable the File/Attachments menuitem  node = document.getElementById("fileAttachmentMenu");  if (node)    node.setAttribute("disabled", "true");  // clear selection  var list = document.getElementById('attachmentList');  while (list.hasChildNodes())     list.removeChild(list.lastChild);}function ShowEditMessageButton() {  // it would be nice if we passed in the msgHdr from the back end  var msgHdr;  try  {    msgHdr = gDBView.hdrForFirstSelectedMessage;  }  catch (ex)  {    return;  }  if (IsSpecialFolder(msgHdr.folder, MSG_FOLDER_FLAG_DRAFTS, true))    document.getElementById("editMessageBox").collapsed = false;} function ClearEditMessageButton() {   var editBox = document.getElementById("editMessageBox");  if (editBox)    editBox.collapsed = true;}// CopyWebsiteAddress takes the website address title button, extracts// the website address we stored in there and copies it to the clipboardfunction CopyWebsiteAddress(websiteAddressNode){  if (websiteAddressNode)  {    var websiteAddress = websiteAddressNode.getAttribute("value");    var contractid = "@mozilla.org/widget/clipboardhelper;1";    var iid = Components.interfaces.nsIClipboardHelper;    var clipboard = Components.classes[contractid].getService(iid);    clipboard.copyString(websiteAddress);  }}var attachmentAreaDNDObserver = {  onDragStart: function (aEvent, aAttachmentData, aDragAction)  {    var target = aEvent.target;    if (target.localName == "descriptionitem")    {      var attachmentUrl = target.getAttribute("attachmentUrl");      var attachmentDisplayName = target.getAttribute("label");      var attachmentContentType = target.getAttribute("attachmentContentType");      var tmpurl = attachmentUrl;      var tmpurlWithExtraInfo = tmpurl + "&type=" + attachmentContentType + "&filename=" + attachmentDisplayName;      aAttachmentData.data = new TransferData();      if (attachmentUrl && attachmentDisplayName)      {        aAttachmentData.data.addDataForFlavour("text/x-moz-url", tmpurlWithExtraInfo + "\n" + attachmentDisplayName);        aAttachmentData.data.addDataForFlavour("text/x-moz-url-data", tmpurl);        aAttachmentData.data.addDataForFlavour("text/x-moz-url-desc", attachmentDisplayName);                aAttachmentData.data.addDataForFlavour("application/x-moz-file-promise-url", tmpurl);           aAttachmentData.data.addDataForFlavour("application/x-moz-file-promise", new nsFlavorDataProvider(), 0, Components.interfaces.nsISupports);        }    }  }};function nsFlavorDataProvider(){}nsFlavorDataProvider.prototype ={  QueryInterface : function(iid)  {      if (iid.equals(Components.interfaces.nsIFlavorDataProvider) ||          iid.equals(Components.interfaces.nsISupports))        return this;      throw Components.results.NS_NOINTERFACE;  },    getFlavorData : function(aTransferable, aFlavor, aData, aDataLen)  {    // get the url for the attachment    if (aFlavor == "application/x-moz-file-promise")    {      var urlPrimitive = { };      var dataSize = { };      aTransferable.getTransferData("application/x-moz-file-promise-url", urlPrimitive, dataSize);      var srcUrlPrimitive = urlPrimitive.value.QueryInterface(Components.interfaces.nsISupportsString);      // now get the destination file location from kFilePromiseDirectoryMime      var dirPrimitive = {};      aTransferable.getTransferData("application/x-moz-file-promise-dir", dirPrimitive, dataSize);      var destDirectory = dirPrimitive.value.QueryInterface(Components.interfaces.nsILocalFile);      // now save the attachment to the specified location      // XXX: we need more information than just the attachment url to save it, fortunately, we have an array      // of all the current attachments so we can cheat and scan through them      var attachment = null;      for (index in currentAttachments)      {        attachment = currentAttachments[index];        if (attachment.url == srcUrlPrimitive)          break;      }      // call our code for saving attachments      if (attachment)      {        var destFilePath = messenger.saveAttachmentToFolder(attachment.contentType, attachment.url, encodeURIComponent(attachment.displayName), attachment.uri, destDirectory);        aData.value = destFilePath.QueryInterface(Components.interfaces.nsISupports);        aDataLen.value = 4;      }    }  }}function nsDummyMsgHeader(){}nsDummyMsgHeader.prototype ={  mProperties : new Array,  getStringProperty : function(property) {return this.mProperties[property];},  setStringProperty : function(property, val) {this.mProperties[property] = val;},  messageSize : 0,  recipients : null,  from : null,  subject : null,  ccList : null,  messageId : null,  accountKey : "",  folder : null};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?