msghdrviewoverlay.js
来自「现在很火的邮件客户端软件thunderbird的源码」· JavaScript 代码 · 共 1,653 行 · 第 1/5 页
JS
1,653 行
// add empty entries if we don't have the minimum number of rowsfunction EnsureMinimumNumberOfHeaders (headerTable){ if (!gMinNumberOfHeaders) // 0 means we don't have a minimum..do nothing special return; var numVisibleHeaders = 0; for (index in headerTable) { if (headerTable[index].valid) numVisibleHeaders ++; } if (numVisibleHeaders < gMinNumberOfHeaders) { // how many empty headers do we need to add? var numEmptyHeaders = gMinNumberOfHeaders - numVisibleHeaders; // we may have already dynamically created our empty rows and we just need to make them visible for (index in headerTable) { if (index.indexOf("Dummy-Header") == 0 && numEmptyHeaders) { headerTable[index].valid = true; numEmptyHeaders--; } } // ok, now if we have any extra dummy headers we need to add, create a new header widget for them while (numEmptyHeaders) { var dummyHeaderId = "Dummy-Header" + gDummyHeaderIdIndex; gExpandedHeaderView[dummyHeaderId] = new createNewHeaderView(dummyHeaderId, ""); gExpandedHeaderView[dummyHeaderId].valid = true; gDummyHeaderIdIndex++; numEmptyHeaders--; } }}// make sure the appropriate fields within the currently displayed view header mode// are collapsed or visible...function updateHeaderViews(){ if (gCollapsedHeaderViewMode) showHeaderView(gCollapsedHeaderView); else { if (gMinNumberOfHeaders) EnsureMinimumNumberOfHeaders(gExpandedHeaderView); showHeaderView(gExpandedHeaderView); } displayAttachmentsForExpandedView();}function ToggleHeaderView (){ gCollapsedHeaderViewMode = !gCollapsedHeaderViewMode; // Work around a xul deck bug where the height of the deck is determined by the tallest panel in the deck // even if that panel is not selected... document.getElementById('msgHeaderViewDeck').selectedPanel.collapsed = true; UpdateMessageHeaders(); // select the new panel. document.getElementById('msgHeaderViewDeck').selectedIndex = gCollapsedHeaderViewMode ? 0 : 1; // Work around a xul deck bug where the height of the deck is determined by the tallest panel in the deck // even if that panel is not selected... document.getElementById('msgHeaderViewDeck').selectedPanel.collapsed = false;}// default method for updating a header value into a header entryfunction updateHeaderValue(headerEntry, headerValue){ headerEntry.enclosingBox.headerValue = headerValue;}function updateHeaderValueInTextNode(headerEntry, headerValue){ headerEntry.textNode.value = headerValue;}function createNewHeaderView(headerName, label){ var idName = 'expanded' + headerName + 'Box'; var newHeader = document.createElement("mail-headerfield"); newHeader.setAttribute('id', idName); newHeader.setAttribute('label', label); newHeader.collapsed = true; // this new element needs to be inserted into the view... var topViewNode = document.getElementById('expandedHeaders'); topViewNode.appendChild(newHeader); this.enclosingBox = newHeader; this.isValid = false; this.useToggle = false; this.outputFunction = updateHeaderValue;}// UpdateMessageHeaders: Iterate through all the current header data we received from mime for this message// for each header entry table, see if we have a corresponding entry for that header. i.e. does the particular// view care about this header value. if it does then call updateHeaderEntryfunction UpdateMessageHeaders(){ // iterate over each header we received and see if we have a matching entry in each // header view table... var headerName; for (headerName in currentHeaderData) { var headerField = currentHeaderData[headerName]; var headerEntry = null; if (headerName == "subject") { try { if (gDBView.keyForFirstSelectedMessage == nsMsgKey_None) { var folder = null; if (gCurrentFolderUri) folder = RDF.GetResource(gCurrentFolderUri).QueryInterface(Components.interfaces.nsIMsgFolder); setTitleFromFolder(folder, headerField.headerValue); } } catch (ex) {} } if (gCollapsedHeaderViewMode && !gBuiltCollapsedView) { if (headerName in gCollapsedHeaderView) headerEntry = gCollapsedHeaderView[headerName]; } else if (!gCollapsedHeaderViewMode && !gBuiltExpandedView) { if (headerName in gExpandedHeaderView) headerEntry = gExpandedHeaderView[headerName]; if (!headerEntry && gViewAllHeaders) { // for view all headers, if we don't have a header field for this value....cheat and create one....then // fill in a headerEntry gExpandedHeaderView[headerName] = new createNewHeaderView(headerName, currentHeaderData[headerName].headerName + ':'); headerEntry = gExpandedHeaderView[headerName]; } } // if we are in expanded view.... if (headerEntry) { headerEntry.outputFunction(headerEntry, headerField.headerValue); headerEntry.valid = true; } } if (gCollapsedHeaderViewMode) gBuiltCollapsedView = true; else gBuiltExpandedView = true; // now update the view to make sure the right elements are visible updateHeaderViews(); if ("FinishEmailProcessing" in this) FinishEmailProcessing();}function ClearCurrentHeaders(){ currentHeaderData = {}; currentAttachments = new Array();}function ShowMessageHeaderPane(){ document.getElementById('msgHeaderView').collapsed = false; /* workaround for 39655 */ if (gFolderJustSwitched) { var el = document.getElementById("msgHeaderView"); el.setAttribute("style", el.getAttribute("style")); gFolderJustSwitched = false; }}function HideMessageHeaderPane(){ document.getElementById('msgHeaderView').collapsed = true; // disable the File/Attachments menuitem document.getElementById("fileAttachmentMenu").setAttribute("disabled", "true"); // disable the attachment box document.getElementById("attachmentView").collapsed = true;}function OutputNewsgroups(headerEntry, headerValue){ headerValue = headerValue.replace(/,/g,", "); updateHeaderValue(headerEntry, headerValue);}// OutputEmailAddresses --> knows how to take a comma separated list of email addresses,// extracts them one by one, linkifying each email address into a mailto url. // Then we add the link-ified email address to the parentDiv passed in.// // emailAddresses --> comma separated list of the addresses for this header fieldfunction OutputEmailAddresses(headerEntry, emailAddresses){ if (!emailAddresses) return; if (msgHeaderParser) { var addresses = {}; var fullNames = {}; var names = {}; var numAddresses = 0; numAddresses = msgHeaderParser.parseHeadersWithArray(emailAddresses, addresses, names, fullNames); var index = 0; while (index < numAddresses) { // if we want to include short/long toggle views and we have a long view, always add it. // if we aren't including a short/long view OR if we are and we haven't parsed enough // addresses to reach the cutoff valve yet then add it to the default (short) div. var address = {}; address.emailAddress = addresses.value[index]; address.fullAddress = fullNames.value[index]; address.displayName = names.value[index]; if (headerEntry.useToggle) headerEntry.enclosingBox.addAddressView(address); else updateEmailAddressNode(headerEntry.enclosingBox.emailAddressNode, address); index++; } if (headerEntry.useToggle) headerEntry.enclosingBox.buildViews(); } // if msgheader parser}function updateEmailAddressNode(emailAddressNode, address){ emailAddressNode.setAttribute("label", address.fullAddress || address.displayName); emailAddressNode.removeAttribute("tooltiptext"); emailAddressNode.setAttribute("emailAddress", address.emailAddress); emailAddressNode.setAttribute("fullAddress", address.fullAddress); emailAddressNode.setAttribute("displayName", address.displayName); AddExtraAddressProcessing(address.emailAddress, emailAddressNode);}// thunderbird has smart logic for determining if we should show just the display name.// mozilla already has a generic method that gets called on each email address node called// AddExtraAddressProcessing which is undefined in seamonkey. Let's hijack this convient method to do what// we want.function AddExtraAddressProcessing(emailAddress, addressNode){ var displayName = addressNode.getAttribute("displayName"); var emailAddress = addressNode.getAttribute("emailAddress"); // always show the address for the from and reply-to fields var parentElementId = addressNode.parentNode.id; var condenseName = true; if (parentElementId == "expandedfromBox" || parentElementId == "expandedreply-toBox") condenseName = false; if (condenseName && gShowCondensedEmailAddresses && displayName) { if (useDisplayNameForAddress(emailAddress)) addressNode.setAttribute("label", displayName); addressNode.setAttribute("tooltiptext", emailAddress); addressNode.setAttribute("tooltip", "emailAddressTooltip"); } else addressNode.removeAttribute("tooltiptext");} function fillEmailAddressPopup(emailAddressNode){ var emailAddressPlaceHolder = document.getElementById('emailAddressPlaceHolder'); var emailAddress = emailAddressNode.getAttribute('emailAddress'); emailAddressPlaceHolder.setAttribute('label', emailAddress);}// Public method called to generate a tooltip over a condensed display namefunction fillInEmailAddressTooltip(addressNode){ var emailAddress = addressNode.getAttribute('emailAddress'); var tooltipNode = document.getElementById("attachmentListTooltip"); tooltipNode.setAttribute("label", attachmentName); return true;}// returns true if we should use the display name for this address// otherwise returns falsefunction useDisplayNameForAddress(emailAddress){ // For now, if the email address is in the personal address book, then consider this user a 'known' user // and use the display name. I could eventually see our rules enlarged to include other local ABs, replicated // LDAP directories, and maybe even domain matches (i.e. any email from someone in my company // should use the friendly display name) if (!gPersonalAddressBookDirectory) { var RDFService = Components.classes[kRDFServiceContractID].getService(Components.interfaces.nsIRDFService); gPersonalAddressBookDirectory = RDFService.GetResource(kPersonalAddressbookUri).QueryInterface(Components.interfaces.nsIAbMDBDirectory); if (!gPersonalAddressBookDirectory) return false; } // look up the email address in the database return gPersonalAddressBookDirectory.hasCardForEmailAddress(emailAddress);}function AddNodeToAddressBook (emailAddressNode){ if (emailAddressNode) { var primaryEmail = emailAddressNode.getAttribute("emailAddress"); var displayName = emailAddressNode.getAttribute("displayName");
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?