Skip to content

Commit

Permalink
add new version of unsubscribe zimlet that uses a button that is next…
Browse files Browse the repository at this point in the history
… to the spam button
  • Loading branch information
barrydegraaff committed Jul 3, 2015
1 parent c572a58 commit 3166d9c
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 43 deletions.
133 changes: 91 additions & 42 deletions tk_barrydegraaff_list_unsubscribe.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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 = '<a target="_blank" href="?view=compose&to='+listUnsubscribemailto[0].replace(">","").replace("<","").replace("mailto:","").replace("?","&")+'">Unsubscribe</a>';
}
else if (listUnsubscribeHttp)
{
document.getElementById('tk_barrydegraaff_zimbra_openpgp_actionbar').innerHTML = '<a target="_blank" href="'+listUnsubscribeHttp[0].replace(">","").replace("<","")+'">Unsubscribe</a>';
}
}
}
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
}
}
2 changes: 1 addition & 1 deletion tk_barrydegraaff_list_unsubscribe.xml
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<zimlet name="tk_barrydegraaff_list_unsubscribe" version="0.1" label="Display an Unsubscribe button in Zimbra based on the List-Unsubscribe header" description="Display an Unsubscribe button in Zimbra based on the List-Unsubscribe header" target="main view-window">
<zimlet name="tk_barrydegraaff_list_unsubscribe" version="0.2" label="Display an Unsubscribe button in Zimbra based on the List-Unsubscribe header" description="Display an Unsubscribe button in Zimbra based on the List-Unsubscribe header" target="main view-window">
<include>tk_barrydegraaff_list_unsubscribe.js</include>
<handlerObject>tk_barrydegraaff_list_unsubscribe_HandlerObject</handlerObject>
</zimlet>
Binary file modified tk_barrydegraaff_list_unsubscribe.zip
Binary file not shown.

0 comments on commit 3166d9c

Please sign in to comment.