From 3166d9c170b80cd22c79a56c01a3d3ceb4fae09d Mon Sep 17 00:00:00 2001 From: barrydegraaff Date: Fri, 3 Jul 2015 20:42:42 +0200 Subject: [PATCH] add new version of unsubscribe zimlet that uses a button that is next to the spam button --- tk_barrydegraaff_list_unsubscribe.js | 133 ++++++++++++++++++-------- tk_barrydegraaff_list_unsubscribe.xml | 2 +- tk_barrydegraaff_list_unsubscribe.zip | Bin 2016 -> 2468 bytes 3 files changed, 92 insertions(+), 43 deletions(-) mode change 100755 => 100644 tk_barrydegraaff_list_unsubscribe.js mode change 100755 => 100644 tk_barrydegraaff_list_unsubscribe.xml diff --git a/tk_barrydegraaff_list_unsubscribe.js b/tk_barrydegraaff_list_unsubscribe.js old mode 100755 new mode 100644 index 4cc99ce..dc761c1 --- a/tk_barrydegraaff_list_unsubscribe.js +++ b/tk_barrydegraaff_list_unsubscribe.js @@ -28,10 +28,9 @@ tk_barrydegraaff_list_unsubscribe_HandlerObject.prototype.constructor = tk_barry /** * Simplify handler object - * */ var List_UnsubscribeZimlet = tk_barrydegraaff_list_unsubscribe_HandlerObject; - +ZmArchiveZimlet.OP_UNSUBSCRIBE = "OP_UNSUBSCRIBE"; /** * Initializes the zimlet. */ @@ -49,57 +48,107 @@ function() { ZmMailMsg.requestHeaders["List-Unsubscribe"] = "List-Unsubscribe"; }; -List_UnsubscribeZimlet.prototype.onMsgView = function (msg, oldMsg, msgView) { - if(appCtxt.getCurrentAppName()=='Mail') - { - //Remove Zimlets infobar from previous message - try { - var elem = document.getElementById("tk_barrydegraaff_list_unsubscribe_actionbar"); - elem.parentNode.removeChild(elem); - } catch (err) {} - - //Create new empty infobar for display - var el = msgView.getHtmlElement(); - - var g=document.createElement('div'); - g.setAttribute("id", "tk_barrydegraaff_list_unsubscribe_actionbar"); - el.insertBefore(g, el.firstChild); +/* + * + */ +List_UnsubscribeZimlet.prototype.initializeToolbar = +function(app, toolbar, controller, viewId) { + console.log(toolbar); + // bug fix #7192 - disable detach toolbar button + toolbar.enable(ZmOperation.DETACH_COMPOSE, false); + if(viewId.indexOf("CLV-main") >=0){ + if (toolbar.getButton('List_UnsubscribeZimletButton')) + { + //button already defined + return; + } + var buttonArgs = { + text : 'Unsubscribe', + tooltip: 'Unsubscribe from mailing', + index: 8, //position of the button + image: "zimbraicon", //icon + enabled: false + }; + var button = toolbar.createOp("List_UnsubscribeZimletButton", buttonArgs); + button.addSelectionListener(new AjxListener(this, this._handleList_UnsubscribeZimletMenuClick, controller)); + //button.setEnabled(false); + } +}; + +List_UnsubscribeZimlet.prototype._handleList_UnsubscribeZimletMenuClick = function(controller) { + var items = controller.getSelection(); + if(!items instanceof Array) { + this._showOneClickDlg(""); + return; + } + var type = items[0].type; + var msg; + if (type == ZmId.ITEM_CONV) { + msg = items[0].getFirstHotMsg(); + } else if(type == ZmId.ITEM_MSG) { + msg = items[0]; + } - } - try { if(msg.attrs['List-Unsubscribe'].indexOf('http') > 0) { + var listUnsubscribe = msg.attrs['List-Unsubscribe']; + + var httpRegEx = new RegExp('(\<)(http.*?)(\>)'); + var listUnsubscribeHttp = listUnsubscribe.match(httpRegEx) - if(document.getElementById('tk_barrydegraaff_zimbra_openpgp_actionbar')) + var mailtoRegEx = new RegExp('(\<)(mailto.*?)(\>)'); + var listUnsubscribemailto = listUnsubscribe.match(mailtoRegEx) + + // window.open/location is a bit ugly, + // if you want to change this, please read the RFC: http://www.faqs.org/rfcs/rfc2369.html + // The below trick using ?view= also parses any subject that may be in the unsubscribe header, + // body of the mail is not implemented, as I don't think much systems use that. + if (listUnsubscribemailto) { - if(document.getElementById('main_MSGC'+msg.id)) - { - var listUnsubscribe = msg.attrs['List-Unsubscribe']; - - var httpRegEx = new RegExp('(\<)(http.*?)(\>)'); - var listUnsubscribeHttp = listUnsubscribe.match(httpRegEx) - - var mailtoRegEx = new RegExp('(\<)(mailto.*?)(\>)'); - var listUnsubscribemailto = listUnsubscribe.match(mailtoRegEx) - - if(document.getElementById('tk_barrydegraaff_zimbra_openpgp_actionbar')) - { - if (listUnsubscribemailto) - { - document.getElementById('tk_barrydegraaff_zimbra_openpgp_actionbar').innerHTML = '","").replace("<","").replace("mailto:","").replace("?","&")+'">Unsubscribe'; - } - else if (listUnsubscribeHttp) - { - document.getElementById('tk_barrydegraaff_zimbra_openpgp_actionbar').innerHTML = '","").replace("<","")+'">Unsubscribe'; - } - } - } + window.location='?view=compose&to='+listUnsubscribemailto[0].replace(">","").replace("<","").replace("mailto:","").replace("?","&").replace("+","%2B"); + } + else if (listUnsubscribeHttp) + { + window.open(listUnsubscribeHttp[0].replace(">","").replace("<","")); } } } catch (err) { // List-Unsubscribe header not found } +}; + +List_UnsubscribeZimlet.prototype.onMsgView = function (msg, oldMsg, msgView) { + console.log(appCtxt.getAppViewMgr().getCurrentViewId()); + try + { + if(msg.attrs['List-Unsubscribe']) + { + var listUnsubscribe = msg.attrs['List-Unsubscribe']; + + var httpRegEx = new RegExp('(\<)(http.*?)(\>)'); + var listUnsubscribeHttp = listUnsubscribe.match(httpRegEx) + + var mailtoRegEx = new RegExp('(\<)(mailto.*?)(\>)'); + var listUnsubscribemailto = listUnsubscribe.match(mailtoRegEx) + + if (listUnsubscribemailto || listUnsubscribeHttp) + { + console.log('true'); + } + else + { + console.log('fasle'); + } + } + else + { + console.log('fasle2'); + } + } catch (err) + { + // List-Unsubscribe header not found + } } diff --git a/tk_barrydegraaff_list_unsubscribe.xml b/tk_barrydegraaff_list_unsubscribe.xml old mode 100755 new mode 100644 index e39b394..02b079f --- a/tk_barrydegraaff_list_unsubscribe.xml +++ b/tk_barrydegraaff_list_unsubscribe.xml @@ -1,4 +1,4 @@ - + tk_barrydegraaff_list_unsubscribe.js tk_barrydegraaff_list_unsubscribe_HandlerObject diff --git a/tk_barrydegraaff_list_unsubscribe.zip b/tk_barrydegraaff_list_unsubscribe.zip index 498dc0ca9861c09b1dae23891abf943aa0509f9c..efe53df665fd405ce126e9eae971be987ce82878 100644 GIT binary patch delta 2258 zcmV;@2rc*E52O@6aWAK2mn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