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

source: content/vI_getHeader.js @ bcf746

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

added new prefs module, not finished

  • Property mode set to 100644
File size: 6.8 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): Christian Weiske
23    Contributor(s): Patrick Brunschwig
24    Contributor(s): http://xulsolutions.blogspot.com/2006/07/creating-uninstall-script-for.html
25
26 * ***** END LICENSE BLOCK ***** */
27
28Components.utils.import("resource://v_identity/vI_nameSpaceWrapper.js");
29virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) {
30
31Components.utils.import("resource://v_identity/stdlib/msgHdrUtils.js", virtualIdentityExtension);
32Components.utils.import("resource://v_identity/vI_prefs.js", virtualIdentityExtension);
33let Log = vI.setupLogging("virtualIdentity.getHeader");
34
35// var storedHeaders = { };
36var getHeader = {
37    unicodeConverter : Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
38            .createInstance(Components.interfaces.nsIScriptableUnicodeConverter),
39
40//  strings : document.getElementById("virtualIdentityExtension_vIdentBundle"),
41   
42    headerToSearch : null,
43   
44    prefObserverToSearchArray : function() {
45        var headerList = getHeader.unicodeConverter.ConvertToUnicode(vI.vIprefs.get("smart_reply_headers")).split(/\n/)
46       
47        getHeader.headerToSearch = [];
48       
49        // prepare headerToSearch for speedup.
50        for (var index = 0; index < headerList.length; index++) {
51            var headerToSearch_splitted = headerList[index].split(/:/)
52            // use first part (all before ':') as the header name
53            var headerNameToSearch = headerToSearch_splitted[0].toLowerCase()
54            // check second or third part for any number
55            var headerNumberToSearch = parseInt(headerToSearch_splitted[1])
56            if (isNaN(headerNumberToSearch)) headerNumberToSearch = parseInt(headerToSearch_splitted[2])
57           
58            // create header name to store the value
59            var headerNameToStore = headerNameToSearch
60            if (!isNaN(headerNumberToSearch)) headerNameToStore += ":" + headerNumberToSearch
61           
62            getHeader.headerToSearch.push({ headerNameToSearch : headerNameToSearch, headerNumberToSearch : headerNumberToSearch,
63                    headerNameToStore : headerNameToStore });
64        }
65    },
66
67    getHeader: function() {
68      vI.clearDebugOutput();
69      if (!getHeader.headerToSearch) getHeader.prefObserverToSearchArray()
70     
71      vI.msgHdrGetHeaders(getHeader.hdr, function (aHeaders) {
72        let label = "";
73        if (aHeaders.has("list-id")) {
74          getHeader.hdr.setStringProperty("vI_list-id","found");
75          Log.debug("found header: list-id  ...stored to recognize mailing-list\n");
76        }
77        if (aHeaders.has("received")) {
78          getHeader.hdr.setStringProperty("vI_received","found");
79          Log.debug("found header: received  ...stored to recognize received mail\n");
80        }
81        if (aHeaders.has("content-base")) {
82          getHeader.hdr.setStringProperty("vI_content_base","found");
83          Log.debug("found header: content-base  ...stored to recognize blog/news-feed\n");
84        }
85        for (let index = 0; index < getHeader.headerToSearch.length; index++) {
86          let {headerNameToSearch: headerNameToSearch, headerNumberToSearch: headerNumberToSearch,
87            headerNameToStore: headerNameToStore} = getHeader.headerToSearch[index];
88          if (aHeaders.has(headerNameToSearch)) {
89            let value = "";
90            let values = aHeaders.getAll(headerNameToSearch);
91            if (isNaN(headerNumberToSearch))
92              for (let i = 0; i < values.length;)
93                value += ((value)?(", "):("")) + values[i++];
94            else value = values[headerNumberToSearch-1];
95            if (value) {
96              getHeader.hdr.setStringProperty("vI_" + headerNameToStore,
97                getHeader.unicodeConverter.ConvertFromUnicode(value) + getHeader.unicodeConverter.Finish());
98             
99              let storedValue = getHeader.hdr.getProperty("vI_" + headerNameToStore);
100              let storedConvValue = getHeader.unicodeConverter.ConvertToUnicode(storedValue);
101             
102              Log.debug("found header: " + headerNameToStore +
103                  " - stored as '" + storedConvValue + "'\n");
104              label += (label)?"\n":""
105              label += headerNameToStore + ":\t" + storedConvValue
106            }
107          }
108        }
109        vI.GetHeaderNotification.info(label);
110      });
111    },
112   
113    setupEventListener: function() {
114       
115        getHeader.strings = document.getElementById("virtualIdentityExtension_vIdentBundle");
116       
117        getHeader.unicodeConverter.charset = "UTF-8";
118       
119        // read headers later if msg is loaded completely - this ensures compatibility to Thunderbird Conversation
120        getHeader.orig_OnMsgLoaded = OnMsgLoaded;
121        OnMsgLoaded = getHeader.OnMsgLoaded;
122
123    },
124   
125    OnMsgLoaded: function(url) {
126        const Cc = Components.classes;
127        const Ci = Components.interfaces;
128        // Necko URL, so convert it into a message header
129        let ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
130        var neckoURL = ioService.newURI(null, null, url.baseURI);
131        neckoURL.QueryInterface(Ci.nsIMsgMessageUrl);
132       
133        getHeader.hdr = neckoURL.messageHeader;
134        if (getHeader.hdr) getHeader.getHeader();
135        getHeader.orig_OnMsgLoaded(url);
136    }
137}
138
139
140var prefObserver = {
141    unicodeConverter : Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
142            .createInstance(Components.interfaces.nsIScriptableUnicodeConverter),
143           
144    observer_added : false,
145   
146    init : function() {
147      vI.vIprefs.addObserver("smart_reply_headers", this.observe, this);
148    },
149   
150    cleanup : function() {
151      let self = this;
152      vI.vIprefs.removeObserver("smart_reply_headers", self.observe);
153    },
154   
155    observe: function(self, subject, topic, data) {
156        if (topic == "nsPref:changed") {
157            // remove (old) prepared headerArray
158            getHeader.headerToSearch = null;
159            ReloadMessage();
160        }
161    },
162
163}
164addEventListener('messagepane-loaded', getHeader.setupEventListener, true);
165window.addEventListener("load", function(e) { prefObserver.init(); }, false);
166window.addEventListener("unload", function(e) { prefObserver.cleanup(); }, false);
167// vI.storedHeaders = storedHeaders;
168}});
Note: See TracBrowser for help on using the repository browser.