This is just some static backup of the original site, don't expect every link to work!

source: modules/plugins/conversations.js @ 11bc96d

ng_0.9
Last change on this file since 11bc96d was 11bc96d, checked in by rene <rene@…>, 10 years ago

adaptions for new seamonkey (not finished)

  • Property mode set to 100644
File size: 9.9 KB
Line 
1/* ***** BEGIN LICENSE BLOCK *****
2    This program is free software; you can redistribute it and/or modify
3    it under the terms of the GNU General Public License as published by
4    the Free Software Foundation; either version 2 of the License, or
5    (at your option) any later version.
6
7    This program is distributed in the hope that it will be useful,
8    but WITHOUT ANY WARRANTY; without even the implied warranty of
9    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10    GNU General Public License for more details.
11
12    You should have received a copy of the GNU General Public License
13    along with this program; if not, write to the Free Software
14    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
15
16    The Original Code is the Virtual Identity Extension.
17
18    The Initial Developer of the Original Code is Rene Ejury.
19    Portions created by the Initial Developer are Copyright (C) 2007
20    the Initial Developer. All Rights Reserved.
21
22    Contributor(s):
23 * ***** END LICENSE BLOCK ***** */
24 
25var EXPORTED_SYMBOLS = [];
26
27const {classes: Cc, interfaces: Ci, utils: Cu, results : Cr} = Components;
28
29Cu.import("resource://v_identity/vI_log.js");
30Cu.import("resource://v_identity/vI_rdfDatasource.js");
31Cu.import("resource://v_identity/vI_account.js");
32Cu.import("resource://v_identity/vI_smartIdentityCollection.js");
33Cu.import("resource://v_identity/vI_identityData.js");
34Cu.import("resource://v_identity/vI_prefs.js");
35
36let Log = setupLogging("virtualIdentity.plugins.conversations");
37
38const AccountManager = Cc["@mozilla.org/messenger/account-manager;1"]
39  .getService(Components.interfaces.nsIMsgAccountManager);
40 
41const HeaderParser = Cc["@mozilla.org/messenger/headerparser;1"]
42  .getService(Ci.nsIMsgHeaderParser);
43
44let currentIdentityData;
45let currentIdSenderName;
46let virtualIdInUse;
47let virtualSenderNameElem;
48
49let _rdfDatasourceAccess;
50
51let changeIdentityToSmartIdentity = function(allIdentities, index) {
52  _changeIdentityToSmartIdentity(allIdentities.identityDataCollection[index]);
53};
54
55let _changeIdentityToSmartIdentity = function(identityData) {
56  Log.debug("changeIdentityToSmartIdentity");
57 
58  if ( identityData.id.key != null ) {
59    currentParams.identity = AccountManager.getIdentity(identityData.id.key);
60    Log.debug("changed base identity to ", identityData.id.key);
61    virtualSenderNameElem.text(currentIdSenderName);
62  }
63  virtualIdInUse = !(identityData.isExistingIdentity(false));
64  Log.debug("changeIdentityToSmartIdentity virtualIdInUse=" + virtualIdInUse);
65  if (virtualIdInUse) {
66    currentIdentityData = identityData;
67    currentIdSenderName = currentIdentityData.combinedName;
68  }
69  virtualSenderNameElem.text(identityData.combinedName); // change this also to reflect changes of base id
70};
71
72let virtualIdentityHook = {
73  onComposeSessionChanged: function _virtualIdentityHook_onComposeSessionChanged(aComposeSession, aMessage, aAddress) {
74    let toAddrList = aAddress.to.concat(aAddress.cc);
75   
76    currentParams = aComposeSession.params; virtualSenderNameElem = aComposeSession.senderNameElem; // to enable access from out of this class.
77    let identity = aComposeSession.params.identity;
78   
79    if (typeof(this._AccountManager.getServersForIdentity) == 'function') { // new style
80        let server = this._AccountManager.getServersForIdentity(identity).queryElementAt(0, Components.interfaces.nsIMsgIncomingServer);
81    } else {
82        let server = this._AccountManager.GetServersForIdentity(identity).QueryElementAt(0, Components.interfaces.nsIMsgIncomingServer);
83    }
84
85    currentIdentityData = new identityData(identity.email, identity.fullName, identity.key,
86                                                                    identity.smtpServerKey, null, server.prettyName, true)
87    currentIdSenderName = currentIdentityData.combinedName;
88    virtualIdInUse = false;
89   
90    let recipients = []; var combinedNames = {}; var number;
91    number = HeaderParser.parseHeadersWithArray(toAddrList.join(", "), {}, {}, combinedNames);
92    for (var index = 0; index < number; index++)
93      recipients.push( { recipient: combinedNames.value[index], recipientType: "addr_to" } )
94     
95    var localSmartIdentityCollection = new smartIdentityCollection(aComposeSession.params.msgHdr, identity, 
96                                                                      false, false, recipients);
97    localSmartIdentityCollection.Reply();   // we can always use the reply-case, msgHdr is set the right way
98   
99    if (localSmartIdentityCollection._allIdentities.number == 0)
100      return;
101 
102    if (vIprefs.get("idSelection_preferExisting")) {
103      var existingIDIndex = localSmartIdentityCollection._foundExistingIdentity();
104      if (existingIDIndex) {
105        Log.debug("smartIdentity: found existing Identity, use without interaction.", existingIDIndex.key);
106        changeIdentityToSmartIdentity(localSmartIdentityCollection._allIdentities, existingIDIndex.key);
107        return;
108      }
109    }
110
111    if (vIprefs.get("idSelection_ask") && 
112      ((localSmartIdentityCollection._allIdentities.number == 1 && vIprefs.get("idSelection_ask_always"))
113      || localSmartIdentityCollection._allIdentities.number > 1)) {
114        recentWindow = Cc["@mozilla.org/appshell/window-mediator;1"]
115          .getService(Ci.nsIWindowMediator)
116          .getMostRecentWindow("mail:3pane");
117     
118        recentWindow.openDialog("chrome://v_identity/content/vI_smartReplyDialog.xul",0,
119          "chrome, dialog, modal, alwaysRaised, resizable=yes",
120          localSmartIdentityCollection._allIdentities,
121          /* callback: */ changeIdentityToSmartIdentity).focus();
122      }
123    else if (vIprefs.get("idSelection_autocreate"))
124      changeIdentityToSmartIdentity(localSmartIdentityCollection._allIdentities, 0);
125  },
126 
127  onMessageBeforeSendOrPopout_canceled: function _enigmailHook_onMessageBeforeSendOrPopout_canceledy(aAddress, aEditor, aStatus, aPopout) {
128    Log.debug("onMessageBeforeSendOrPopout_canceled");
129    return aStatus;
130
131  },
132  onMessageBeforeSendOrPopout: function _enigmailHook_onMessageBeforeSendOrPopout(aAddress, aEditor, aStatus, aPopout) {
133    Log.debug("onMessageBeforeSendOrPopout");
134    return aStatus;
135
136  },
137  onMessageBeforeSendOrPopout_early: function _enigmailHook_onMessageBeforeSendOrPopout_early(aAddress, aEditor, aStatus, aPopout) {
138    if (aStatus.canceled)
139      return aStatus;
140
141    let toAddrList = aAddress.to.concat(aAddress.cc);
142    Log.debug("onMessageBeforeSendOrPopup_early");
143   
144    if (virtualIdInUse) {
145      if (!aPopout) {
146        let recipients = []; var combinedNames = {}; var number;
147        number = HeaderParser.parseHeadersWithArray(toAddrList.join(", "), {}, {}, combinedNames);
148        for (var index = 0; index < number; index++)
149          recipients.push( { recipient: combinedNames.value[index], recipientType: "addr_to" } )
150       
151        let recentWindow = Cc["@mozilla.org/appshell/window-mediator;1"]
152          .getService(Ci.nsIWindowMediator)
153          .getMostRecentWindow("mail:3pane");
154         
155        returnValue = vIaccount_prepareSendMsg(virtualIdInUse, Ci.nsIMsgCompDeliverMode.Now,
156          currentIdentityData, aAddress.params.identity, recipients, recentWindow);
157        Log.debug("returnValue.update:", returnValue.update);
158       
159        if (returnValue.update == "abort") {
160          aStatus.canceled = true; return aStatus;
161        }
162        else if (returnValue.update == "takeover") {
163          _changeIdentityToSmartIdentity(returnValue.storedIdentity);
164          aStatus.canceled = true; return aStatus;
165        }
166       
167        aAddress.params.identity = get_vIaccount().defaultIdentity;
168        if (!vIaccount_finalCheck(currentIdentityData, aAddress.params.identity)) {
169          vIaccount_removeUsedVIAccount();
170          aStatus.canceled = true; return aStatus;
171        }
172      }
173      else {
174        // code virtual Identity into subject - this will be decoded by smartIdentity - newMail
175        aAddress.params.subject = aAddress.params.subject + "\nvirtualIdentityExtension\n" + currentIdSenderName;
176        Log.debug("coding virtualIdentity into subject:", aAddress.params.subject);
177      }
178    }
179    Log.debug("onSendMessage done");
180    return aStatus;
181  },
182 
183  onStopSending: function _virtualIdentityHook_onStopSending(aMsgID, aStatus, aMsg, aReturnFile) {
184    vIaccount_removeUsedVIAccount();
185    Log.debug("onStopSending done");
186  },
187
188  onRecipientAdded: function _virtualIdentityHook_onRecipientAdded(aData, aType, aCount) {
189    Log.debug("onRecipientAdded", aData.data, aType, aCount);
190    if (!vIprefs.get("storage")) return;
191    if (aType == "bcc") return;
192    if (aData.data == "") return;
193
194    // if we are editing the "cc" or not the first recipient, recognize this.
195    var isNotFirstInputElement = !(aType == "to" && aCount == 0);
196    Log.debug("onRecipientAdded isNotFirstInputElement", isNotFirstInputElement);
197   
198    if (!_rdfDatasourceAccess) _rdfDatasourceAccess = new rdfDatasourceAccess();
199    else _rdfDatasourceAccess.clean();
200
201    let recentWindow = Cc["@mozilla.org/appshell/window-mediator;1"]
202          .getService(Ci.nsIWindowMediator)
203          .getMostRecentWindow("mail:3pane");
204
205    var storageResult = _rdfDatasourceAccess.updateVIdentityFromStorage(aData.data, "addr_to",
206      currentIdentityData, virtualIdInUse, isNotFirstInputElement, recentWindow);
207   
208    if (storageResult.identityCollection.number == 0) return; // return if there was no match
209    if (storageResult.result != "accept") return; // return if we don't like the resulting id
210   
211    changeIdentityToSmartIdentity(storageResult.identityCollection, 0);
212  }
213}
214
215try {
216  Cu.import("resource://conversations/modules/hook.js");
217  mainWindow = Cc["@mozilla.org/appshell/window-mediator;1"]
218    .getService(Ci.nsIWindowMediator)
219    .getMostRecentWindow("mail:3pane");
220  mainWindow.addEventListener("load", function () {
221    Log.debug("Virtual Identity plugin for Thunderbird Conversations loaded!");
222    registerHook(virtualIdentityHook);
223  }, false);
224}
225catch(e) {
226  Log.debug("virtualIdentity is ready for conversations, but you don't use it");
227}
Note: See TracBrowser for help on using the repository browser.