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

source: content/vI_getHeader.js @ db5435

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

cleanup and usage of stdlib-module (still incomplete)

  • 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/stdlib/msgHdrUtils.js");
29// XXX still missing implementation to select specific header by number and to display notification.
30 
31virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) {
32 
33// var storedHeaders = { };
34var getHeader = {
35    preferences : Components.classes["@mozilla.org/preferences-service;1"]
36            .getService(Components.interfaces.nsIPrefService)
37            .getBranch("extensions.virtualIdentity."),
38           
39    unicodeConverter : Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
40            .createInstance(Components.interfaces.nsIScriptableUnicodeConverter),
41
42//  strings : document.getElementById("vIdentBundle"),
43   
44    headerToSearch : null,
45   
46    prefObserverToSearchArray : function() {
47        var headerList = getHeader.unicodeConverter.ConvertToUnicode(getHeader.preferences.getCharPref("smart_reply_headers")).split(/\n/)
48       
49        getHeader.headerToSearch = [];
50       
51        // prepare headerToSearch for speedup.
52        for (var index = 0; index < headerList.length; index++) {
53            var headerToSearch_splitted = headerList[index].split(/:/)
54            // use first part (all before ':') as the header name
55            var headerNameToSearch = headerToSearch_splitted[0].toLowerCase()
56            // check second or third part for any number
57//          var headerNumberToSearch = parseInt(headerToSearch_splitted[1])
58//          if (isNaN(headerNumberToSearch)) headerNumberToSearch = parseInt(headerToSearch_splitted[2])
59           
60            // create header name to store the value
61//          var headerNameToStore = "vI_" + headerNameToSearch
62//          if (!isNaN(headerNumberToSearch)) headerNameToStore += ":" + headerNumberToSearch
63           
64//          getHeader.headerToSearch.push({ headerNameToSearch : headerNameToSearch, headerNumberToSearch : headerNumberToSearch,
65//                  headerNameToStore : headerNameToStore });
66            getHeader.headerToSearch.push({ headerNameToSearch : headerNameToSearch });
67        }
68    },
69
70    getHeader: function() {
71      vI.notificationBar.clear_dump();
72      vI.notificationBar.dump("\n");
73     
74      if (!getHeader.headerToSearch) getHeader.prefObserverToSearchArray()
75     
76      msgHdrGetHeaders(getHeader.hdr, function (aHeaders) {
77        if (aHeaders.has("list-id")) {
78          getHeader.hdr.setStringProperty("vI_list-id","found");
79          vI.notificationBar.dump("## getHeader: found header: list-id  ...stored to recognize mailing-list\n");
80        }
81        if (aHeaders.has("received")) {
82          getHeader.hdr.setStringProperty("vI_received","found");
83          vI.notificationBar.dump("## getHeader: found header: received  ...stored to recognize received mail\n");
84        }
85        if (aHeaders.has("content-base")) {
86          getHeader.hdr.setStringProperty("vI_content_base","found");
87          vI.notificationBar.dump("## getHeader: found header: content-base  ...stored to recognize blog/news-feed\n");
88        }
89        for (let index = 0; index < getHeader.headerToSearch.length; index++) {
90          let headerNameToSearch = getHeader.headerToSearch[index].headerNameToSearch;
91          if (aHeaders.has(headerNameToSearch)) {
92            let value = aHeaders.get(headerNameToSearch);
93            getHeader.hdr.setStringProperty("vI_" + headerNameToSearch,
94                                  getHeader.unicodeConverter.ConvertFromUnicode(value) + getHeader.unicodeConverter.Finish());
95            let storedValue = getHeader.hdr.getProperty("vI_" + headerNameToSearch);
96            let storedConvValue = getHeader.unicodeConverter.ConvertToUnicode(storedValue);
97            vI.notificationBar.dump("## getHeader: found header: " + headerNameToSearch +
98                " - stored as '" + storedConvValue + "'\n");
99          }
100        }
101      });
102    },
103   
104    setupEventListener: function() {
105       
106        getHeader.strings = document.getElementById("vIdentBundle");
107       
108        getHeader.unicodeConverter.charset = "UTF-8";
109       
110        // read headers later if msg is loaded completely - this ensures compatibility to Thunderbird Conversation
111        getHeader.orig_OnMsgLoaded = OnMsgLoaded;
112        OnMsgLoaded = getHeader.OnMsgLoaded;
113
114    },
115   
116    OnMsgLoaded: function(url) {
117        const Cc = Components.classes;
118        const Ci = Components.interfaces;
119        // Necko URL, so convert it into a message header
120        let ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
121        var neckoURL = ioService.newURI(null, null, url.baseURI);
122        neckoURL.QueryInterface(Ci.nsIMsgMessageUrl);
123       
124        getHeader.hdr = neckoURL.messageHeader;
125        if (getHeader.hdr) getHeader.getHeader();
126        getHeader.orig_OnMsgLoaded(url);
127    }
128}
129
130
131var prefObserver = {
132    prefroot : Components.classes["@mozilla.org/preferences-service;1"]
133            .getService(Components.interfaces.nsIPrefService)
134            .getBranch(null).QueryInterface(Components.interfaces.nsIPrefBranch2),
135
136    unicodeConverter : Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
137            .createInstance(Components.interfaces.nsIScriptableUnicodeConverter),
138           
139    observer_added : false,
140   
141    init : function() {
142      prefObserver.prefroot.addObserver("extensions.virtualIdentity.smart_reply_headers", this, false);
143    },
144   
145    cleanup : function() {
146      prefObserver.prefroot.removeObserver("extensions.virtualIdentity.smart_reply_headers", this);
147    },
148   
149    observe: function(subject, topic, data) {
150        if (topic == "nsPref:changed") {
151            // remove (old) prepared headerArray
152            getHeader.headerToSearch = null;
153           
154            vI.notificationBar.dump("## prefObserver: reload Message\n");
155            MsgReload();
156        }
157    },
158
159}
160addEventListener('messagepane-loaded', getHeader.setupEventListener, true);
161window.addEventListener("load", function(e) { prefObserver.init(); }, false);
162window.addEventListener("unload", function(e) { prefObserver.cleanup(); }, false);
163// vI.storedHeaders = storedHeaders;
164}});
Note: See TracBrowser for help on using the repository browser.