Skip to content

Commit

Permalink
add first version of list_unsubscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
Barry de Graaff committed Jul 2, 2015
1 parent 32d4052 commit 3e6f806
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
# list-unsubscribe-zimlet
Zimbra list-unsubscribe Zimlet

Implements an Unsubscribe button in Zimbra based on the List-Unsubscribe header
as defined by http://www.list-unsubscribe.com/ or RFC 2369




License

Copyright (C) 2014-2015 Barry de Graaff

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Binary file added list-unsubscribe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/test-list-unsubscribe-2015-07-02-142825.tgz
Binary file not shown.
105 changes: 105 additions & 0 deletions tk_barrydegraaff_list_unsubscribe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
This file is part of the list-unsubscribe Zimlet.
Copyright (C) 2015 Barry de Graaff
Bugs and feedback: https://github.com/barrydegraaff/list-unsubscribe-zimlet
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
*/
/**
* This zimlet checks for List-Unsubscribe message header and displays unsubscribe button when found.
*/
function tk_barrydegraaff_list_unsubscribe_HandlerObject() {
}

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

/**
* Simplify handler object
*
*/
var List_UnsubscribeZimlet = tk_barrydegraaff_list_unsubscribe_HandlerObject;

/**
* Initializes the zimlet.
*/
List_UnsubscribeZimlet.prototype.init =
function() {
AjxPackage.require({name:"MailCore", callback:new AjxCallback(this, this._applyRequestHeaders)});
};

/**
* Applies the request headers.
*
*/
List_UnsubscribeZimlet.prototype._applyRequestHeaders =
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);

}

try
{
if(msg.attrs['List-Unsubscribe'].indexOf('http') > 0)
{

if(document.getElementById('tk_barrydegraaff_zimbra_openpgp_actionbar'))
{
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>';
}
}
}
}
}
} catch (err)
{
// List-Unsubscribe header not found
}
}
4 changes: 4 additions & 0 deletions tk_barrydegraaff_list_unsubscribe.xml
Original file line number Diff line number Diff line change
@@ -0,0 +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">
<include>tk_barrydegraaff_list_unsubscribe.js</include>
<handlerObject>tk_barrydegraaff_list_unsubscribe_HandlerObject</handlerObject>
</zimlet>
Binary file added tk_barrydegraaff_list_unsubscribe.zip
Binary file not shown.

0 comments on commit 3e6f806

Please sign in to comment.