msghdrviewoverlay.js

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

JS
1,653
字号
    onEndHeaders: function()     {      // WARNING: This is the ONLY routine inside of the message Header Sink that should       // trigger a reflow!      CheckNotify();            ClearHeaderView(gCollapsedHeaderView);      ClearHeaderView(gExpandedHeaderView);      EnsureSubjectValue(); // make sure there is a subject even if it's empty so we'll show the subject and the twisty            ShowMessageHeaderPane();      UpdateMessageHeaders();      ShowEditMessageButton();            for (index in gMessageListeners)        gMessageListeners[index].onEndHeaders();    },        processHeaders: function(headerNameEnumerator, headerValueEnumerator, dontCollectAddress)    {      this.onStartHeaders();       const kMailboxSeparator = ", ";      var index = 0;      while (headerNameEnumerator.hasMore())       {        var header = new Object;                header.headerValue = headerValueEnumerator.getNext();        header.headerName = headerNameEnumerator.getNext();        // for consistancy sake, let's force all header names to be lower case so        // we don't have to worry about looking for: Cc and CC, etc.        var lowerCaseHeaderName = header.headerName.toLowerCase();        // if we have an x-mailer or x-mimeole string, put it in the user-agent slot which we know how to handle        // already.         if (lowerCaseHeaderName == "x-mailer" || lowerCaseHeaderName == "x-mimeole")          lowerCaseHeaderName = "user-agent";           if (this.mDummyMsgHeader)        {          if (lowerCaseHeaderName == "from")            this.mDummyMsgHeader.author = header.headerValue;          else if (lowerCaseHeaderName == "to")            this.mDummyMsgHeader.recipients = header.headerValue;          else if (lowerCaseHeaderName == "cc")            this.mDummyMsgHeader.ccList = header.headerValue;          else if (lowerCaseHeaderName == "subject")            this.mDummyMsgHeader.subject = header.headerValue;          else if (lowerCaseHeaderName == "reply-to")            this.mDummyMsgHeader.replyTo = header.headerValue;          else if (lowerCaseHeaderName == "message-id")            this.mDummyMsgHeader.messageId = header.headerValue;        }        // according to RFC 2822, certain headers        // can occur "unlimited" times        if (lowerCaseHeaderName in currentHeaderData)        {          // sometimes, you can have multiple To or Cc lines....          // in this case, we want to append these headers into one.          if (lowerCaseHeaderName == 'to' || lowerCaseHeaderName == 'cc')            currentHeaderData[lowerCaseHeaderName].headerValue = currentHeaderData[lowerCaseHeaderName].headerValue + ',' + header.headerValue;          else {              // use the index to create a unique header name like:            // received5, received6, etc            currentHeaderData[lowerCaseHeaderName + index++] = header;          }        }        else         currentHeaderData[lowerCaseHeaderName] = header;      } // while we have more headers to parse      // process message tags as if they were headers in the message      SetTagHeader();            if (("from" in currentHeaderData) && ("sender" in currentHeaderData) && msgHeaderParser)      {        var senderMailbox = kMailboxSeparator + msgHeaderParser.extractHeaderAddressMailboxes(null,                            currentHeaderData.sender.headerValue) + kMailboxSeparator;        var fromMailboxes = kMailboxSeparator + msgHeaderParser.extractHeaderAddressMailboxes(null,                            currentHeaderData.from.headerValue) + kMailboxSeparator;        if (fromMailboxes.indexOf(senderMailbox) >= 0)          delete currentHeaderData.sender;      }      this.onEndHeaders();    },    handleAttachment: function(contentType, url, displayName, uri, isExternalAttachment)     {      // presentation level change....don't show vcards as external attachments in the UI.      // libmime already renders them inline.      try      {        if (!this.mSaveHdr)          this.mSaveHdr = messenger.messageServiceFromURI(uri).messageURIToMsgHdr(uri);      }      catch (ex) {}      if (contentType == "text/x-vcard")      {        var inlineAttachments = pref.getBoolPref("mail.inline_attachments");        var displayHtmlAs = pref.getIntPref("mailnews.display.html_as");        if (inlineAttachments && !displayHtmlAs)        {          return;        }      }      // display name optimization. Eliminate any large quantities of white space from the display name.      // such that Hello       World.txt becomes Hello World.txt.      var displayName = displayName.replace(/ +/g, " ");                currentAttachments.push (new createNewAttachmentInfo(contentType, url, displayName, uri, isExternalAttachment));      // if we have an attachment, set the MSG_FLAG_ATTACH flag on the hdr      // this will cause the "message with attachment" icon to show up      // in the thread pane      // we only need to do this on the first attachment      var numAttachments = currentAttachments.length;      if (numAttachments == 1) {        // we also have to enable the File/Attachments menuitem        var node = document.getElementById("fileAttachmentMenu");        if (node)          node.removeAttribute("disabled");        try {          // convert the uri into a hdr          this.mSaveHdr.markHasAttachments(true);        }        catch (ex) {          dump("ex = " + ex + "\n");        }      }    },        onEndAllAttachments: function()    {      displayAttachmentsForExpandedView();    },    onEndMsgDownload: function(url)    {      // if we don't have any attachments, turn off the attachments flag      if (!this.mSaveHdr)      {        var messageUrl = url.QueryInterface(Components.interfaces.nsIMsgMessageUrl);        try        {          this.mSaveHdr = messenger.msgHdrFromURI(messageUrl.uri);        }        catch (ex) {}      }      if (!currentAttachments.length && this.mSaveHdr)        this.mSaveHdr.markHasAttachments(false);      OnMsgParsed(url);    },    onEndMsgHeaders: function(url)    {       OnMsgLoaded(url);    },    onMsgHasRemoteContent: function(aMsgHdr)    {      gMessageNotificationBar.setRemoteContentMsg(aMsgHdr);    },    mSecurityInfo  : null,    mSaveHdr: null,    get securityInfo()    {      return this.mSecurityInfo;    },    set securityInfo(aSecurityInfo)    {      this.mSecurityInfo = aSecurityInfo;    },    mDummyMsgHeader: null,    getDummyMsgHeader: function()     {      if (!this.mDummyMsgHeader)        this.mDummyMsgHeader = new nsDummyMsgHeader();      return this.mDummyMsgHeader;    },    mProperties: null,    get properties()    {      if (!this.mProperties)        this.mProperties = Components.classes["@mozilla.org/hash-property-bag;1"].          createInstance(Components.interfaces.nsIWritablePropertyBag2);      return this.mProperties;    }};function SetTagHeader(){  // it would be nice if we passed in the msgHdr from the back end  var msgHdr;  try  {    msgHdr = gDBView.hdrForFirstSelectedMessage;  }  catch (ex)  {    return; // no msgHdr to add our tags to  }  // get the list of known tags  var tagService = Components.classes["@mozilla.org/messenger/tagservice;1"]                   .getService(Components.interfaces.nsIMsgTagService);  var tagArray = tagService.getAllTags({});  var tagKeys = {};  for each (var tagInfo in tagArray)    if (tagInfo.tag)      tagKeys[tagInfo.key] = true;  // extract the tag keys from the msgHdr  var msgKeyArray = msgHdr.getStringProperty("keywords").split(" ");  // attach legacy label to the front if not already there  var label = msgHdr.label;  if (label)  {    var labelKey = "$label" + label;    if (msgKeyArray.indexOf(labelKey) < 0)      msgKeyArray.unshift(labelKey);  } // Rebuild the keywords string with just the keys that are actual tags or  // legacy labels and not other keywords like Junk and NonJunk.  // Retain their order, though, with the label as oldest element.  for (var i = msgKeyArray.length - 1; i >= 0; --i)    if (!(msgKeyArray[i] in tagKeys))      msgKeyArray.splice(i, 1); // remove non-tag key  var msgKeys = msgKeyArray.join(" ");  if (msgKeys)    currentHeaderData.tags = {headerName: "tags", headerValue: msgKeys};  else // no more tags, so clear out the header field    delete currentHeaderData.tags;}function EnsureSubjectValue(){  if (!('subject' in currentHeaderData))  {    var foo = new Object;    foo.headerValue = "";    foo.headerName = 'subject';    currentHeaderData[foo.headerName] = foo;  } }function CheckNotify(){  if ("NotifyClearAddresses" in this)    NotifyClearAddresses();}function OnTagsChange(){  // rebuild the tag headers  SetTagHeader();  // now update the expanded header view to rebuild the tags,  // and then show or hide the tag header box.    if (gBuiltExpandedView)  {    var headerEntry = gExpandedHeaderView.tags;    if (headerEntry)    {      headerEntry.valid = ("tags" in currentHeaderData);      if (headerEntry.valid)        headerEntry.outputFunction(headerEntry, currentHeaderData.tags.headerValue);            // if we are showing the expanded header view then we may need to collapse or      // show the tag header box...      if (!gCollapsedHeaderViewMode)        headerEntry.enclosingBox.collapsed = !headerEntry.valid;    }  }}// flush out any local state being held by a header entry for a given// tablefunction ClearHeaderView(headerTable){  for (index in headerTable)  {     var headerEntry = headerTable[index];     if (headerEntry.useToggle)     {       headerEntry.enclosingBox.clearEmailAddresses();         }     headerEntry.valid = false;  }}// make sure that any valid header entry in the table is collapsedfunction hideHeaderView(headerTable){  for (index in headerTable)  {    headerTable[index].enclosingBox.collapsed = true;  }}// make sure that any valid header entry in the table specified is // visiblefunction showHeaderView(headerTable){  var headerEntry;  for (index in headerTable)  {    headerEntry = headerTable[index];    if (headerEntry.valid)    {      headerEntry.enclosingBox.collapsed = false;    }    else // if the entry is invalid, always make sure it's collapsed      headerEntry.enclosingBox.collapsed = true;  }}// enumerate through the list of headers and find the number that are visible

⌨️ 快捷键说明

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