1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var { MailServices } = ChromeUtils.import(
"resource:///modules/MailServices.jsm"
);
// biff observer topic
const BIFF_TOPIC = "mail:biff-state-changed";
// biff state constants used by themes
const BIFF_STATE_MESSAGES = "NewMail";
const BIFF_STATE_NOMESSAGES = "NoMail";
const BIFF_STATE_UNKNOWN = "UnknownMail";
// uses "toOpenWindowByType" function provided by tasksOverlay.js
// which is included by most clients.
function toMessengerWindow()
{
toOpenWindowByType("mail:3pane", "chrome://messenger/content/");
}
function toAddressBook()
{
toOpenWindowByType("mail:addressbook",
"chrome://messenger/content/addressbook/addressbook.xul");
}
function toNewsgroups()
{
dump("Sorry, command not implemented.\n");
}
function toImport()
{
window.openDialog("chrome://messenger/content/importDialog.xul",
"importDialog",
"chrome, modal, titlebar, centerscreen");
}
function CoalesceGetMsgsForPop3ServersByDestFolder(aCurrentServer,
aPOP3DownloadServersArray,
aLocalFoldersToDownloadTo)
{
// coalesce the servers that download into the same folder...
var inbox = aCurrentServer.rootMsgFolder.getFolderWithFlags(Ci.nsMsgFolderFlags.Inbox);
var index = aLocalFoldersToDownloadTo.indexOf(inbox);
if (index == -1)
{
inbox.biffState = Ci.nsIMsgFolder.nsMsgBiffState_NoMail;
inbox.clearNewMessages();
aLocalFoldersToDownloadTo.push(inbox);
index = aPOP3DownloadServersArray.length;
aPOP3DownloadServersArray.push([]);
}
aPOP3DownloadServersArray[index].push(aCurrentServer);
}
function MailTasksGetMessagesForAllServers(aBiff, aMsgWindow, aDefaultServer)
{
// now log into any server
try
{
// array of array of servers for a particular folder
var pop3DownloadServersArray = [];
// parallel array of folders to download to...
var localFoldersToDownloadTo = [];
var pop3Server = null;
for (let currentServer of MailServices.accounts.allServers)
{
if (currentServer)
{
if (aBiff)
{
if (currentServer.protocolInfo.canLoginAtStartUp &&
currentServer.loginAtStartUp)
{
if (aDefaultServer &&
aDefaultServer.equals(currentServer) &&
!aDefaultServer.isDeferredTo &&
aDefaultServer.rootFolder == aDefaultServer.rootMsgFolder)
{
dump(currentServer.serverURI + " ... skipping, already opened\n");
}
else if (currentServer.type == "pop3" && currentServer.downloadOnBiff)
{
CoalesceGetMsgsForPop3ServersByDestFolder(currentServer,
pop3DownloadServersArray,
localFoldersToDownloadTo);
pop3Server = currentServer;
}
else
{
// check to see if there are new messages on the server
currentServer.performBiff(aMsgWindow);
}
}
}
else
{
if (currentServer.protocolInfo.canGetMessages &&
!currentServer.passwordPromptRequired)
{
if (currentServer.type == "pop3")
{
CoalesceGetMsgsForPop3ServersByDestFolder(currentServer,
pop3DownloadServersArray,
localFoldersToDownloadTo);
pop3Server = currentServer;
}
else
{
// get new messages on the server for IMAP or RSS
GetMessagesForInboxOnServer(currentServer);
}
}
}
}
}
if (pop3Server instanceof Ci.nsIPop3IncomingServer)
{
for (let i = 0; i < pop3DownloadServersArray.length; ++i)
{
// any ol' pop3Server will do -
// the serversArray specifies which servers to download from
pop3Server.downloadMailFromServers(pop3DownloadServersArray[i],
aMsgWindow,
localFoldersToDownloadTo[i],
null);
}
}
}
catch (e)
{
Cu.reportError(e);
}
}
var biffObserver =
{
observe: function observe(subject, topic, state)
{
// sanity check
if (topic == BIFF_TOPIC)
{
var biffManager = Cc["@mozilla.org/messenger/statusBarBiffManager;1"]
.getService(Ci.nsIStatusBarBiffManager);
document.getElementById("mini-mail")
.setAttribute("BiffState",
[BIFF_STATE_MESSAGES,
BIFF_STATE_NOMESSAGES,
BIFF_STATE_UNKNOWN][biffManager.biffState]);
}
}
};
function MailTasksOnLoad(aEvent)
{
// Without the mini-mail icon to show the biff state, there's no need to
// initialize this here. We won't start with the hidden window alone,
// so this early return doesn't break anything.
var miniMail = document.getElementById("mini-mail");
if (!miniMail)
return;
// initialize biff state
Services.obs.addObserver(biffObserver, BIFF_TOPIC);
biffObserver.observe(null, BIFF_TOPIC, null); // init mini-mail icon
addEventListener("unload", MailTasksOnUnload, false);
// don't try to biff if offline, but do so silently
if (Services.io.offline)
return;
// Performing biff here will mean performing it for all new windows opened!
// This might make non-users of mailnews unhappy...
if (!Services.prefs.getBoolPref("mail.biff.on_new_window"))
return;
// The MailNews main window will perform biff later in its onload handler,
// so we don't need to do this here.
if (Services.wm.getMostRecentWindow("mail:3pane"))
return;
// If we already have a defined biff-state set on the mini-mail icon,
// we know that biff is already running.
const kBiffState = Cc["@mozilla.org/messenger/statusBarBiffManager;1"]
.getService(Ci.nsIStatusBarBiffManager)
.biffState;
if (kBiffState != Ci.nsIMsgFolder.nsMsgBiffState_Unknown)
return;
// still no excuse to refuse to use this ruse
MailTasksGetMessagesForAllServers(true, null, null);
}
function MailTasksOnUnload(aEvent)
{
Services.obs.removeObserver(biffObserver, BIFF_TOPIC);
}
/**
* This class implements nsIBadCertListener2. Its job is to prevent "bad cert"
* security dialogs from being shown to the user. Currently it puts up the
* cert override dialog, though we'd like to give the user more detailed
* information in the future.
*/
function nsMsgBadCertHandler() {
}
nsMsgBadCertHandler.prototype = {
// Suppress any certificate errors
notifyCertProblem: function(socketInfo, status, targetSite) {
if (!status)
return true;
setTimeout(InformUserOfCertError, 0, status, targetSite);
return true;
},
// nsIInterfaceRequestor
getInterface: function(iid) {
return this.QueryInterface(iid);
},
// nsISupports
QueryInterface: function(iid) {
if (!iid.equals(Ci.nsIBadCertListener2) &&
!iid.equals(Ci.nsIInterfaceRequestor) &&
!iid.equals(Ci.nsISupports))
throw Cr.NS_ERROR_NO_INTERFACE;
return this;
}
};
function InformUserOfCertError(status, targetSite)
{
var params = { exceptionAdded : false,
sslStatus : status,
prefetchCert : true,
location : targetSite };
window.openDialog('chrome://pippki/content/exceptionDialog.xul',
'','chrome,centerscreen,modal', params);
}
addEventListener("load", MailTasksOnLoad, false);
|