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

source: content/modules/plugins/conversation.js @ 184c6c

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

rearranged tree structure / added build-script

  • Property mode set to 100644
File size: 7.0 KB
Line 
1virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) {
2
3const Ci = Components.interfaces;
4const Cc = Components.classes;
5const Cu = Components.utils;
6
7let pref = Cc["@mozilla.org/preferences-service;1"]
8  .getService(Components.interfaces.nsIPrefService)
9  .getBranch("extensions.virtualIdentity.");
10
11const AccountManager = Cc["@mozilla.org/messenger/account-manager;1"]
12  .getService(Components.interfaces.nsIMsgAccountManager);
13 
14const HeaderParser = Cc["@mozilla.org/messenger/headerparser;1"]
15  .getService(Ci.nsIMsgHeaderParser);
16
17let currentIdentityData;
18let currentIdSenderName;
19let virtualIdInUse;
20let virtualSenderNameElem;
21let Log;
22let _rdfDatasourceAccess;
23
24let changeIdentityToSmartIdentity = function(allIdentities, index) {
25  _changeIdentityToSmartIdentity(allIdentities.identityDataCollection[index]);
26};
27
28let _changeIdentityToSmartIdentity = function(identityData) {
29  Log.debug("## changeIdentityToSmartIdentity\n");
30 
31  if ( identityData.id.key != null ) {
32    currentParams.identity = AccountManager.getIdentity(identityData.id.key);
33    Log.debug("## changed base identity to ", identityData.id.key);
34    virtualSenderNameElem.text(currentIdSenderName);
35  }
36  virtualIdInUse = !(identityData.isExistingIdentity(false));
37  Log.debug("## changeIdentityToSmartIdentity virtualIdInUse=" + virtualIdInUse + "\n");
38  if (virtualIdInUse) {
39    currentIdentityData = identityData;
40    currentIdSenderName = currentIdentityData.combinedName;
41  }
42  virtualSenderNameElem.text(identityData.combinedName); // change this also to reflect changes of base id
43};
44
45let conversationHook = {
46  onComposeSessionChanged: function (aComposeSession, aAddress, ExternalLog) {
47    Log = ExternalLog;
48    let toAddrList = aAddress.to.concat(aAddress.cc);
49   
50    currentParams = aComposeSession.params; virtualSenderNameElem = aComposeSession.senderNameElem; // to enable access from out of this class.
51    let identity = aComposeSession.params.identity;
52   
53    let server = AccountManager.GetServersForIdentity(identity).QueryElementAt(0, Components.interfaces.nsIMsgIncomingServer);
54    currentIdentityData = new virtualIdentityExtension.identityData(identity.email, identity.fullName, identity.key,
55                                                                    identity.smtpServerKey, null, server.prettyName, true)
56    currentIdSenderName = currentIdentityData.combinedName;
57    virtualIdInUse = false;
58   
59    let recipients = []; var combinedNames = {}; var number;
60    number = HeaderParser.parseHeadersWithArray(toAddrList.join(", "), {}, {}, combinedNames);
61    for (var index = 0; index < number; index++)
62      recipients.push( { recipient: combinedNames.value[index], recipientType: "addr_to" } )
63     
64    var localSmartIdentityCollection = new vI.smartIdentityCollection(aComposeSession.params.msgHdr, identity, 
65                                                                      false, false, recipients);
66    localSmartIdentityCollection.Reply();   // we can always use the reply-case, msgHdr is set the right way
67   
68    if (localSmartIdentityCollection._allIdentities.number == 0)
69      return;
70 
71    if (pref.getBoolPref("idSelection_preferExisting")) {
72      var existingIDIndex = localSmartIdentityCollection._foundExistingIdentity();
73      if (existingIDIndex) {
74        Log.debug("## smartIdentity: found existing Identity, use without interaction.\n", existingIDIndex.key);
75        changeIdentityToSmartIdentity(localSmartIdentityCollection._allIdentities, existingIDIndex.key);
76        return;
77      }
78    }
79
80    if (pref.getBoolPref("idSelection_ask") && 
81      ((localSmartIdentityCollection._allIdentities.number == 1 && pref.getBoolPref("idSelection_ask_always"))
82      || localSmartIdentityCollection._allIdentities.number > 1)) {
83        window.openDialog("chrome://v_identity/content/vI_smartReplyDialog.xul",0,
84          "chrome, dialog, modal, alwaysRaised, resizable=yes",
85          localSmartIdentityCollection._allIdentities,
86          /* callback: */ changeIdentityToSmartIdentity).focus();
87      }
88    else if (pref.getBoolPref("idSelection_autocreate"))
89      changeIdentityToSmartIdentity(localSmartIdentityCollection._allIdentities, 0);
90  },
91 
92  onMessageBeforeSendOrPopout: function(aAddress, aStatus, aPopout, ExternalLog) {
93    Log = ExternalLog;
94    let toAddrList = aAddress.to.concat(aAddress.cc);
95    Log.debug("## onMessageBeforeSendOrPopup");
96   
97    if (virtualIdInUse) {
98      if (!aPopout) {
99        let recipients = []; var combinedNames = {}; var number;
100        number = HeaderParser.parseHeadersWithArray(toAddrList.join(", "), {}, {}, combinedNames);
101        for (var index = 0; index < number; index++)
102          recipients.push( { recipient: combinedNames.value[index], recipientType: "addr_to" } )
103
104        returnValue = vI.prepareSendMsg(virtualIdInUse, Ci.nsIMsgCompDeliverMode.Now,
105          currentIdentityData, aAddress.params.identity, recipients );
106        Log.debug("returnValue.update:", returnValue.update);
107       
108        if (returnValue.update == "abort") {
109          aStatus.canceled = true; return aStatus;
110        }
111        else if (returnValue.update == "takeover") {
112          _changeIdentityToSmartIdentity(returnValue.storedIdentity);
113          aStatus.canceled = true; return aStatus;
114        }
115       
116        aAddress.params.identity = vI.account._account.defaultIdentity
117        if (!vI.finalCheck(currentIdentityData, aAddress.params.identity)) {
118          vI.account.removeUsedVIAccount();
119          aStatus.canceled = true; return aStatus;
120        }
121      }
122      else {
123        // code virtual Identity into subject - this will be decoded by smartIdentity - newMail
124        aAddress.params.subject = aAddress.params.subject + "\nvirtualIdentityExtension\n" + currentIdSenderName;
125        Log.debug("coding virtualIdentity into subject:", aAddress.params.subject);
126      }
127    }
128    Log.debug("onSendMessage done");
129    return aStatus;
130  },
131 
132  onStopSending: function () {
133    vI.account.removeUsedVIAccount();
134    Log.debug("onStopSending done");
135  },
136
137  onRecipientAdded: function onRecipientAdded(aData, aType, aCount, ExternalLog) {
138    Log = ExternalLog;
139   
140    Log.debug("onRecipientAdded", aData.data, aType, aCount);
141    if (!pref.getBoolPref("storage")) return;
142    if (aType == "bcc") return;
143    if (aData.data == "") return;
144
145    // if we are editing the "cc" or not the first recipient, recognize this.
146    var isNotFirstInputElement = !(aType == "to" && aCount == 0);
147    Log.debug("onRecipientAdded isNotFirstInputElement", isNotFirstInputElement);
148   
149    if (!_rdfDatasourceAccess) _rdfDatasourceAccess = new vI.rdfDatasourceAccess();
150    else _rdfDatasourceAccess.clean();
151   
152    var storageResult = _rdfDatasourceAccess.updateVIdentityFromStorage(aData.data, "addr_to",
153      currentIdentityData, virtualIdInUse, isNotFirstInputElement);
154   
155    if (storageResult.identityCollection.number == 0) return; // return if there was no match
156    if (storageResult.result != "accept") return; // return if we don't like the resulting id
157   
158    changeIdentityToSmartIdentity(storageResult.identityCollection, 0);
159  }
160}
161
162vI.conversationHook = conversationHook;
163}});
Note: See TracBrowser for help on using the repository browser.