msghdrviewoverlay.js

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

JS
1,653
字号
    window.openDialog("chrome://messenger/content/addressbook/abNewCardDialog.xul",                      "",                      "chrome,resizable=no,titlebar,modal,centerscreen",                       {primaryEmail:primaryEmail, displayName:displayName });  }}// SendMailToNode takes the email address title button, extracts// the email address we stored in there and opens a compose window// with that addressfunction SendMailToNode(emailAddressNode){  var fields = Components.classes["@mozilla.org/messengercompose/composefields;1"].createInstance(Components.interfaces.nsIMsgCompFields);  var params = Components.classes["@mozilla.org/messengercompose/composeparams;1"].createInstance(Components.interfaces.nsIMsgComposeParams);  if (emailAddressNode && fields && params)  {    fields.to = emailAddressNode.getAttribute("fullAddress");    params.type = Components.interfaces.nsIMsgCompType.New;    params.format = Components.interfaces.nsIMsgCompFormat.Default;    params.identity = accountManager.getFirstIdentityForServer(GetLoadedMsgFolder().server);    params.composeFields = fields;    msgComposeService.OpenComposeWindowWithParams(null, params);  }}// CopyEmailAddress takes the email address title button, extracts// the email address we stored in there and copies it to the clipboardfunction CopyEmailAddress(emailAddressNode){  if (emailAddressNode)  {    var emailAddress = emailAddressNode.getAttribute("emailAddress");    var contractid = "@mozilla.org/widget/clipboardhelper;1";    var iid = Components.interfaces.nsIClipboardHelper;    var clipboard = Components.classes[contractid].getService(iid);    clipboard.copyString(emailAddress);  }}// CreateFilter opens the Message Filters and Filter Rules dialogs.//The Filter Rules dialog has focus. The window is prefilled with filtername <email address>//Sender condition is selected and the value is prefilled <email address>function CreateFilter(emailAddressNode){  if (emailAddressNode)  {     var emailAddress = emailAddressNode.getAttribute("emailAddress");     if (emailAddress){         top.MsgFilters(emailAddress, GetFirstSelectedMsgFolder());     }  }}// createnewAttachmentInfo --> constructor method for creating new attachment object which goes into the// data attachment array.function createNewAttachmentInfo(contentType, url, displayName, uri, isExternalAttachment){  this.contentType = contentType;  this.url = url;  this.displayName = displayName;  this.uri = uri;  this.isExternalAttachment = isExternalAttachment;}function dofunc(aFunctionName, aFunctionArg){  if (aFunctionName == "saveAttachment")     saveAttachment(aFunctionArg);   else if (aFunctionName == "openAttachment")     openAttachment(aFunctionArg);   else if (aFunctionName == "printAttachment")     printAttachment(aFunctionArg);  else if (aFunctionName == "deleteAttachment")    detachAttachment(aFunctionArg, false);  else if (aFunctionName == "detachAttachment")    detachAttachment(aFunctionArg, true);}function saveAttachment(aAttachment){  messenger.saveAttachment(aAttachment.contentType,                            aAttachment.url,                            encodeURIComponent(aAttachment.displayName),                            aAttachment.messageUri, aAttachment.isExternalAttachment);}function openAttachment(aAttachment){  messenger.openAttachment(aAttachment.contentType,                            aAttachment.url,                            encodeURIComponent(aAttachment.displayName),                            aAttachment.messageUri, aAttachment.isExternalAttachment);}function printAttachment(aAttachment){  /* we haven't implemented the ability to print attachments yet...  messenger.printAttachment(aAttachment.contentType,                             aAttachment.url,                             encodeURIComponent(aAttachment.displayName),                             aAttachment.messageUri);  */}function detachAttachment(aAttachment, aSaveFirst){  messenger.detachAttachment(aAttachment.contentType,                            aAttachment.url,                            encodeURIComponent(aAttachment.displayName),                            aAttachment.messageUri, aSaveFirst);}function CanDetachAttachments(){  var uri = GetLoadedMessage();  var canDetach = !IsNewsMessage(uri) && (!IsImapMessage(uri) || MailOfflineMgr.isOnline());  if (canDetach && ("content-type" in currentHeaderData))  {    var contentType = currentHeaderData["content-type"].headerValue;    canDetach = contentType.indexOf("application/x-pkcs7-mime") < 0 &&         contentType.indexOf("application/x-pkcs7-signature") < 0;  }  return canDetach;}function onShowAttachmentContextMenu(){  // if no attachments are selected, disable the Open and Save...  var attachmentList = document.getElementById('attachmentList');  var selectedAttachments = attachmentList.selectedItems;  var openMenu = document.getElementById('context-openAttachment');  var saveMenu = document.getElementById('context-saveAttachment');  var detachMenu = document.getElementById('context-detachAttachment');  var deleteMenu = document.getElementById('context-deleteAttachment');  var detachAllMenu = document.getElementById('context-detachAllAttachments');  var deleteAllMenu = document.getElementById('context-deleteAllAttachments');  var canDetach = CanDetachAttachments();  var canOpen = false;  for (var i = 0; i < selectedAttachments.length && !canOpen; i++)    canOpen = selectedAttachments[i].attachment.contentType != 'text/x-moz-deleted';  if (canOpen && selectedAttachments.length == 1)  {    openMenu.removeAttribute('disabled');  }  else  {    openMenu.setAttribute('disabled', true);  }  if (canOpen)  {    saveMenu.removeAttribute('disabled');  }  else  {    saveMenu.setAttribute('disabled', true);  }  if (canDetach && canOpen)  {    detachMenu.removeAttribute('disabled');    deleteMenu.removeAttribute('disabled');  }  else  {    detachMenu.setAttribute('disabled', 'true');    deleteMenu.setAttribute('disabled', 'true');  }  if (canDetach)  {    detachAllMenu.removeAttribute('disabled');    deleteAllMenu.removeAttribute('disabled');  }  else  {    detachAllMenu.setAttribute('disabled', 'true');    deleteAllMenu.setAttribute('disabled', 'true');  }}// this is our onclick handler for the attachment list. // A double click in a listitem simulates "opening" the attachment....function attachmentListClick(event){   // we only care about button 0 (left click) events  if (event.button != 0) return;  if (event.detail == 2) // double click  {    var target = event.target;    if (target.localName == "descriptionitem")    {      dofunc("openAttachment", target.attachment);    }  }}// on command handlers for the attachment list context menu...// commandPrefix matches one of our existing functions // (openAttachment, saveAttachment, etc.)function handleAttachmentSelection(commandPrefix){  var attachmentList = document.getElementById('attachmentList');  var selectedAttachments = attachmentList.selectedItems;  // loop over all of the selected attachments...  // XXX hack alert. If we sit in tight loop and call doFunc for multiple attachments,   // we get chrome errors in layout as we start loading the first helper app dialog  // then before it loads, we kick off the next one and the next one. Subsequent helper app dialogs  // were failing because we were still loading the chrome files for the first attempt (error about the xul cache  // being empty). For now, work around this by doing the first helper app dialog right away, then waiting a bit  // before we launch the rest.  for (var i = 0; i < selectedAttachments.length; i++)    if (!i)      dofunc(commandPrefix, selectedAttachments[i].attachment);    else      setTimeout(dofunc, 100, commandPrefix, selectedAttachments[i].attachment);}function cloneAttachment(aAttachment){  var obj = new Object();  obj.contentType = aAttachment.contentType;  obj.url = aAttachment.url;  obj.displayName = aAttachment.displayName;  obj.messageUri = aAttachment.uri;  obj.isExternalAttachment = aAttachment.isExternalAttachment;  return obj;}function displayAttachmentsForExpandedView(){  var numAttachments = currentAttachments.length;    // IMPORTANT: make sure we uncollapse the attachment box BEFORE we start adding  // our attachments to the view. Otherwise, layout doesn't calculate the correct height for  // the attachment view and we end up with a box that is too tall.  var expandedAttachmentBox = document.getElementById('attachmentView');  expandedAttachmentBox.collapsed = numAttachments <= 0;  if (numAttachments > 0 && !gBuildAttachmentsForCurrentMsg)  {    var attachmentList = document.getElementById('attachmentList');    for (index in currentAttachments)    {      var attachment = currentAttachments[index];      // create a new attachment widget. set the label, set the       // moz-icon img src      var attachmentView = attachmentList.appendItem(attachment.displayName);      attachmentView.setAttribute("class", "descriptionitem-iconic");       if (gShowLargeAttachmentView)      {        attachmentView.setAttribute("largeView", "true");        attachmentView.setAttribute("orient", "vertical");      }      setApplicationIconForAttachment(attachment, attachmentView, gShowLargeAttachmentView);      attachmentView.setAttribute("tooltip", "attachmentListTooltip");      attachmentView.setAttribute("context", "attachmentListContext");            attachmentView.attachment = cloneAttachment(attachment);      attachmentView.setAttribute("attachmentUrl", attachment.url);      attachmentView.setAttribute("attachmentContentType", attachment.contentType);      attachmentView.setAttribute("attachmentUri", attachment.uri);      var item = attachmentList.appendChild(attachmentView);    } // for each attachment    gBuildAttachmentsForCurrentMsg = true;  }}// attachment --> the attachment struct containing all the information on the attachment// listitem --> the listitem currently showing the attachment.function setApplicationIconForAttachment(attachment, listitem, largeView){  var iconSize = largeView ? kLargeIcon : kSmallIcon;  // generate a moz-icon url for the attachment so we'll show a nice icon next to it.  if ( attachment.contentType == 'text/x-moz-deleted' )    listitem.setAttribute('image', 'chrome://messenger/skin/icons/message-mail-attach-del.png');  else    listitem.setAttribute('image', "moz-icon:" + "//" + attachment.displayName + "?size=" + iconSize + "&contentType=" + attachment.contentType);}// Public method called to generate a tooltip over an attachmentfunction FillInAttachmentTooltip(cellNode){  var attachmentName = cellNode.getAttribute("label");  var tooltipNode = document.getElementById("attachmentListTooltip");  tooltipNode.setAttribute("label", attachmentName);  return true;}// Public method called when we create the attachments file menufunction FillAttachmentListPopup(popup){  // the FE sometimes call this routine TWICE...I haven't been able to figure out why yet...  // protect against it...  if (!gBuildAttachmentPopupForCurrentMsg) return;   var attachmentIndex = 0;  // otherwise we need to build the attachment view...  // First clear out the old view...  ClearAttachmentMenu(popup);  for (index in currentAttachments)  {    ++attachmentIndex;    addAttachmentToPopup(popup, currentAttachments[index], attachmentIndex);  }  gBuildAttachmentPopupForCurrentMsg = false;  var detachAllMenu = document.getElementById('file-detachAllAttachments');  var deleteAllMenu = document.getElementById('file-deleteAllAttachments');  if (CanDetachAttachments())  {    detachAllMenu.removeAttribute('disabled');    deleteAllMenu.removeAttribute('disabled');  }  else  {    detachAllMenu.setAttribute('disabled', 'true');    deleteAllMenu.setAttribute('disabled', 'true');  }}// Public method used to clear the file attachment menu

⌨️ 快捷键说明

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