Difference between revisions of "Zimlet cookbook based on JavaScript API"
(→Mail) |
(→Mail) |
||
Line 17: | Line 17: | ||
</pre> | </pre> | ||
− | The email dropped(zmObject) can be either a conversation or a single email. This zmObject internally has an object called 'srcObj' ( | + | The email dropped(zmObject) can be either a conversation or a single email. This zmObject internally has an object called 'srcObj' (source-object) and contains the real or actual Zimbra Object that was dropped. Once we get access to this, we can access all the properties and even functions. |
<pre> | <pre> | ||
com_zimbra_coloredemails.prototype.doDrop = | com_zimbra_coloredemails.prototype.doDrop = | ||
Line 23: | Line 23: | ||
var msgObj = zmObject.srcObj;//get access to source-object | var msgObj = zmObject.srcObj;//get access to source-object | ||
− | + | //if its a conversation i.e. "ZmConv" object, get the first loaded message "ZmMailMsg" object within that. | |
− | msgObj = zmObject.getFirstHotMsg(); | + | if (zmObject.type == "CONV") { |
+ | msgObj = zmObject.getFirstHotMsg(); | ||
} | } | ||
− | |||
− | |||
− | |||
}; | }; | ||
+ | </pre> | ||
+ | |||
+ | |||
+ | At this point we have a single message "ZmMailMsg" object and we can access all its properties. | ||
+ | |||
+ | ====Get mail subject==== | ||
+ | <pre> | ||
+ | var subject = msgObj.subject; //where msgObj is of typu "ZmMailMsg" | ||
+ | <pre> | ||
+ | ====Get all email addresses==== | ||
+ | <pre> | ||
+ | var emails = [];//stores all email address in the email | ||
+ | var participants = msgObj.participants.getArray(); | ||
+ | for(var i =0; i < participants.length; i++) { | ||
+ | emails.push(participants[i].address); | ||
+ | } | ||
+ | </pre> | ||
+ | |||
+ | ====Get email addresses only in CC==== | ||
+ | <pre> | ||
+ | var ccemails = [];//stores all email address in the email | ||
+ | var participants = msgObj.participants.getArray(); | ||
+ | for(var i =0; i < participants.length; i++) { | ||
+ | if(participants[i].type == AjxEmailAddress.CC) { | ||
+ | ccemails.push(participants[i].address); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | PS: Email address type can be any of the following: | ||
+ | AjxEmailAddress.FROM = "FROM"; | ||
+ | AjxEmailAddress.TO = "TO"; | ||
+ | AjxEmailAddress.CC = "CC"; | ||
+ | AjxEmailAddress.BCC = "BCC"; | ||
+ | AjxEmailAddress.REPLY_TO = "REPLY_TO"; | ||
+ | AjxEmailAddress.SENDER = "SENDER"; | ||
</pre> | </pre> | ||
Revision as of 05:41, 31 March 2009
Contents
1. How to get access to an email's to,cc,bcc,subject, body information when its drag-dropped onto Zimlet's panel Item? First off we need to allow message(ZmMailMsg) or conversation(ZmConv) to be dragged onto Zimlet Panel Item.
<zimletPanelItem label="Zimlet Name" icon="Zimlet-panelIcon"> <dragSource type="ZmConv" /> <dragSource type="ZmMailMsg" /> </zimletPanelItem>
Then, within the Zimlet's Javascript file, we need to override 'doDrop' function.
com_zimbra_coloredemails.prototype.doDrop = function(zmObject) { };
The email dropped(zmObject) can be either a conversation or a single email. This zmObject internally has an object called 'srcObj' (source-object) and contains the real or actual Zimbra Object that was dropped. Once we get access to this, we can access all the properties and even functions.
com_zimbra_coloredemails.prototype.doDrop = function(zmObject) { var msgObj = zmObject.srcObj;//get access to source-object //if its a conversation i.e. "ZmConv" object, get the first loaded message "ZmMailMsg" object within that. if (zmObject.type == "CONV") { msgObj = zmObject.getFirstHotMsg(); } };
At this point we have a single message "ZmMailMsg" object and we can access all its properties.
Get mail subject
var subject = msgObj.subject; //where msgObj is of typu "ZmMailMsg" <pre> ====Get all email addresses==== <pre> var emails = [];//stores all email address in the email var participants = msgObj.participants.getArray(); for(var i =0; i < participants.length; i++) { emails.push(participants[i].address); }
Get email addresses only in CC
var ccemails = [];//stores all email address in the email var participants = msgObj.participants.getArray(); for(var i =0; i < participants.length; i++) { if(participants[i].type == AjxEmailAddress.CC) { ccemails.push(participants[i].address); } } PS: Email address type can be any of the following: AjxEmailAddress.FROM = "FROM"; AjxEmailAddress.TO = "TO"; AjxEmailAddress.CC = "CC"; AjxEmailAddress.BCC = "BCC"; AjxEmailAddress.REPLY_TO = "REPLY_TO"; AjxEmailAddress.SENDER = "SENDER";