diff --git a/mozilla/mailnews/base/resources/content/mail3PaneWindowCommands.js b/mozilla/mailnews/base/resources/content/mail3PaneWindowCommands.js index 516f47d3bed..cf416648608 100644 --- a/mozilla/mailnews/base/resources/content/mail3PaneWindowCommands.js +++ b/mozilla/mailnews/base/resources/content/mail3PaneWindowCommands.js @@ -202,6 +202,7 @@ var DefaultController = case "cmd_forwardInline": case "cmd_forwardAttachment": case "cmd_editAsNew": + case "cmd_canHaveFilter": case "cmd_delete": case "button_delete": case "cmd_shiftDelete": @@ -330,6 +331,10 @@ var DefaultController = case "cmd_forwardInline": case "cmd_forwardAttachment": case "cmd_editAsNew": + case "cmd_canHaveFilter": + var loadedFolder = GetLoadedMsgFolder(); + if (!(loadedFolder && loadedFolder.server.canHaveFilters) || !(IsMessageDisplayedInMessagePane())) + return false; case "cmd_openMessage": case "button_print": case "cmd_print": @@ -372,7 +377,7 @@ var DefaultController = return(MailAreaHasFocus() && IsFolderSelected()); case "cmd_find": case "cmd_findAgain": - return IsFindEnabled(); + return IsMessageDisplayedInMessagePane(); break; // these are enabled on when we are in threaded mode case "cmd_selectThread": @@ -478,6 +483,9 @@ var DefaultController = case "cmd_editAsNew": MsgEditMessageAsNew(); break; + case "cmd_canHaveFilter": + MsgCreateFilter(); + break; case "button_delete": case "cmd_delete": SetNextMessageAfterDelete(); @@ -867,7 +875,7 @@ function IsFolderSelected() return false; } -function IsFindEnabled() +function IsMessageDisplayedInMessagePane() { return (!IsThreadAndMessagePaneSplitterCollapsed() && (GetNumSelectedMessages() > 0)); } diff --git a/mozilla/mailnews/base/resources/content/mail3PaneWindowVertLayout.xul b/mozilla/mailnews/base/resources/content/mail3PaneWindowVertLayout.xul index 94bc60ec291..2af3f6c9218 100644 --- a/mozilla/mailnews/base/resources/content/mail3PaneWindowVertLayout.xul +++ b/mozilla/mailnews/base/resources/content/mail3PaneWindowVertLayout.xul @@ -126,6 +126,10 @@ Rights Reserved. + diff --git a/mozilla/mailnews/base/resources/content/mailWindowOverlay.js b/mozilla/mailnews/base/resources/content/mailWindowOverlay.js index d722c6b12a1..c1da4ab67fc 100644 --- a/mozilla/mailnews/base/resources/content/mailWindowOverlay.js +++ b/mozilla/mailnews/base/resources/content/mailWindowOverlay.js @@ -654,6 +654,24 @@ function MsgEditMessageAsNew() ComposeMessage(msgComposeType.Template, msgComposeFormat.Default, loadedFolder, messageArray); } +function MsgCreateFilter() +{ + var emailAddressNode; + + if (gCollapsedHeaderViewMode) + emailAddressNode = document.getElementById("collapsedfromValue"); + else + emailAddressNode = document.getElementById("expandedfromValue"); + + if (emailAddressNode) + { + var emailAddress = emailAddressNode.getTextAttribute("emailAddress"); + if (emailAddress){ + top.MsgFilters(emailAddress); + } + } +} + function MsgHome(url) { window.open(url, "_blank", "chrome,dependent=yes,all"); @@ -926,26 +944,43 @@ function MsgSearchMessages() "chrome,resizable,centerscreen,dialog=no", { folder: preselectedFolder }); } -function MsgFilters() +function MsgFilters(emailAddress) { var preselectedFolder = GetFirstSelectedMsgFolder(); var windowManagerInterface = GetWindowMediator(); var filterList = windowManagerInterface.getMostRecentWindow("mailnews:filterlist"); + var args = { folder: preselectedFolder }; + if (emailAddress) + args.prefillValue = emailAddress; if (filterList) { - var filterEditor = windowManagerInterface.getMostRecentWindow("mailnews:filtereditor"); + var filterEditor = windowManagerInterface.getMostRecentWindow("mailnews:filtereditor"); - // If the filtereditor is open, then we focus that because it is modal and - // thus blocking the filterlist from focusing. - if (filterEditor) - filterEditor.focus(); - else - filterList.focus(); + // If the filtereditor is open, then we focus that because it is modal and + // thus blocking the filterlist from focusing. + if (filterEditor) + { + if(emailAddress) + { + if(!gPromptService) { + gPromptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(); + gPromptService = gPromptService.QueryInterface(Components.interfaces.nsIPromptService); + } + + gPromptService.alert(window, + gBrandBundle.getString("brandShortName"), + gMessengerBundle.getString('cannotHaveTwoFilterRulesText') + ); + } + filterEditor.focus(); + } + else + filterList.openPrefillOnExistingFilterList(emailAddress); } else - window.openDialog("chrome://messenger/content/FilterListDialog.xul", "", - "chrome,resizable,centerscreen,dialog=yes", { folder: preselectedFolder }); + window.openDialog("chrome://messenger/content/FilterListDialog.xul", "", + "chrome,resizable,centerscreen,dialog=yes", args); } function MsgViewAllHeaders() diff --git a/mozilla/mailnews/base/resources/content/mailWindowOverlay.xul b/mozilla/mailnews/base/resources/content/mailWindowOverlay.xul index 74be4ad2ccd..f50f97349ab 100644 --- a/mozilla/mailnews/base/resources/content/mailWindowOverlay.xul +++ b/mozilla/mailnews/base/resources/content/mailWindowOverlay.xul @@ -188,7 +188,7 @@ Rights Reserved. - + @@ -900,7 +900,7 @@ Rights Reserved. + oncommand="MsgFilters(null);"/> @@ -1064,6 +1064,10 @@ Rights Reserved. key="key_editAsNew" observes="cmd_editAsNew"/> + + diff --git a/mozilla/mailnews/base/resources/content/messageWindow.js b/mozilla/mailnews/base/resources/content/messageWindow.js index 3ff008109aa..02112a10377 100644 --- a/mozilla/mailnews/base/resources/content/messageWindow.js +++ b/mozilla/mailnews/base/resources/content/messageWindow.js @@ -420,6 +420,7 @@ var MessageWindowController = case "cmd_forwardInline": case "cmd_forwardAttachment": case "cmd_editAsNew": + case "cmd_canHaveFilter": case "cmd_delete": case "cmd_undo": case "cmd_redo": @@ -499,6 +500,11 @@ var MessageWindowController = case "cmd_forwardInline": case "cmd_forwardAttachment": case "cmd_editAsNew": + case "cmd_canHaveFilter": + var loadedFolder = GetLoadedMsgFolder(); + if (!(loadedFolder && loadedFolder.server.canHaveFilters)) + return false; + case "button_delete": case "cmd_shiftDelete": case "cmd_print": @@ -600,6 +606,9 @@ var MessageWindowController = case "cmd_editAsNew": MsgEditMessageAsNew(); break; + case "cmd_canHaveFilter": + MsgCreateFilter(); + break; case "cmd_delete": MsgDeleteMessageFromMessageWindow(false, false); break; diff --git a/mozilla/mailnews/base/resources/content/messageWindow.xul b/mozilla/mailnews/base/resources/content/messageWindow.xul index cdf8be45866..0eb19b46d19 100644 --- a/mozilla/mailnews/base/resources/content/messageWindow.xul +++ b/mozilla/mailnews/base/resources/content/messageWindow.xul @@ -106,6 +106,10 @@ Rights Reserved. + diff --git a/mozilla/mailnews/base/resources/content/messenger.xul b/mozilla/mailnews/base/resources/content/messenger.xul index 514c8ad7d10..d973d8db3c0 100644 --- a/mozilla/mailnews/base/resources/content/messenger.xul +++ b/mozilla/mailnews/base/resources/content/messenger.xul @@ -130,6 +130,10 @@ Rights Reserved. + diff --git a/mozilla/mailnews/base/resources/content/msgAccountCentral.js b/mozilla/mailnews/base/resources/content/msgAccountCentral.js index 99feaa16feb..e835df3c1f9 100644 --- a/mozilla/mailnews/base/resources/content/msgAccountCentral.js +++ b/mozilla/mailnews/base/resources/content/msgAccountCentral.js @@ -236,7 +236,7 @@ function SearchMessages() // Open filters window function CreateMsgFilters() { - window.parent.MsgFilters(); + window.parent.MsgFilters(null); } // Open Subscribe dialog diff --git a/mozilla/mailnews/base/resources/content/msgHdrViewOverlay.js b/mozilla/mailnews/base/resources/content/msgHdrViewOverlay.js index 4611483976b..ddef925cbf2 100644 --- a/mozilla/mailnews/base/resources/content/msgHdrViewOverlay.js +++ b/mozilla/mailnews/base/resources/content/msgHdrViewOverlay.js @@ -712,6 +712,20 @@ function CopyEmailAddress(emailAddressNode) } } +// CreateFilter opens the Message Filters and Filter Rules dialogs. +//The Filter Rules dialog has focus. The window is prefilled with filtername +//Sender condition is selected and the value is prefilled +function CreateFilter(emailAddressNode) +{ + if (emailAddressNode) + { + var emailAddress = emailAddressNode.getAttribute("emailAddress"); + if (emailAddress){ + top.MsgFilters(emailAddress); + } + } +} + // createnewAttachmentInfo --> constructor method for creating new attachment object which goes into the // data attachment array. function createNewAttachmentInfo(contentType, url, displayName, uri, notDownloaded) diff --git a/mozilla/mailnews/base/resources/locale/en-US/messenger.dtd b/mozilla/mailnews/base/resources/locale/en-US/messenger.dtd index 5dc1656dbaa..56ab19b4f58 100644 --- a/mozilla/mailnews/base/resources/locale/en-US/messenger.dtd +++ b/mozilla/mailnews/base/resources/locale/en-US/messenger.dtd @@ -341,6 +341,8 @@ Rights Reserved. + + @@ -495,6 +497,10 @@ Rights Reserved. + + + + diff --git a/mozilla/mailnews/base/resources/locale/en-US/messenger.properties b/mozilla/mailnews/base/resources/locale/en-US/messenger.properties index 2977552136b..23ccdb5495b 100644 --- a/mozilla/mailnews/base/resources/locale/en-US/messenger.properties +++ b/mozilla/mailnews/base/resources/locale/en-US/messenger.properties @@ -174,6 +174,8 @@ nocachedbodytitle=Go Online to View This Message\n\ confirmUnsubscribeTitle=Confirm Unsubscribe confirmUnsubscribeText=Are you sure you want to unsubscribe from %S? +cannotHaveTwoFilterRulesDialogs=Filter Rules Dialog +cannotHaveTwoFilterRulesText=The filter cannot be created because the Filter Rules dialog is already in use. Please close the dialog and try again. # msgHdrViewOverlay.js openLabel=Open diff --git a/mozilla/mailnews/base/search/resources/content/FilterEditor.js b/mozilla/mailnews/base/search/resources/content/FilterEditor.js index c963c6a6b02..bb7fd047758 100644 --- a/mozilla/mailnews/base/search/resources/content/FilterEditor.js +++ b/mozilla/mailnews/base/search/resources/content/FilterEditor.js @@ -39,7 +39,6 @@ // the actual filter that we're editing var gFilter; - // cache the key elements we need var gFilterList; var gFilterNameElement; @@ -49,10 +48,14 @@ var gActionValueDeck; var gActionPriority; var gActionLabel; var gFilterBundle; - +var gPreFillName; var nsMsgSearchScope = Components.interfaces.nsMsgSearchScope; var nsMsgFilterAction = Components.interfaces.nsMsgFilterAction; + +/* the okCallback is used for sending a callback to the Filter Dialog to close incase the user cancels from pre-fill.*/ +var okCallback=null; + var gFilterEditorMsgWindow=null; function filterEditorOnLoad() @@ -63,16 +66,45 @@ function filterEditorOnLoad() gFilterBundle = document.getElementById("bundle_filter"); if ("arguments" in window && window.arguments[0]) { var args = window.arguments[0]; + if("okCallback" in args ) { + top.okCallback = window.arguments[0].okCallback; + } + if ("filter" in args) { - gFilter = window.arguments[0].filter; + // editing a filter + gFilter = window.arguments[0].filter; + initializeDialog(gFilter); + } + else { + gFilterList = args.filterList; + if (gFilterList) + setSearchScope(getScopeFromFilterList(gFilterList)); + + // if doing prefill filter create a new filter and populate it. + if ("filterName" in args) { + gPreFillName = args.filterName; + gFilter = gFilterList.createFilter(gPreFillName); + var term = gFilter.createTerm(); + + term.attrib = Components.interfaces.nsMsgSearchAttrib.Sender; + term.op = Components.interfaces.nsMsgSearchOp.Is; + + var termValue = term.value; + termValue.attrib = term.attrib; + termValue.str = gPreFillName; + + term.value = termValue; + + gFilter.appendTerm(term); + gFilter.action = nsMsgFilterAction.MoveToFolder; initializeDialog(gFilter); - } else { - gFilterList = args.filterList; - if (gFilterList) - setSearchScope(getScopeFromFilterList(gFilterList)); + } + else{ // fake the first more button press onMore(null); + } + } } if (!gFilter) @@ -90,7 +122,7 @@ function filterEditorOnLoad() gFilterNameElement.value = name; } gFilterNameElement.focus(); - doSetOKCancel(onOk, null); + doSetOKCancel(onOk, onCancel); moveToAlertPosition(); } @@ -127,6 +159,13 @@ function onOk() window.close(); } +function onCancel() +{ + if (top.okCallback) + top.okCallback(); + window.close(); +} + function duplicateFilterNameExists(filterName) { var args = window.arguments[0]; @@ -261,7 +300,15 @@ function saveFilter() { gFilter.enabled=true; } else { gFilter.filterName = gFilterNameElement.value; - isNewFilter = false; + + //Prefilter is treated as a new filter. + if (gPreFillName) { + isNewFilter = true; + gFilter.enabled=true; + } + else { + isNewFilter = false; + } } gFilter.action = action; diff --git a/mozilla/mailnews/base/search/resources/content/FilterEditor.xul b/mozilla/mailnews/base/search/resources/content/FilterEditor.xul index 18dacb8882a..38b9de9b519 100644 --- a/mozilla/mailnews/base/search/resources/content/FilterEditor.xul +++ b/mozilla/mailnews/base/search/resources/content/FilterEditor.xul @@ -40,7 +40,8 @@ Contributor(s): windowtype="mailnews:filtereditor" width="510" height="360" persist="width height screenX screenY" - onload="filterEditorOnLoad();"> + onload="filterEditorOnLoad();" + onclose="onCancel();"> diff --git a/mozilla/mailnews/base/search/resources/content/FilterListDialog.js b/mozilla/mailnews/base/search/resources/content/FilterListDialog.js index 310821dc880..476383517ed 100644 --- a/mozilla/mailnews/base/search/resources/content/FilterListDialog.js +++ b/mozilla/mailnews/base/search/resources/content/FilterListDialog.js @@ -29,7 +29,7 @@ const nsMsgFilterMotion = Components.interfaces.nsMsgFilterMotion; var gFilterBundle; var gPromptService; - +var gFilterListDialogAlreadyOpen = false; function onLoad() { rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService); @@ -44,7 +44,7 @@ function onLoad() reorderUpButton = document.getElementById("reorderUpButton"); reorderDownButton = document.getElementById("reorderDownButton"); - doSetOKCancel(onOk, null); + doSetOKCancel(onOk, onCancel); updateButtons(); @@ -62,14 +62,30 @@ function onLoad() } moveToAlertPosition(); + + if (("arguments" in window) && window.arguments[0] && ("prefillValue" in window.arguments[0])) + onNewFilter(window.arguments[0].prefillValue); } +function openPrefillOnExistingFilterList(emailAddress) +{ + gFilterListDialogAlreadyOpen = true; + onNewFilter(emailAddress); +} +function onCancel() +{ + if(gFilterListDialogAlreadyOpen) + gFilterListDialogAlreadyOpen = false; + else + window.close(); +} + function onOk() { - // make sure to save the filter to disk - var filterList = currentFilterList(); - if (filterList) filterList.saveToDefaultFile(); - window.close(); + // make sure to save the filter to disk + var filterList = currentFilterList(); + if (filterList) filterList.saveToDefaultFile(); + window.close(); } function onServerClick(event) @@ -157,11 +173,15 @@ function onEditFilter() { refreshFilterList(); } -function onNewFilter() +function onNewFilter(emailAddress) { - var curFilterList = currentFilterList(); - var args = {filterList: curFilterList}; - + var curFilterList = currentFilterList(); + var args = {filterList: curFilterList}; + if(emailAddress) { + args.okCallback = onCancel; + args.filterName = emailAddress; + } + window.openDialog("chrome://messenger/content/FilterEditor.xul", "FilterEditor", "chrome,modal,titlebar,resizable,centerscreen", args); if ("refresh" in args && args.refresh) diff --git a/mozilla/mailnews/base/search/resources/content/FilterListDialog.xul b/mozilla/mailnews/base/search/resources/content/FilterListDialog.xul index 81bc7675d33..12b4a48d801 100644 --- a/mozilla/mailnews/base/search/resources/content/FilterListDialog.xul +++ b/mozilla/mailnews/base/search/resources/content/FilterListDialog.xul @@ -122,7 +122,7 @@ Contributor(s): H -