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

source: chrome/content/v_identity/modules/plugins/conversation.js @ afd8b0

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

updated conversation plugin

  • Property mode set to 100644
File size: 6.6 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 virtualIdentityData;
18let virtualIdSenderName;
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  // add code to set stored base identity
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(virtualIdSenderName);
35  }
36  virtualIdInUse = !(identityData.isExistingIdentity(false));
37  Log.debug("## changeIdentityToSmartIdentity virtualIdInUse=" + virtualIdInUse + "\n");
38  if (virtualIdInUse) {
39    virtualIdentityData = identityData;
40    virtualIdSenderName = virtualIdentityData.combinedName;
41  }
42  virtualSenderNameElem.text(identityData.combinedName); // change this also to reflect changes of base id
43};
44
45let conversationHook = {
46  onComposeSessionConstructDone: function (recipientString, params, senderNameElem, ExternalLog) {
47    // this.params = { identity: ???, msgHdr: ???, subject: ??? };
48    Log = ExternalLog;
49
50    currentParams = params; virtualSenderNameElem = senderNameElem; // to enable access from out of this class.
51    virtualIdentityData = null; virtualIdInUse = false; virtualIdSenderName = "";
52   
53    let recipients = []; var combinedNames = {}; var number;
54    number = HeaderParser.parseHeadersWithArray(recipientString, {}, {}, combinedNames);
55    for (var index = 0; index < number; index++)
56      recipients.push( { recipient: combinedNames.value[index], recipientType: "addr_to" } )
57     
58    var localSmartIdentityCollection = new vI.smartIdentityCollection(params.msgHdr, params.identity, false, false, recipients);
59    localSmartIdentityCollection.Reply();   // we can always use the reply-case, msgHdr is set the right way
60   
61    if (localSmartIdentityCollection._allIdentities.number == 0) return;
62 
63    if (pref.getBoolPref("idSelection_preferExisting")) {
64      var existingIDIndex = localSmartIdentityCollection._foundExistingIdentity();
65      if (existingIDIndex) {
66        Log.debug("## smartIdentity: found existing Identity, use without interaction.\n", existingIDIndex.key);
67        changeIdentityToSmartIdentity(localSmartIdentityCollection._allIdentities, existingIDIndex.key);
68        return;
69      }
70    }
71
72    if (pref.getBoolPref("idSelection_ask") && 
73      ((localSmartIdentityCollection._allIdentities.number == 1 && pref.getBoolPref("idSelection_ask_always"))
74      || localSmartIdentityCollection._allIdentities.number > 1)) {
75        window.openDialog("chrome://v_identity/content/vI_smartReplyDialog.xul",0,
76          "chrome, dialog, modal, alwaysRaised, resizable=yes",
77          localSmartIdentityCollection._allIdentities,
78          /* callback: */ changeIdentityToSmartIdentity).focus();
79      }
80    else if (pref.getBoolPref("idSelection_autocreate")) changeIdentityToSmartIdentity(localSmartIdentityCollection._allIdentities, 0);
81  },
82 
83  onMessageBeforeSendOrPopup: function(gComposeParams, recipientString, popOut, aStatus, ExternalLog) {
84    Log = ExternalLog;
85    Log.debug("## onMessageBeforeSendOrPopup", recipientString);
86   
87    if (virtualIdInUse) {
88      if (!popOut) {
89        let recipients = []; var combinedNames = {}; var number;
90        number = HeaderParser.parseHeadersWithArray(recipientString, {}, {}, combinedNames);
91        for (var index = 0; index < number; index++)
92          recipients.push( { recipient: combinedNames.value[index], recipientType: "addr_to" } )
93
94        returnValue = vI.prepareSendMsg(virtualIdInUse, Ci.nsIMsgCompDeliverMode.Now,
95          virtualIdentityData, gComposeParams.identity, recipients );
96        Log.debug("returnValue.update:", returnValue.update);
97       
98        if (returnValue.update == "abort") {
99          aStatus.canceled = true; return aStatus;
100        }
101        else if (returnValue.update == "takeover") {
102          _changeIdentityToSmartIdentity(returnValue.storedIdentity);
103          aStatus.canceled = true; return aStatus;
104        }
105       
106        gComposeParams.identity = vI.account._account.defaultIdentity
107        if (!vI.finalCheck(virtualIdentityData, gComposeParams.identity)) {
108          vI.account.removeUsedVIAccount();
109          aStatus.canceled = true; return aStatus;
110        }
111      }
112      else {
113        // code virtual Identity into subject - this will be decoded by smartIdentity - newMail
114        gComposeParams.subject = gComposeParams.subject + "\nvirtualIdentityExtension\n" + virtualIdSenderName;
115        Log.debug("coding virtualIdentity into subject:", gComposeParams.subject);
116      }
117    }
118    Log.debug("onSendMessage done");
119    return aStatus;
120  },
121 
122  onStopSending: function () {
123    vI.account.removeUsedVIAccount();
124    Log.debug("onStopSending done");
125  },
126
127  onRecipientAdded: function onRecipientAdded(recipient, recipientType, count, ExternalLog) {
128    Log = ExternalLog;
129    Log.debug("onRecipientAdded", recipient, recipientType, count);
130    if (!pref.getBoolPref("storage")) return;
131    if (recipientType == "bcc") return;
132    if (recipient == "") return;
133
134    // if we are editing the "cc" or not the first recipient, recognize this.
135    var isNotFirstInputElement = !(recipientType == "to" && count == 0);
136    Log.debug("onRecipientAdded isNotFirstInputElement", isNotFirstInputElement);
137   
138    if (!_rdfDatasourceAccess) _rdfDatasourceAccess = new vI.rdfDatasourceAccess();
139    else _rdfDatasourceAccess.clean();
140   
141    var storageResult = _rdfDatasourceAccess.updateVIdentityFromStorage(recipient, "addr_to",
142      virtualIdentityData, virtualIdInUse, isNotFirstInputElement);
143   
144    if (storageResult.identityCollection.number == 0) return; // return if there was no match
145    if (storageResult.result != "accept") return; // return if we don't like the resulting id
146   
147    changeIdentityToSmartIdentity(storageResult.identityCollection, 0);
148  }
149}
150
151vI.conversationHook = conversationHook;
152}});
Note: See TracBrowser for help on using the repository browser.