Monotone-Parent: 34791f35dbfae81d89b325cab373497ac8267859

Monotone-Revision: d60b33f55567caeee757661e23d65eee6e952ed9

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2010-08-03T18:52:49
Monotone-Branch: ca.inverse.sogo
maint-2.0.2
Wolfgang Sourdeau 2010-08-03 18:52:49 +00:00
parent 05ef0e573e
commit 9100c3db2f
7 changed files with 165 additions and 263 deletions

View File

@ -1,5 +1,33 @@
2010-08-03 Wolfgang Sourdeau <wsourdeau@inverse.ca> 2010-08-03 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* UI/WebServerResources/MailerUI.js (composeNewMessage): the first
account is always identified as "0".
* UI/MailerUI/UIxMailMainFrame.m (-mailAccounts): we now return
tje JSON rep. of a simple and flat array containing the account
display names, since the account are represented with an integer
index.
(-inboxData): we directly fetch the first mail account by using
the "0" key.
(-composeAction): same as above.
* SoObjects/Mailer/SOGoMailAccount.m (-imap4URLString): the
"nameInContainer" now represents the index of the current account
in the array of user mail accounts, which simplifies this method.
We also handle the "encryption" key, albeit currently unused, and
we now add the port to the url as needed.
(-shortTitle): removed method.
(-davDisplayName): we only need to return the "name" key of the
current account.
* SoObjects/Mailer/SOGoMailAccounts.m (-mailAccounts): new utility
method that returns the mail account dictionaries corresponding to
the owner.
(-toManyRelationshipKeys): we now identify mail accounts via their
index in the array of accounts, since the order will never vary,
this simplifies the code.
(-lookupName:inContext:acquire:): same as the above.
* UI/WebServerResources/RowEditionController.js: * UI/WebServerResources/RowEditionController.js:
RowEditionController.startEditing: keep the "_selected" class RowEditionController.startEditing: keep the "_selected" class
when starting edition, if exists. when starting edition, if exists.

View File

@ -50,7 +50,6 @@ typedef enum {
@interface SOGoMailAccount : SOGoMailBaseObject @interface SOGoMailAccount : SOGoMailBaseObject
{ {
NSString *accountName;
SOGoMailFolder *inboxFolder; SOGoMailFolder *inboxFolder;
SOGoDraftsFolder *draftsFolder; SOGoDraftsFolder *draftsFolder;
SOGoSentFolder *sentFolder; SOGoSentFolder *sentFolder;
@ -58,8 +57,6 @@ typedef enum {
SOGoIMAPAclStyle imapAclStyle; SOGoIMAPAclStyle imapAclStyle;
} }
- (void) setAccountName: (NSString *) newAccountName;
- (SOGoIMAPAclStyle) imapAclStyle; - (SOGoIMAPAclStyle) imapAclStyle;
- (BOOL) imapAclConformsToIMAPExt; - (BOOL) imapAclConformsToIMAPExt;

View File

@ -69,7 +69,6 @@ static NSString *sieveScriptName = @"sogo";
draftsFolder = nil; draftsFolder = nil;
sentFolder = nil; sentFolder = nil;
trashFolder = nil; trashFolder = nil;
accountName = nil;
imapAclStyle = undefined; imapAclStyle = undefined;
} }
@ -82,15 +81,9 @@ static NSString *sieveScriptName = @"sogo";
[draftsFolder release]; [draftsFolder release];
[sentFolder release]; [sentFolder release];
[trashFolder release]; [trashFolder release];
[accountName release];
[super dealloc]; [super dealloc];
} }
- (void) setAccountName: (NSString *) newAccountName
{
ASSIGN (accountName, newAccountName);
}
/* listing the available folders */ /* listing the available folders */
- (BOOL) isInDraftsFolder - (BOOL) isInDraftsFolder
@ -475,11 +468,6 @@ static NSString *sieveScriptName = @"sogo";
/* IMAP4 */ /* IMAP4 */
- (BOOL) useSSL
{
return NO;
}
- (NSString *) imap4LoginFromHTTP - (NSString *) imap4LoginFromHTTP
{ {
WORequest *rq; WORequest *rq;
@ -505,46 +493,52 @@ static NSString *sieveScriptName = @"sogo";
return [creds objectAtIndex:0]; /* the user */ return [creds objectAtIndex:0]; /* the user */
} }
- (NSString *) _urlHostString - (NSDictionary *) _mailAccount
{ {
NSDictionary *mailAccount; NSDictionary *mailAccount;
NSString *username, *escUsername, *hostString; NSArray *accounts;
SOGoUser *user;
mailAccount = [[context activeUser] accountWithName: accountName]; user = [SOGoUser userWithLogin: [self ownerInContext: nil]];
if (mailAccount) accounts = [user mailAccounts];
{ mailAccount = [accounts objectAtIndex: [nameInContainer intValue]];
username = [mailAccount objectForKey: @"userName"];
escUsername
= [[username stringByEscapingURL] stringByReplacingString: @"@"
withString: @"%40"];
hostString = [NSString stringWithFormat: @"%@@%@", escUsername,
[mailAccount objectForKey: @"serverName"]];
}
else
hostString = @"localhost";
return hostString; return mailAccount;
} }
- (NSMutableString *) imap4URLString - (NSMutableString *) imap4URLString
{ {
/* private, overridden by SOGoSharedMailAccount */ NSMutableString *imap4URLString;
NSMutableString *urlString; NSDictionary *mailAccount;
NSString *host; NSString *encryption, *protocol, *username, *escUsername;
int defaultPort, port;
urlString = [NSMutableString string]; mailAccount = [self _mailAccount];
encryption = [mailAccount objectForKey: @"encryption"];
if ([self useSSL]) if ([encryption isEqualToString: @"ssl"])
[urlString appendString: @"imaps://"]; {
protocol = @"imaps";
defaultPort = 993;
}
else else
[urlString appendString: @"imap://"]; {
protocol = @"imap";
defaultPort = 143;
}
username = [mailAccount objectForKey: @"userName"];
escUsername
= [[username stringByEscapingURL] stringByReplacingString: @"@"
withString: @"%40"];
imap4URLString = [NSMutableString stringWithFormat: @"%@://%@@%@",
protocol, escUsername,
[mailAccount objectForKey: @"serverName"]];
port = [[mailAccount objectForKey: @"port"] intValue];
if (port && port != defaultPort)
[imap4URLString appendFormat: @":%d", port];
[imap4URLString appendString: @"/"];
host = [self _urlHostString]; return imap4URLString;
if (![host rangeOfString: @"@"].length)
[urlString appendFormat: @"%@@", [self imap4LoginFromHTTP]];
[urlString appendFormat: @"%@/", host];
return urlString;
} }
- (NSMutableString *) traversalFromMailAccount - (NSMutableString *) traversalFromMailAccount
@ -800,40 +794,9 @@ static NSString *sieveScriptName = @"sogo";
return [[self imap4Connection] createMailbox:_name atURL:[self imap4URL]]; return [[self imap4Connection] createMailbox:_name atURL:[self imap4URL]];
} }
- (NSString *) shortTitle
{
NSString *login, *host;
NSRange r;
r = [accountName rangeOfString:@"@"];
if (r.length > 0)
{
login = [accountName substringToIndex:r.location];
host = [accountName substringFromIndex:(r.location + r.length)];
}
else
{
login = nil;
host = accountName;
}
r = [host rangeOfString:@"."];
if (r.length > 0)
host = [host substringToIndex:r.location];
if ([login length] == 0)
return host;
r = [login rangeOfString:@"."];
if (r.length > 0)
login = [login substringToIndex:r.location];
return [NSString stringWithFormat:@"%@@%@", login, host];
}
- (NSString *) davDisplayName - (NSString *) davDisplayName
{ {
return [self shortTitle]; return [[self _mailAccount] objectForKey: @"name"];
} }
@end /* SOGoMailAccount */ @end /* SOGoMailAccount */

View File

@ -41,12 +41,10 @@
@class NSMutableDictionary; @class NSMutableDictionary;
@interface SOGoMailAccounts : SOGoFolder @interface SOGoMailAccounts : SOGoFolder
{
NSMutableDictionary *accountKeys; - (NSArray *) mailAccounts;
}
- (NSArray *) toManyRelationshipKeys; - (NSArray *) toManyRelationshipKeys;
- (NSDictionary *) accountKeys;
@end @end

View File

@ -36,113 +36,55 @@
@implementation SOGoMailAccounts @implementation SOGoMailAccounts
/* listing the available mailboxes */ - (NSArray *) mailAccounts
// - (BOOL) isInHomeFolderBranchOfLoggedInAccount: (NSString *) userLogin
// {
// return [[container nameInContainer] isEqualToString: userLogin];
// }
- (id) init
{ {
if ((self = [super init])) SOGoUser *user;
{
accountKeys = nil; user = [SOGoUser userWithLogin: [self ownerInContext: nil]];
}
return self; return [user mailAccounts];
}
- (void) dealloc
{
[accountKeys release];
[super dealloc];
}
- (void) _initAccountKeys
{
NSArray *accounts;
NSString *currentName;
int count, max;
if (!accountKeys)
{
accountKeys = [NSMutableDictionary new];
accounts = [[context activeUser] mailAccounts];
max = [accounts count];
for (count = 0; count < max; count++)
{
currentName = [[accounts objectAtIndex: count] objectForKey: @"name"];
[accountKeys setObject: currentName
forKey: [currentName asCSSIdentifier]];
}
}
}
- (NSDictionary *) accountKeys
{
[self _initAccountKeys];
return accountKeys;
} }
- (NSArray *) toManyRelationshipKeys - (NSArray *) toManyRelationshipKeys
{ {
[self _initAccountKeys]; NSMutableArray *keys;
NSArray *accounts;
int count, max;
SOGoUser *user;
user = [SOGoUser userWithLogin: [self ownerInContext: nil]];
accounts = [user mailAccounts];
max = [accounts count];
return [accountKeys allKeys]; keys = [NSMutableArray arrayWithCapacity: max];
for (count = 0; count < max; count++)
[keys addObject: [NSString stringWithFormat: @"%d", count]];
return keys;
} }
/* name lookup */ /* name lookup */
// - (id) mailAccountWithName: (NSString *) _key
// inContext: (id) _ctx
// {
// static Class ctClass = Nil;
// id ct;
// if (ctClass == Nil)
// ctClass = NSClassFromString(@"SOGoMailAccount");
// if (ctClass == Nil) {
// [self errorWithFormat:@"missing SOGoMailAccount class!"];
// return nil;
// }
// ct = [[ctClass alloc] initWithName:_key inContainer:self];
// return [ct autorelease];
// }
- (id) lookupName: (NSString *) _key - (id) lookupName: (NSString *) _key
inContext: (id) _ctx inContext: (id) _ctx
acquire: (BOOL) _flag acquire: (BOOL) _flag
{ {
id obj; id obj;
NSString *accountName; NSArray *accounts;
// NSString *userLogin; SOGoUser *user;
int keyCount;
// userLogin = [[context activeUser] login];
// if (![self isInHomeFolderBranchOfLoggedInAccount: userLogin]) {
// [self warnWithFormat:@ "User %@ tried to access mail hierarchy of %@",
// userLogin, [container nameInContainer]];
// return [NSException exceptionWithHTTPStatus:403 /* Forbidden */
// reason:@"Tried to access the mail of another user"];
// }
/* first check attributes directly bound to the application */ /* first check attributes directly bound to the application */
obj = [super lookupName:_key inContext:_ctx acquire:NO]; obj = [super lookupName:_key inContext:_ctx acquire:NO];
if (!obj) if (!obj)
{ {
[self _initAccountKeys]; user = [SOGoUser userWithLogin: [self ownerInContext: nil]];
accountName = [accountKeys objectForKey: _key]; accounts = [user mailAccounts];
if ([accountName length])
{ keyCount = [_key intValue];
obj = [SOGoMailAccount objectWithName: _key inContainer: self]; if ([_key isEqualToString: [NSString stringWithFormat: @"%d", keyCount]]
[obj setAccountName: accountName]; && keyCount > -1 && keyCount < [accounts count])
} obj = [SOGoMailAccount objectWithName: _key inContainer: self];
else else
obj = [NSException exceptionWithHTTPStatus: 404 /* Not Found */]; obj = [NSException exceptionWithHTTPStatus: 404 /* Not Found */];
} }

View File

@ -103,27 +103,12 @@
- (NSString *) mailAccounts - (NSString *) mailAccounts
{ {
SOGoMailAccounts *accounts; NSArray *accounts, *names;
NSDictionary *accountKeys;
NSArray *keys, *entry;
NSMutableArray *values;
NSString *key;
int i, max;
accounts = [self clientObject]; accounts = [[self clientObject] mailAccounts];
accountKeys = [accounts accountKeys]; names = [accounts objectsForKey: @"name" notFoundMarker: nil];
keys = [accountKeys allKeys];
values = [NSMutableArray array];
max = [keys count]; return [names jsonRepresentation];
for (i = 0; i < max; i++)
{
key = [keys objectAtIndex: i];
entry = [NSArray arrayWithObjects: key, [accountKeys objectForKey: key], nil];
[values addObject: entry];
}
return [values jsonRepresentation];
} }
- (NSString *) defaultColumnsOrder - (NSString *) defaultColumnsOrder
@ -182,21 +167,18 @@
SOGoMailAccounts *accounts; SOGoMailAccounts *accounts;
SOGoMailAccount *account; SOGoMailAccount *account;
SOGoMailFolder *inbox; SOGoMailFolder *inbox;
NSString *firstAccount;
NSDictionary *data; NSDictionary *data;
SOGoUser *activeUser; SOGoUser *activeUser;
UIxMailListActions *actions; UIxMailListActions *actions;
[self _setupContext]; [self _setupContext];
#warning this code is dirty: we should not invoke UIxMailListActions from here!
actions = [[[UIxMailListActions new] initWithRequest: [context request]] autorelease]; actions = [[[UIxMailListActions new] initWithRequest: [context request]] autorelease];
activeUser = [context activeUser]; activeUser = [context activeUser];
accounts = [self clientObject]; accounts = [self clientObject];
firstAccount = [[[accounts accountKeys] allKeys] account = [accounts lookupName: @"0" inContext: context acquire: NO];
objectAtIndex: 0];
account = [accounts lookupName: firstAccount inContext: context acquire: NO];
inbox = [account inboxFolderInContext: context]; inbox = [account inboxFolderInContext: context];
data = [actions getUIDsAndHeadersInFolder: inbox]; data = [actions getUIDsAndHeadersInFolder: inbox];
@ -207,8 +189,8 @@
- (id <WOActionResults>) composeAction - (id <WOActionResults>) composeAction
{ {
id contact; id contact;
NSArray *accounts, *contactsId, *cards; NSArray *contactsId, *cards;
NSString *firstAccount, *firstEscapedAccount, *newLocation, *parameters, *folderId, *uid, *formattedMail; NSString *newLocation, *parameters, *folderId, *uid, *formattedMail;
NSEnumerator *uids; NSEnumerator *uids;
NSMutableArray *addresses; NSMutableArray *addresses;
NGVCard *card; NGVCard *card;
@ -222,11 +204,6 @@
parameters = nil; parameters = nil;
co = [self clientObject]; co = [self clientObject];
// We use the first mail account
accounts = [[context activeUser] mailAccounts];
firstAccount = [[accounts objectsForKey: @"name" notFoundMarker: nil]
objectAtIndex: 0];
firstEscapedAccount = [firstAccount asCSSIdentifier];
request = [context request]; request = [context request];
if ((folderId = [request formValueForKey: @"folder"]) && if ((folderId = [request formValueForKey: @"folder"]) &&
@ -290,9 +267,8 @@
// No parameter passed; simply open the compose window // No parameter passed; simply open the compose window
parameters = @"?mailto="; parameters = @"?mailto=";
newLocation = [NSString stringWithFormat: @"%@/%@/compose%@", newLocation = [NSString stringWithFormat: @"%@/0/compose%@",
[co baseURLInContext: context], [co baseURLInContext: context],
firstEscapedAccount,
parameters]; parameters];
return [self redirectToLocation: newLocation]; return [self redirectToLocation: newLocation];

View File

@ -1,7 +1,7 @@
/* -*- Mode: js2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* -*- Mode: js2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* JavaScript for SOGoMail */ /* JavaScript for SOGoMail */
var accounts = {}; var accounts = [];
var mailboxTree; var mailboxTree;
var mailAccounts; var mailAccounts;
if (typeof textMailAccounts != 'undefined') { if (typeof textMailAccounts != 'undefined') {
@ -223,10 +223,10 @@ function mailListMarkMessage(event) {
action = 'markMessageUnread'; action = 'markMessageUnread';
markread = false; markread = false;
} }
markMailInWindow(window, msguid, markread); markMailInWindow(window, msguid, markread);
var url = ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/" var url = ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/"
+ msguid + "/" + action; + msguid + "/" + action;
var data = { "msguid": msguid }; var data = { "msguid": msguid };
@ -260,10 +260,10 @@ function mailListFlagMessageToggle (e) {
action = "markMessageUnflagged"; action = "markMessageUnflagged";
flagged = false; flagged = false;
} }
flagMailInWindow(window, msguid, flagged); flagMailInWindow(window, msguid, flagged);
var url = ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/" var url = ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/"
+ msguid + "/" + action; + msguid + "/" + action;
var data = { "msguid": msguid }; var data = { "msguid": msguid };
@ -283,7 +283,7 @@ function mailListFlagMessageToggleCallback (http) {
function onUnload(event) { function onUnload(event) {
var url = ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/expunge"; var url = ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/expunge";
new Ajax.Request(url, { new Ajax.Request(url, {
asynchronous: false, asynchronous: false,
method: 'get', method: 'get',
@ -315,7 +315,7 @@ function onDocumentKeydown(event) {
if (nextRow && nextRow.id != 'rowTop' && nextRow.id != 'rowBottom') { if (nextRow && nextRow.id != 'rowTop' && nextRow.id != 'rowBottom') {
Mailer.currentMessages[Mailer.currentMailbox] = nextRow.getAttribute("id").substr(4); Mailer.currentMessages[Mailer.currentMailbox] = nextRow.getAttribute("id").substr(4);
row.up().deselectAll(); row.up().deselectAll();
// Adjust the scollbar // Adjust the scollbar
var viewPort = $("mailboxList"); var viewPort = $("mailboxList");
var divDimensions = viewPort.getDimensions(); var divDimensions = viewPort.getDimensions();
@ -328,7 +328,7 @@ function onDocumentKeydown(event) {
viewPort.scrollTop += rowBottom - divBottom + centerOffset; viewPort.scrollTop += rowBottom - divBottom + centerOffset;
else if (viewPort.scrollTop > nextRow.offsetTop) else if (viewPort.scrollTop > nextRow.offsetTop)
viewPort.scrollTop -= rowScrollOffset.top - nextRow.offsetTop + centerOffset; viewPort.scrollTop -= rowScrollOffset.top - nextRow.offsetTop + centerOffset;
// Select and load the next message // Select and load the next message
nextRow.selectElement(); nextRow.selectElement();
loadMessage(Mailer.currentMessages[Mailer.currentMailbox]); loadMessage(Mailer.currentMessages[Mailer.currentMailbox]);
@ -375,7 +375,7 @@ function deleteSelectedMessages(sender) {
} }
else else
window.alert(_("Please select a message.")); window.alert(_("Please select a message."));
return false; return false;
} }
@ -493,10 +493,10 @@ function onMailboxTreeItemClick(event) {
toggleAddressColumn("from", "to"); toggleAddressColumn("from", "to");
else else
toggleAddressColumn("to", "from"); toggleAddressColumn("to", "from");
openMailbox(mailbox); openMailbox(mailbox);
} }
Event.stop(event); Event.stop(event);
} }
@ -519,7 +519,7 @@ function onMailboxMenuMove(event) {
var rows = messageList.getSelectedNodes(); var rows = messageList.getSelectedNodes();
var uids = new Array(); // message IDs var uids = new Array(); // message IDs
var paths = new Array(); // row IDs var paths = new Array(); // row IDs
Mailer.currentMessages[Mailer.currentMailbox] = null; Mailer.currentMessages[Mailer.currentMailbox] = null;
$('messageContent').update(); $('messageContent').update();
@ -611,11 +611,11 @@ function composeNewMessage() {
if (Mailer.currentMailbox) if (Mailer.currentMailbox)
account = Mailer.currentMailbox.split("/")[1]; account = Mailer.currentMailbox.split("/")[1];
else if (mailAccounts.length) else if (mailAccounts.length)
account = mailAccounts[0][0]; account = "0";
else else
account = null; account = null;
if (account) { if (account) {
var url = ApplicationBaseURL + "/" + encodeURI(account) + "/compose"; var url = ApplicationBaseURL + encodeURI(account) + "/compose";
openMailComposeWindow(url); openMailComposeWindow(url);
} }
} }
@ -624,7 +624,7 @@ function openMailbox(mailbox, reload, updateStatus) {
if (mailbox != Mailer.currentMailbox || reload) { if (mailbox != Mailer.currentMailbox || reload) {
var url = ApplicationBaseURL + encodeURI(mailbox); var url = ApplicationBaseURL + encodeURI(mailbox);
var urlParams = new Hash(); var urlParams = new Hash();
if (!reload) { if (!reload) {
var messageContent = $("messageContent"); var messageContent = $("messageContent");
messageContent.update(); messageContent.update();
@ -641,7 +641,7 @@ function openMailbox(mailbox, reload, updateStatus) {
if (sortAttribute && sortAttribute.length > 0) { if (sortAttribute && sortAttribute.length > 0) {
urlParams.set("sort", sorting["attribute"]); urlParams.set("sort", sorting["attribute"]);
urlParams.set("asc", sorting["ascending"]); urlParams.set("asc", sorting["ascending"]);
var sortHeader = $(sorting["attribute"] + "Header"); var sortHeader = $(sorting["attribute"] + "Header");
if (sortHeader) { if (sortHeader) {
var sortImages = sortHeader.up('THEAD').select(".sortImage"); var sortImages = sortHeader.up('THEAD').select(".sortImage");
@ -664,7 +664,7 @@ function openMailbox(mailbox, reload, updateStatus) {
var p = urlParams.keys().collect(function(key) { return key + "=" + urlParams.get(key); }).join("&"); var p = urlParams.keys().collect(function(key) { return key + "=" + urlParams.get(key); }).join("&");
key += "?" + p; key += "?" + p;
} }
var dataSource = Mailer.dataSources.get(key); var dataSource = Mailer.dataSources.get(key);
if (!dataSource || reload) { if (!dataSource || reload) {
dataSource = new SOGoMailDataSource(Mailer.dataTable, url); dataSource = new SOGoMailDataSource(Mailer.dataTable, url);
@ -704,7 +704,7 @@ function messageListCallback(row, data, isNew) {
row.id = data['rowID']; row.id = data['rowID'];
row.writeAttribute('labels', (data['labels']?data['labels']:"")); row.writeAttribute('labels', (data['labels']?data['labels']:""));
row.className = data['rowClasses']; row.className = data['rowClasses'];
// Restore previous selection // Restore previous selection
if (data['uid'] == currentMessage) if (data['uid'] == currentMessage)
row.addClassName('_selected'); row.addClassName('_selected');
@ -755,7 +755,7 @@ function getStatusFolders() {
function statusFoldersCallback(http) { function statusFoldersCallback(http) {
var div = $('mailboxContent'); var div = $('mailboxContent');
var table = $('messageList'); var table = $('messageList');
if (http.status == 200) { if (http.status == 200) {
document.statusFoldersAjaxRequest = null; document.statusFoldersAjaxRequest = null;
var data = http.responseText.evalJSON(true); var data = http.responseText.evalJSON(true);
@ -766,7 +766,7 @@ function statusFoldersCallback(http) {
function updateStatusFolders(count, isDelta) { function updateStatusFolders(count, isDelta) {
var span = $("unseenCount"); var span = $("unseenCount");
var counter = null; var counter = null;
if (span) if (span)
counter = span.select("SPAN").first(); counter = span.select("SPAN").first();
@ -794,7 +794,7 @@ function updateMessageListCounter(count, isDelta) {
var value = parseInt(cell.innerHTML); var value = parseInt(cell.innerHTML);
count += value; count += value;
} }
if (count > 0) if (count > 0)
cell.update(count + " " + _("messages")); cell.update(count + " " + _("messages"));
else else
@ -820,11 +820,11 @@ function onMessageContextMenu(event) {
var selectedNodes = topNode.getSelectedRows(); var selectedNodes = topNode.getSelectedRows();
menu.observe("hideMenu", onMessageContextMenuHide); menu.observe("hideMenu", onMessageContextMenuHide);
if (selectedNodes.length > 1) if (selectedNodes.length > 1)
popupMenu(event, "messagesListMenu", selectedNodes); popupMenu(event, "messagesListMenu", selectedNodes);
else else
popupMenu(event, "messageListMenu", this); popupMenu(event, "messageListMenu", this);
} }
function onMessageContextMenuHide(event) { function onMessageContextMenuHide(event) {
@ -890,7 +890,7 @@ function deleteCachedMailboxByType(type) {
var nodes = $("mailboxTree").select("DIV[datatype=" + type + "]"); var nodes = $("mailboxTree").select("DIV[datatype=" + type + "]");
if (nodes.length == 1) if (nodes.length == 1)
deleteCachedMailbox(nodes[0].readAttribute("dataname")); deleteCachedMailbox(nodes[0].readAttribute("dataname"));
if (Mailer.currentMailboxType == type) if (Mailer.currentMailboxType == type)
refreshCurrentFolder(); refreshCurrentFolder();
} }
@ -1154,7 +1154,7 @@ function configureiCalLinksInMessage() {
delegatedTo.uidField = "c_mail"; delegatedTo.uidField = "c_mail";
delegatedTo.excludeGroups = true; delegatedTo.excludeGroups = true;
delegatedTo.excludeLists = true; delegatedTo.excludeLists = true;
var editDelegate = $("editDelegate"); var editDelegate = $("editDelegate");
if (editDelegate) { if (editDelegate) {
// The user delegates the invitation // The user delegates the invitation
@ -1260,7 +1260,7 @@ function ICalendarButtonCallback(http) {
function resizeMailContent() { function resizeMailContent() {
var headerTable = document.getElementsByClassName('mailer_fieldtable')[0]; var headerTable = document.getElementsByClassName('mailer_fieldtable')[0];
var contentDiv = document.getElementsByClassName('mailer_mailcontent')[0]; var contentDiv = document.getElementsByClassName('mailer_mailcontent')[0];
contentDiv.setStyle({ 'top': contentDiv.setStyle({ 'top':
(Element.getHeight(headerTable) + headerTable.offsetTop) + 'px' }); (Element.getHeight(headerTable) + headerTable.offsetTop) + 'px' });
@ -1280,7 +1280,7 @@ function resizeMailContent() {
function toggleDisplayHeader(event) { function toggleDisplayHeader(event) {
var row = this.up("TR"); var row = this.up("TR");
var span = row.down("SPAN"); var span = row.down("SPAN");
if (this.hasClassName("collapse")) { if (this.hasClassName("collapse")) {
this.writeAttribute("src", ResourcesURL + '/minus.png'); this.writeAttribute("src", ResourcesURL + '/minus.png');
this.writeAttribute("class", "expand"); this.writeAttribute("class", "expand");
@ -1301,7 +1301,7 @@ function onMessageContentMenu(event) {
var element = getTarget(event); var element = getTarget(event);
if ((element.tagName == 'A' && element.href.substring(0,7) == "mailto:") if ((element.tagName == 'A' && element.href.substring(0,7) == "mailto:")
|| element.tagName == 'IMG') || element.tagName == 'IMG')
// Don't show the default contextual menu; let the click propagate to // Don't show the default contextual menu; let the click propagate to
// other observers // other observers
return true; return true;
popupMenu(event, 'messageContentMenu', this); popupMenu(event, 'messageContentMenu', this);
@ -1371,7 +1371,7 @@ function loadMessageCallback(http) {
resizeMailContent(); resizeMailContent();
configureLoadImagesButton(); configureLoadImagesButton();
configureSignatureFlagImage(); configureSignatureFlagImage();
if (http.callbackData) { if (http.callbackData) {
var cachedMessage = new Array(); var cachedMessage = new Array();
var msguid = http.callbackData.msguid; var msguid = http.callbackData.msguid;
@ -1538,7 +1538,7 @@ function expandUpperTree(node) {
function onHeaderClick(event) { function onHeaderClick(event) {
if (SOGoResizableTable._onHandle) if (SOGoResizableTable._onHandle)
return; return;
var headerId = this.getAttribute("id"); var headerId = this.getAttribute("id");
var newSortAttribute; var newSortAttribute;
if (headerId == "subjectHeader") if (headerId == "subjectHeader")
@ -1560,9 +1560,9 @@ function onHeaderClick(event) {
sorting["attribute"] = newSortAttribute; sorting["attribute"] = newSortAttribute;
sorting["ascending"] = true; sorting["ascending"] = true;
} }
refreshCurrentFolder(); refreshCurrentFolder();
Event.stop(event); Event.stop(event);
} }
@ -1581,7 +1581,7 @@ function configureMessageListEvents(headerTable, dataTable) {
if (headerTable) if (headerTable)
// Sortable columns // Sortable columns
configureSortableTableHeaders(headerTable); configureSortableTableHeaders(headerTable);
if (dataTable) { if (dataTable) {
dataTable.multiselect = true; dataTable.multiselect = true;
// Each body row can load a message // Each body row can load a message
@ -1704,7 +1704,7 @@ function initMailer(event) {
initMailboxTree(); initMailboxTree();
initMessageCheckTimer(); initMessageCheckTimer();
if (Prototype.Browser.Gecko) if (Prototype.Browser.Gecko)
Event.observe(document, "keypress", onDocumentKeydown); // for FF2 Event.observe(document, "keypress", onDocumentKeydown); // for FF2
else else
@ -1721,7 +1721,7 @@ function initMailer(event) {
onMessageListResize(); onMessageListResize();
} }
onWindowResize.defer(); onWindowResize.defer();
Event.observe(window, "resize", onWindowResize); Event.observe(window, "resize", onWindowResize);
} }
@ -1773,8 +1773,8 @@ function initMailboxTree() {
mailboxTree.pendingRequests = mailAccounts.length; mailboxTree.pendingRequests = mailAccounts.length;
activeAjaxRequests += mailAccounts.length; activeAjaxRequests += mailAccounts.length;
for (var i = 0; i < mailAccounts.length; i++) { for (var i = 0; i < mailAccounts.length; i++) {
var url = ApplicationBaseURL + encodeURI(mailAccounts[i][0]) + "/mailboxes"; var url = ApplicationBaseURL + i + "/mailboxes";
triggerAjaxRequest(url, onLoadMailboxesCallback, mailAccounts[i]); triggerAjaxRequest(url, onLoadMailboxesCallback, i);
} }
} }
@ -1909,9 +1909,7 @@ function generateMenuForMailbox(mailbox, prefix, callback) {
callbacks.push(callback); callbacks.push(callback);
} }
} }
var menuWidth = parseInt(menu.offsetWidth) + 15 menu.style.width = (parseInt(menu.offsetWidth) + 15) + "px";
menuWidth = menuWidth + "px";
menu.style.width = menuWidth;
initMenu(menuDIV, callbacks); initMenu(menuDIV, callbacks);
@ -1940,9 +1938,9 @@ function updateMailboxMenus() {
var submenuIds = new Array(); var submenuIds = new Array();
for (var i = 0; i < mailAccounts.length; i++) { for (var i = 0; i < mailAccounts.length; i++) {
var menuEntry = mailboxMenuNode("account", mailAccounts[i][1]); var menuEntry = mailboxMenuNode("account", mailAccounts[i]);
menu.appendChild(menuEntry); menu.appendChild(menuEntry);
var mailbox = accounts[mailAccounts[i]]; var mailbox = accounts[i];
var newSubmenuId = generateMenuForMailbox(mailbox, var newSubmenuId = generateMenuForMailbox(mailbox,
key, mailboxActions[key]); key, mailboxActions[key]);
submenuIds.push(newSubmenuId); submenuIds.push(newSubmenuId);
@ -1955,9 +1953,9 @@ function onLoadMailboxesCallback(http) {
if (http.status == 200) { if (http.status == 200) {
checkAjaxRequestsState(); checkAjaxRequestsState();
if (http.responseText.length > 0) { if (http.responseText.length > 0) {
var newAccount = buildMailboxes(http.callbackData, var accountIdx = parseInt(http.callbackData);
http.responseText); var newAccount = buildMailboxes(accountIdx, http.responseText);
accounts[http.callbackData] = newAccount; accounts[accountIdx] = newAccount;
mailboxTree.addMailAccount(newAccount); mailboxTree.addMailAccount(newAccount);
mailboxTree.pendingRequests--; mailboxTree.pendingRequests--;
activeAjaxRequests--; activeAjaxRequests--;
@ -1991,17 +1989,17 @@ function onLoadMailboxesCallback(http) {
// } // }
} }
function buildMailboxes(accountKeys, encoded) { function buildMailboxes(accountIdx, encoded) {
var account = new Mailbox("account", accountKeys[1], var account = new Mailbox("account", "" + accountIdx,
undefined, //necessary, null will cause issues undefined, //necessary, null will cause issues
accountKeys[1]); mailAccounts[accountIdx]);
var data = encoded.evalJSON(true); var data = encoded.evalJSON(true);
var mailboxes = data.mailboxes; var mailboxes = data.mailboxes;
var unseen = (data.status? data.status.unseen : 0); var unseen = (data.status? data.status.unseen : 0);
if (data.quotas) if (data.quotas)
Mailer.quotas = data.quotas; Mailer.quotas = data.quotas;
for (var i = 0; i < mailboxes.length; i++) { for (var i = 0; i < mailboxes.length; i++) {
var currentNode = account; var currentNode = account;
var names = mailboxes[i].path.split("/"); var names = mailboxes[i].path.split("/");
@ -2163,13 +2161,13 @@ function onMenuLabelNone() {
else else
// Menu called from one selection in messages list view // Menu called from one selection in messages list view
messages.push(document.menuTarget.getAttribute("id").substr(4)); messages.push(document.menuTarget.getAttribute("id").substr(4));
var url = ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/"; var url = ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/";
messages.each(function(id) { messages.each(function(id) {
triggerAjaxRequest(url + id + "/removeAllLabels", triggerAjaxRequest(url + id + "/removeAllLabels",
messageFlagCallback, messageFlagCallback,
{ mailbox: Mailer.currentMailbox, msg: id, label: null } ); { mailbox: Mailer.currentMailbox, msg: id, label: null } );
}); });
} }
function _onMenuLabelFlagX(flag) { function _onMenuLabelFlagX(flag) {
@ -2189,12 +2187,12 @@ function _onMenuLabelFlagX(flag) {
// Menu called from one selection in messages list view // Menu called from one selection in messages list view
messages.set(document.menuTarget.getAttribute("id").substr(4), messages.set(document.menuTarget.getAttribute("id").substr(4),
document.menuTarget.getAttribute("labels")); document.menuTarget.getAttribute("labels"));
var url = ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/"; var url = ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/";
messages.keys().each(function(id) { messages.keys().each(function(id) {
var flags = messages.get(id).split(" "); var flags = messages.get(id).split(" ");
var operation = "add"; var operation = "add";
if (flags.indexOf("label" + flag) > -1) if (flags.indexOf("label" + flag) > -1)
operation = "remove"; operation = "remove";
@ -2484,16 +2482,16 @@ Mailbox.prototype = {
function configureDraggables () { function configureDraggables () {
var mainElement = $("dragDropVisual"); var mainElement = $("dragDropVisual");
Draggables.empty (); Draggables.empty ();
if (mainElement == null) { if (mainElement == null) {
mainElement = new Element ("div", {id: "dragDropVisual"}); mainElement = new Element ("div", {id: "dragDropVisual"});
document.body.appendChild(mainElement); document.body.appendChild(mainElement);
mainElement.absolutize (); mainElement.absolutize ();
} }
mainElement.hide(); mainElement.hide();
new Draggable ("dragDropVisual", new Draggable ("dragDropVisual",
{ handle: "messageListBody", { handle: "messageListBody",
onStart: startDragging, onStart: startDragging,
onEnd: stopDragging, onEnd: stopDragging,
onDrag: whileDragging, onDrag: whileDragging,
@ -2502,11 +2500,11 @@ function configureDraggables () {
function configureDroppables () { function configureDroppables () {
var drops = $$("div#dmailboxTree1 div.dTreeNode a.node span.nodeName"); var drops = $$("div#dmailboxTree1 div.dTreeNode a.node span.nodeName");
Droppables.empty (); Droppables.empty ();
drops.each (function (drop) { drops.each (function (drop) {
drop.identify () drop.identify ()
Droppables.add (drop.id, Droppables.add (drop.id,
{ hoverclass: "genericHoverClass", { hoverclass: "genericHoverClass",
onDrop: dropAction }); onDrop: dropAction });
}); });
@ -2516,10 +2514,10 @@ function startDragging (itm, e) {
var target = Event.element(e); var target = Event.element(e);
if (target.up('TBODY') == undefined) if (target.up('TBODY') == undefined)
return false; return false;
var handle = $("dragDropVisual"); var handle = $("dragDropVisual");
var count = $("messageListBody").getSelectedRowsId().length; var count = $("messageListBody").getSelectedRowsId().length;
handle.update (count); handle.update (count);
if (e.shiftKey) if (e.shiftKey)
handle.addClassName ("copy"); handle.addClassName ("copy");
@ -2546,7 +2544,7 @@ function stopDragging () {
function dropAction (dropped, zone, e) { function dropAction (dropped, zone, e) {
var destination = zone.up("div.dTreeNode"); var destination = zone.up("div.dTreeNode");
var f; var f;
if ($("dragDropVisual").hasClassName("copy")) { if ($("dragDropVisual").hasClassName("copy")) {
// Message(s) copied // Message(s) copied
f = onMailboxMenuCopy.bind(destination); f = onMailboxMenuCopy.bind(destination);
@ -2555,6 +2553,6 @@ function dropAction (dropped, zone, e) {
// Message(s) moved // Message(s) moved
f = onMailboxMenuMove.bind(destination); f = onMailboxMenuMove.bind(destination);
} }
f(); f();
} }