Results 1 to 2 of 2

Thread: ZD color filter new mail local address book

  1. #1
    Join Date
    May 2010
    Posts
    5
    Rep Power
    5

    Default ZD color filter new mail local address book

    I need to set filter in ZD for new messages from local addresses with color mark (now new messages are bold). How could it may be realized and what part of code i need to modify(where can i add such condition to change color of messages)?

  2. #2
    Join Date
    May 2010
    Posts
    5
    Rep Power
    5

    Default

    who can and want, made on the basis of Colored Emails

    Colored Emails | Zimbra :: Gallery

    before installing the need to edit the file "coloredemails.js"

    function com_zimbra_coloredemails() {
    }

    com_zimbra_coloredemails.prototype = new ZmZimletBase();
    com_zimbra_coloredemails.prototype.constructor = com_zimbra_coloredemails;

    com_zimbra_coloredemails.prototype.init =
    function() {
    this.turnColoredEmailsZimletON = this.getUserProperty("turnColoredEmailsZimletON") == "true";
    this._areVariablesInitialized = false;
    if (!this.turnColoredEmailsZimletON) {
    return;
    }

    this._initializeVariables();
    this._resetView();
    };

    com_zimbra_coloredemails.prototype._initializeVari ables =
    function() {
    this._defaultEmail = "local@domain.ru"; // any value-mail address
    this._cEmail_manualAddedEmailsArray = [];
    this._cEmail_autoAddedEmailsArray = [];
    this._colorChangedDueToTag = false;

    //this.uprop_cEmail_manualAddedEmails = this.getUserProperty("cEmail_manualAddedEmails"); // <- fix on
    this.uprop_cEmail_manualAddedEmails = ("uu-smok.ru:#000000:#FFD700, slata.ru:#000000:#00CD00"); // <- this
    this.uprop_cEmail_autoAddedEmails = this.getUserProperty("cEmail_autoAddedEmails");
    this.uprop_cEmail_autoAssociateChkbx = this.getUserProperty("cEmail_autoAssociateChkbx") == "true";
    this.uprop_cEmail_useAutoAssociatedEmailsChkbx = this.getUserProperty("cEmail_useAutoAssociatedEmai lsChkbx") == "true";
    this._setEmails(this._cEmail_manualAddedEmailsArra y, this.uprop_cEmail_manualAddedEmails);

    //if we also need to color auto-added emails..
    if (this.uprop_cEmail_useAutoAssociatedEmailsChkbx) {
    this._setEmails(this._cEmail_autoAddedEmailsArray, this.uprop_cEmail_autoAddedEmails);
    setTimeout(AjxCallback.simpleClosure(this._saveAut oAddedEmails, this), 300000);//save autoaddedemails after 5 minutes
    }
    this._areVariablesInitialized = true;
    };

    com_zimbra_coloredemails.prototype._saveAutoAddedE mails =
    function() {
    if (this.uprop_cEmail_autoAddedEmails.split(",").leng th >= 25) {
    var tmp = this.uprop_cEmail_autoAddedEmails.split(",");
    var str = "";
    for (var i = 0; i < 25; i++) {
    if (str == "")
    str = AjxStringUtil.trim(tmp[i]);
    else
    str = str + ", " + AjxStringUtil.trim(tmp[i]);
    }
    }
    this.setUserProperty("cEmail_autoAddedEmails", str, true);
    };

    com_zimbra_coloredemails.prototype._setEmails =
    function(storeArray, userProp) {
    var arry = userProp.split(",");
    for (var i = 0; i < arry.length; i++) {
    try {
    var tmp = arry[i].split(":");
    if (tmp[0] == this._defaultEmail)
    continue;

    var eml = AjxStringUtil.trim(tmp[0]).toLowerCase();
    // window.alert(tmp[0] + "_0");
    // window.alert(tmp.length);
    if (tmp.length == 3) {
    var bg = AjxStringUtil.trim(tmp[2]);
    if (bg == "white" || bg == "#FFFFFF")//if background is white, ignore it
    storeArray[eml] = " style=\"color: " + AjxStringUtil.trim(tmp[1]) + ";\" ";
    else
    storeArray[eml] = " style=\"color: " + AjxStringUtil.trim(tmp[1]) + ";background-color: " + bg + ";\" ";

    } else if (tmp.length == 2) {
    storeArray[eml] = " style=\"color: " + AjxStringUtil.trim(tmp[1]) + ";\" ";
    }
    } catch(e) {
    }
    }
    };

    com_zimbra_coloredemails.prototype.onTagAction =
    function(items, tag, doTag) {//basically refreshes the view to reflect new colors
    if (!this.turnColoredEmailsZimletON)
    return;
    if(!this._colorChangedDueToTag)
    return;

    try {
    var type = items[0].type;
    if (type != null && (type == ZmItem.CONV || type == ZmItem.MSG)) {
    this._resetView();
    }
    } catch(e) {
    }
    this._colorChangedDueToTag = false;
    };


    com_zimbra_coloredemails.prototype._resetView =
    function() {
    try {
    var q = appCtxt.getSearchController().currentSearch.query;
    appCtxt.getSearchController().search({query:q});
    } catch(e) {
    }
    };


    com_zimbra_coloredemails.prototype.getMailCellStyl e =
    function(item, field) {
    if (!this.turnColoredEmailsZimletON)
    return null;

    var eml = "";
    var tagName = "";
    try {
    if (item.type == ZmId.ITEM_CONV) {
    var arry = item.participants.getArray();
    if(arry.length >0) {
    eml = arry[arry.length - 1].address;
    }
    } else if (item.type == ZmId.ITEM_MSG) {
    var obj = item.getAddress(AjxEmailAddress.FROM);
    if(obj)
    //------------------
    var addr = obj.address.split("@");
    //window.alert(addr[1]);
    if(addr[1] == "domein.ru") { //<----fix its
    eml = "domen.ru"; //<----fix its
    } else if (addr[1] == "domen2.ru"){ //<----fix its
    eml = "domen2.ru"; //<----fix its
    } else {
    eml = obj.address;
    }
    //------------------
    } else {
    return null;
    }

    var tgs = item.tags;
    if (tgs.length > 0) {
    tagName = appCtxt.getById(tgs[0]).name;
    }

    } catch(e) {
    }

    if (eml == "" && tagName == "") {
    return "";
    }

    //highest priority is for tags, then emails, followed by auto-added emails
    if (tagName != "") {//if we might need to color based on tagName
    var colorsByTag = this._cEmail_manualAddedEmailsArray[tagName];
    if (colorsByTag) {
    this._colorChangedDueToTag = true;
    return colorsByTag;
    }
    }
    var eml = AjxStringUtil.trim(eml).toLowerCase();//trim and ignore case
    var colors = this._cEmail_manualAddedEmailsArray[eml];
    if (colors) {
    return colors;
    }

    return "";
    };


    com_zimbra_coloredemails.prototype.doubleClicked = function() {
    this.singleClicked();
    };

    com_zimbra_coloredemails.prototype.singleClicked = function() {
    this._showPreferenceDlg();
    };

    com_zimbra_coloredemails.prototype.doDrop =
    function(msg) {
    if(msg instanceof Array)
    msg = msg[0];

    if (this.turnColoredEmailsZimletON) {
    this._showPreferenceDlg();
    var tagName = "";
    var eml = "";

    var tgs = msg.tags;
    if (tgs.length > 0) {
    tagName = appCtxt.getById(tgs[0]).name;
    }

    var from = msg.from;

    if (from) {
    eml = from[0].address;
    } else {
    eml = msg.participants[msg.participants.length - 1].address;
    }
    if (eml == "" && tagName == "")
    return;

    document.getElementById("cEmail_emailField").value = tagName != "" ? tagName : eml;
    document.getElementById("cEmail_exampleEmailNameTD ").innerHTML = eml;
    }
    };

    com_zimbra_coloredemails.prototype._showPreference Dlg = function() {
    //if zimlet dialog already exists...
    if (this._preferenceDialog) {
    //this._setZimletCurrentPreferences();
    this._preferenceDialog.popup();
    return;
    }
    this._preferenceView = new DwtComposite(this.getShell());
    this._preferenceView.setSize("520", "490");
    this._preferenceView.getHtmlElement().style.overfl ow = "auto";
    this._preferenceView.getHtmlElement().innerHTML = this._createPrefView();

    document.getElementById('cEmail_showHideLnk').oncl ick = AjxCallback.simpleClosure(this._showHideDetails, this);
    this._showHideDetails();//initially hide the div
    var pickrComposite = new DwtComposite(this.getShell());
    this._fontColorButton = new ZmHtmlEditorColorPicker(pickrComposite, null, "ZButton");
    this._fontColorButton.dontStealFocus();
    this._fontColorButton.setImage("FontColor");
    this._fontColorButton.showColorDisplay(true);
    this._fontColorButton.setToolTipContent(ZmMsg.font Color);
    this._fontColorButton.addSelectionListener(new AjxListener(this, this._emailAndColorBtnListener));
    document.getElementById("cEmail_colorsMenuTD").app endChild(pickrComposite.getHtmlElement());

    var pickrBgComposite = new DwtComposite(this.getShell());
    this._fontBackgroundButton = new ZmHtmlEditorColorPicker(pickrBgComposite, null, "ZButton");
    this._fontBackgroundButton.dontStealFocus();
    this._fontBackgroundButton.setImage("FontBackgroun d");
    this._fontBackgroundButton.showColorDisplay(true);
    this._fontBackgroundButton.setToolTipContent(ZmMsg .fontBackground);
    this._fontBackgroundButton.addSelectionListener(ne w AjxListener(this, this._emailAndColorBtnListener));
    document.getElementById("cEmail_colorsBgMenuTD").a ppendChild(pickrBgComposite.getHtmlElement());

    var addButton = new DwtButton(this.getShell());
    addButton.setText("Add");
    addButton.addSelectionListener(new AjxListener(this, this._addButtonListener, true));
    document.getElementById("cEmail_AddBtnTD").appendC hild(addButton.getHtmlElement());

    var saveButtonId = Dwt.getNextId();
    var saveButton = new DwtDialog_ButtonDescriptor(saveButtonId, ("Save Changes"), DwtDialog.ALIGN_RIGHT);
    this._preferenceDialog = this._createDialog({title:"'Colored Emails' Zimlet Preferences", view:this._preferenceView, standardButtons:[DwtDialog.CANCEL_BUTTON], extraButtons:[saveButton]});
    this._preferenceDialog.setButtonListener(saveButto nId, new AjxListener(this, this._okPreferenceBtnListener));

    Dwt.setHandler(document.getElementById("cEmail_ema ilField"), DwtEvent.ONKEYUP, AjxCallback.simpleClosure(this._emailAndColorBtnLi stener, this));

    this._setZimletCurrentPreferences();
    // this._setZimletCurrentPreferences();
    this._preferenceDialog.popup();
    };


    com_zimbra_coloredemails.prototype._createPrefView =
    function() {
    var html = new Array();
    var i = 0;
    html[i++] = "<BR>";
    html[i++] = "<DIV>";
    html[i++] = "<B>Associate a sender's email or tag name with a color:</B>";
    html[i++] = "</DIV>";
    html[i++] = "<TABLE width=95% align='center'>";
    html[i++] = "<TR><TD width='24%'>Email or Tag name:</TD>";
    html[i++] = "<TD width=40%><INPUT id='cEmail_emailField' type=\"text\" style=\"width:100%;\" type='text' value='" + this._defaultEmail + "'></INPUT></TD>";
    html[i++] = "<TD width='12%' id='cEmail_colorsMenuTD'></TD>";
    html[i++] = "<TD width='12%' id='cEmail_colorsBgMenuTD'></TD>";
    html[i++] = "<TD width='22%' id='cEmail_AddBtnTD'></TD></TR>";
    html[i++] = "</TABLE>";
    html[i++] = "</DIV>";

    html[i++] = "<DIV>";
    html[i++] = "<TABLE id='cEmail_exampleEmailTableID' class='cEmail_exampleEmailTable' align='center'>";
    html[i++] = "<TR><TD id='cEmail_exampleEmailNameTD'>" + this._defaultEmail + "</TD>";
    html[i++] = "<TD>Re:This is an example subject of an email</TD></TR>";
    html[i++] = "</TABLE>";
    html[i++] = "</DIV>";
    html[i++] = "<BR>";
    html[i++] = "<DIV>";
    html[i++] = "<a href=\"#\" id='cEmail_showHideLnk'></a>";
    html[i++] = "</DIV>";

    html[i++] = "<DIV id='cEmail_showHideDiv'>";
    html[i++] = "<TABLE width=95% align='center'>";
    html[i++] = "<TR><TD>Manually added Email & colors:</TD><TD id='cEmail_exampleFormatTD' width='65%'></TD></TR>";
    html[i++] = "<TR><TD colspan=2><TEXTAREA rows=\"5\" cols=\"20\" id='cEmail_manualAddedEmails'/></TEXTAREA></TD></TR>";
    html[i++] = "</TABLE>";
    html[i++] = "<BR>";
    html[i++] = "<BR>";
    html[i++] = "<TABLE width=95%>";
    html[i++] = "<TR><TD><input id='turnONColoredEmailsChkbox' type='checkbox'/>Turn ON 'Colored Emails'-Zimlet</TD></TR>";
    html[i++] = "<TR><TD><FONT size='1pt'>*Changes to the above preferences would refresh the browser</FONT></TD></TR>";
    html[i++] = "</TABLE>";
    html[i++] = "</DIV>";
    return html.join("");
    };

    com_zimbra_coloredemails.prototype._showHideDetail s =
    function() {
    var doc = document.getElementById("cEmail_showHideDiv");
    if (doc.style.display == "none") {
    this._preferenceView.setSize("520", "490");
    doc.style.display = "block";
    document.getElementById("cEmail_showHideLnk").inne rHTML = "Hide Advanced Options";
    } else {
    doc.style.display = "none";
    this._preferenceView.setSize("520", "180");
    document.getElementById("cEmail_showHideLnk").inne rHTML = "Show Advanced Options";
    }
    };

    com_zimbra_coloredemails.prototype._addButtonListe ner =
    function(showInfoMsg) {
    var email = document.getElementById("cEmail_emailField").value ;


    var fColor = this._fontColorButton.getColor();
    var bColor = this._fontBackgroundButton.getColor();
    //check for duplicates
    this._mAddedEmailsTextarea = document.getElementById("cEmail_manualAddedEmails" );
    var allEmails = this._mAddedEmailsTextarea.value;

    //remove duplicates(replace old with new)
    var arry = allEmails.split(",");
    var nonDupeArry = [];
    for (var i = 0; i < arry.length; i++) {
    var mailAndColor = AjxStringUtil.trim(arry[i]);
    var tmpArry = mailAndColor.split(":");
    if (tmpArry.length == 0)//there is no :
    continue;

    var currEmail = tmpArry[0].toLowerCase();
    var newEmail = email.toLowerCase();
    if (newEmail != currEmail) {
    nonDupeArry.push(mailAndColor);
    }
    }
    var nonDupeVal = nonDupeArry.join(", ");
    this._mAddedEmailsTextarea.value = email + ":" + fColor + ":" + bColor + ", " + nonDupeVal;

    if (showInfoMsg) {
    var transitions = [ ZmToast.FADE_IN, ZmToast.PAUSE, ZmToast.PAUSE, ZmToast.FADE_OUT ];
    appCtxt.getAppController().setStatusMsg("New Color Added", ZmStatusView.LEVEL_INFO, null, transitions);
    }
    };

    com_zimbra_coloredemails.prototype._emailAndColorB tnListener =
    function(ev) {
    document.getElementById("cEmail_exampleEmailTableI D").style.color = this._fontColorButton.getColor();
    document.getElementById("cEmail_exampleEmailTableI D").style.backgroundColor = this._fontBackgroundButton.getColor();
    var email = document.getElementById("cEmail_emailField").value ;
    if (email == "undefined") {
    email = this._defaultEmail;
    document.getElementById("cEmail_emailField").value = email;
    }

    document.getElementById("cEmail_exampleFormatTD"). innerHTML = "(Current Value: " + email + ":" + this._fontColorButton.getColor() + ":" + this._fontBackgroundButton.getColor() + ")";
    document.getElementById("cEmail_exampleEmailNameTD ").innerHTML = email;
    };

    com_zimbra_coloredemails.prototype._setZimletCurre ntPreferences =
    function(ev) {

    if (!this._areVariablesInitialized) {
    this._initializeVariables();
    }

    //set the values to ui..
    if (this.turnColoredEmailsZimletON) {
    document.getElementById("turnONColoredEmailsChkbox ").checked = true;
    }

    if (this.uprop_cEmail_autoAssociateChkbx) {
    document.getElementById("cEmail_autoAssociateChkbx ").checked = true;
    }
    if (this.uprop_cEmail_useAutoAssociatedEmailsChkbx) {
    document.getElementById("cEmail_useAutoAssociatedE mailsChkbx").checked = true;
    }

    document.getElementById("cEmail_manualAddedEmails" ).value = this.uprop_cEmail_manualAddedEmails;
    document.getElementById("cEmail_autoAddedEmails"). value = this.uprop_cEmail_autoAddedEmails;

    this._fontColorButton.setColor("#009900");
    this._fontBackgroundButton.setColor("#FFFFFF");
    this._emailAndColorBtnListener();
    };

    com_zimbra_coloredemails.prototype._okPreferenceBt nListener =
    function() {
    this._addButtonListener(false);//people might forget to press Add button, so try to add them
    this._reloadRequired = false;
    if (document.getElementById("turnONColoredEmailsChkbo x").checked) {
    if (!this.turnColoredEmailsZimletON) {
    this._reloadRequired = true;
    }
    this.setUserProperty("turnColoredEmailsZimletON", "true", true);

    } else {
    this.setUserProperty("turnColoredEmailsZimletON", "false", true);
    if (this.turnColoredEmailsZimletON)
    this._reloadRequired = true;
    }


    if (document.getElementById("cEmail_useAutoAssociated EmailsChkbx").checked) {
    if (!this.uprop_cEmail_useAutoAssociatedEmailsChkbx) {
    this._reloadRequired = true;
    }
    this.setUserProperty("cEmail_useAutoAssociatedEmai lsChkbx", "true", true);

    } else {
    this.setUserProperty("cEmail_useAutoAssociatedEmai lsChkbx", "false", true);
    if (this.uprop_cEmail_useAutoAssociatedEmailsChkbx)
    this._reloadRequired = true;
    }
    if (document.getElementById("cEmail_autoAssociateChkb x").checked) {
    if (!this.uprop_cEmail_autoAssociateChkbx) {
    this._reloadRequired = true;
    }
    this.setUserProperty("cEmail_autoAssociateChkbx", "true", true);

    } else {
    this.setUserProperty("cEmail_autoAssociateChkbx", "false", true);
    if (this.uprop_cEmail_autoAssociateChkbx)
    this._reloadRequired = true;
    }

    this.setUserProperty("cEmail_manualAddedEmails", document.getElementById("cEmail_manualAddedEmails" ).value, true);
    this.uprop_cEmail_autoAddedEmails = document.getElementById("cEmail_autoAddedEmails"). value;
    this._saveAutoAddedEmails();
    //reset the values and run getMsg to instantly reflect the changes
    this._cEmail_manualAddedEmailsArray = [];
    this._setEmails(this._cEmail_manualAddedEmailsArra y, document.getElementById("cEmail_manualAddedEmails" ).value);
    this._resetView();

    appCtxt.getAppController().setStatusMsg("Changes are Saved", ZmStatusView.LEVEL_INFO);

    this._preferenceDialog.popdown();
    if (this._reloadRequired) {
    var transitions = [ ZmToast.FADE_IN, ZmToast.PAUSE, ZmToast.PAUSE, ZmToast.PAUSE, ZmToast.FADE_OUT ];
    appCtxt.getAppController().setStatusMsg("Browser will be refreshed for changes to take effect..", ZmStatusView.LEVEL_INFO, null, transitions);
    setTimeout(AjxCallback.simpleClosure(this._reloadB rowser, this), 5000);
    }
    };

    com_zimbra_coloredemails.prototype._reloadBrowser =
    function() {
    window.onbeforeunload = null;
    var url = AjxUtil.formatUrl({});
    ZmZimbraMail.sendRedirect(url);
    };

Similar Threads

  1. Filter incoming mail by address book
    By kilrathi in forum Administrators
    Replies: 1
    Last Post: 02-21-2013, 09:25 PM
  2. Replies: 0
    Last Post: 01-08-2010, 07:57 AM
  3. Replies: 7
    Last Post: 10-14-2009, 12:52 PM
  4. Add Color & Address Book to Filter Options
    By Tylast in forum General Questions
    Replies: 0
    Last Post: 07-25-2008, 12:02 PM
  5. Deploy address book to all mail address
    By stich86 in forum Administrators
    Replies: 2
    Last Post: 03-28-2008, 06:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •