From 9100c3db2fe5413e484a0672588ec520299438d8 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Tue, 3 Aug 2010 18:52:49 +0000 Subject: [PATCH] Monotone-Parent: 34791f35dbfae81d89b325cab373497ac8267859 Monotone-Revision: d60b33f55567caeee757661e23d65eee6e952ed9 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2010-08-03T18:52:49 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 28 +++++++ SoObjects/Mailer/SOGoMailAccount.h | 3 - SoObjects/Mailer/SOGoMailAccount.m | 109 ++++++++---------------- SoObjects/Mailer/SOGoMailAccounts.h | 6 +- SoObjects/Mailer/SOGoMailAccounts.m | 114 +++++++------------------ UI/MailerUI/UIxMailMainFrame.m | 42 ++-------- UI/WebServerResources/MailerUI.js | 126 ++++++++++++++-------------- 7 files changed, 165 insertions(+), 263 deletions(-) diff --git a/ChangeLog b/ChangeLog index f218683f8..5a4393a3e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,33 @@ 2010-08-03 Wolfgang Sourdeau + * 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: RowEditionController.startEditing: keep the "_selected" class when starting edition, if exists. diff --git a/SoObjects/Mailer/SOGoMailAccount.h b/SoObjects/Mailer/SOGoMailAccount.h index b442e1a20..2e9026ff6 100644 --- a/SoObjects/Mailer/SOGoMailAccount.h +++ b/SoObjects/Mailer/SOGoMailAccount.h @@ -50,7 +50,6 @@ typedef enum { @interface SOGoMailAccount : SOGoMailBaseObject { - NSString *accountName; SOGoMailFolder *inboxFolder; SOGoDraftsFolder *draftsFolder; SOGoSentFolder *sentFolder; @@ -58,8 +57,6 @@ typedef enum { SOGoIMAPAclStyle imapAclStyle; } -- (void) setAccountName: (NSString *) newAccountName; - - (SOGoIMAPAclStyle) imapAclStyle; - (BOOL) imapAclConformsToIMAPExt; diff --git a/SoObjects/Mailer/SOGoMailAccount.m b/SoObjects/Mailer/SOGoMailAccount.m index 74cd6ea67..70ab35325 100644 --- a/SoObjects/Mailer/SOGoMailAccount.m +++ b/SoObjects/Mailer/SOGoMailAccount.m @@ -69,7 +69,6 @@ static NSString *sieveScriptName = @"sogo"; draftsFolder = nil; sentFolder = nil; trashFolder = nil; - accountName = nil; imapAclStyle = undefined; } @@ -82,15 +81,9 @@ static NSString *sieveScriptName = @"sogo"; [draftsFolder release]; [sentFolder release]; [trashFolder release]; - [accountName release]; [super dealloc]; } -- (void) setAccountName: (NSString *) newAccountName -{ - ASSIGN (accountName, newAccountName); -} - /* listing the available folders */ - (BOOL) isInDraftsFolder @@ -475,11 +468,6 @@ static NSString *sieveScriptName = @"sogo"; /* IMAP4 */ -- (BOOL) useSSL -{ - return NO; -} - - (NSString *) imap4LoginFromHTTP { WORequest *rq; @@ -505,46 +493,52 @@ static NSString *sieveScriptName = @"sogo"; return [creds objectAtIndex:0]; /* the user */ } -- (NSString *) _urlHostString +- (NSDictionary *) _mailAccount { NSDictionary *mailAccount; - NSString *username, *escUsername, *hostString; + NSArray *accounts; + SOGoUser *user; - mailAccount = [[context activeUser] accountWithName: accountName]; - if (mailAccount) - { - username = [mailAccount objectForKey: @"userName"]; - escUsername - = [[username stringByEscapingURL] stringByReplacingString: @"@" - withString: @"%40"]; - hostString = [NSString stringWithFormat: @"%@@%@", escUsername, - [mailAccount objectForKey: @"serverName"]]; - } - else - hostString = @"localhost"; + user = [SOGoUser userWithLogin: [self ownerInContext: nil]]; + accounts = [user mailAccounts]; + mailAccount = [accounts objectAtIndex: [nameInContainer intValue]]; - return hostString; + return mailAccount; } - (NSMutableString *) imap4URLString { - /* private, overridden by SOGoSharedMailAccount */ - NSMutableString *urlString; - NSString *host; + NSMutableString *imap4URLString; + NSDictionary *mailAccount; + NSString *encryption, *protocol, *username, *escUsername; + int defaultPort, port; - urlString = [NSMutableString string]; - - if ([self useSSL]) - [urlString appendString: @"imaps://"]; + mailAccount = [self _mailAccount]; + encryption = [mailAccount objectForKey: @"encryption"]; + if ([encryption isEqualToString: @"ssl"]) + { + protocol = @"imaps"; + defaultPort = 993; + } 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]; - if (![host rangeOfString: @"@"].length) - [urlString appendFormat: @"%@@", [self imap4LoginFromHTTP]]; - [urlString appendFormat: @"%@/", host]; - - return urlString; + return imap4URLString; } - (NSMutableString *) traversalFromMailAccount @@ -800,40 +794,9 @@ static NSString *sieveScriptName = @"sogo"; 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 { - return [self shortTitle]; + return [[self _mailAccount] objectForKey: @"name"]; } @end /* SOGoMailAccount */ diff --git a/SoObjects/Mailer/SOGoMailAccounts.h b/SoObjects/Mailer/SOGoMailAccounts.h index acf179dc9..2fe066a31 100644 --- a/SoObjects/Mailer/SOGoMailAccounts.h +++ b/SoObjects/Mailer/SOGoMailAccounts.h @@ -41,12 +41,10 @@ @class NSMutableDictionary; @interface SOGoMailAccounts : SOGoFolder -{ - NSMutableDictionary *accountKeys; -} + +- (NSArray *) mailAccounts; - (NSArray *) toManyRelationshipKeys; -- (NSDictionary *) accountKeys; @end diff --git a/SoObjects/Mailer/SOGoMailAccounts.m b/SoObjects/Mailer/SOGoMailAccounts.m index 1db84bdf9..fda419240 100644 --- a/SoObjects/Mailer/SOGoMailAccounts.m +++ b/SoObjects/Mailer/SOGoMailAccounts.m @@ -36,113 +36,55 @@ @implementation SOGoMailAccounts -/* listing the available mailboxes */ - -// - (BOOL) isInHomeFolderBranchOfLoggedInAccount: (NSString *) userLogin -// { -// return [[container nameInContainer] isEqualToString: userLogin]; -// } - -- (id) init +- (NSArray *) mailAccounts { - if ((self = [super init])) - { - accountKeys = nil; - } + SOGoUser *user; + + user = [SOGoUser userWithLogin: [self ownerInContext: nil]]; - return self; -} - -- (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; + return [user mailAccounts]; } - (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 */ -// - (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 inContext: (id) _ctx acquire: (BOOL) _flag { id obj; - NSString *accountName; -// NSString *userLogin; - -// userLogin = [[context activeUser] login]; + NSArray *accounts; + SOGoUser *user; + int keyCount; -// 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 */ obj = [super lookupName:_key inContext:_ctx acquire:NO]; if (!obj) { - [self _initAccountKeys]; - accountName = [accountKeys objectForKey: _key]; - if ([accountName length]) - { - obj = [SOGoMailAccount objectWithName: _key inContainer: self]; - [obj setAccountName: accountName]; - } + user = [SOGoUser userWithLogin: [self ownerInContext: nil]]; + accounts = [user mailAccounts]; + + keyCount = [_key intValue]; + if ([_key isEqualToString: [NSString stringWithFormat: @"%d", keyCount]] + && keyCount > -1 && keyCount < [accounts count]) + obj = [SOGoMailAccount objectWithName: _key inContainer: self]; else obj = [NSException exceptionWithHTTPStatus: 404 /* Not Found */]; } diff --git a/UI/MailerUI/UIxMailMainFrame.m b/UI/MailerUI/UIxMailMainFrame.m index fc8aabb59..67fe617c0 100644 --- a/UI/MailerUI/UIxMailMainFrame.m +++ b/UI/MailerUI/UIxMailMainFrame.m @@ -103,27 +103,12 @@ - (NSString *) mailAccounts { - SOGoMailAccounts *accounts; - NSDictionary *accountKeys; - NSArray *keys, *entry; - NSMutableArray *values; - NSString *key; - int i, max; + NSArray *accounts, *names; - accounts = [self clientObject]; - accountKeys = [accounts accountKeys]; - keys = [accountKeys allKeys]; - values = [NSMutableArray array]; + accounts = [[self clientObject] mailAccounts]; + names = [accounts objectsForKey: @"name" notFoundMarker: nil]; - max = [keys count]; - for (i = 0; i < max; i++) - { - key = [keys objectAtIndex: i]; - entry = [NSArray arrayWithObjects: key, [accountKeys objectForKey: key], nil]; - [values addObject: entry]; - } - - return [values jsonRepresentation]; + return [names jsonRepresentation]; } - (NSString *) defaultColumnsOrder @@ -182,21 +167,18 @@ SOGoMailAccounts *accounts; SOGoMailAccount *account; SOGoMailFolder *inbox; - - NSString *firstAccount; NSDictionary *data; SOGoUser *activeUser; UIxMailListActions *actions; [self _setupContext]; +#warning this code is dirty: we should not invoke UIxMailListActions from here! actions = [[[UIxMailListActions new] initWithRequest: [context request]] autorelease]; activeUser = [context activeUser]; accounts = [self clientObject]; - firstAccount = [[[accounts accountKeys] allKeys] - objectAtIndex: 0]; - account = [accounts lookupName: firstAccount inContext: context acquire: NO]; + account = [accounts lookupName: @"0" inContext: context acquire: NO]; inbox = [account inboxFolderInContext: context]; data = [actions getUIDsAndHeadersInFolder: inbox]; @@ -207,8 +189,8 @@ - (id ) composeAction { id contact; - NSArray *accounts, *contactsId, *cards; - NSString *firstAccount, *firstEscapedAccount, *newLocation, *parameters, *folderId, *uid, *formattedMail; + NSArray *contactsId, *cards; + NSString *newLocation, *parameters, *folderId, *uid, *formattedMail; NSEnumerator *uids; NSMutableArray *addresses; NGVCard *card; @@ -222,11 +204,6 @@ parameters = nil; 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]; if ((folderId = [request formValueForKey: @"folder"]) && @@ -290,9 +267,8 @@ // No parameter passed; simply open the compose window parameters = @"?mailto="; - newLocation = [NSString stringWithFormat: @"%@/%@/compose%@", + newLocation = [NSString stringWithFormat: @"%@/0/compose%@", [co baseURLInContext: context], - firstEscapedAccount, parameters]; return [self redirectToLocation: newLocation]; diff --git a/UI/WebServerResources/MailerUI.js b/UI/WebServerResources/MailerUI.js index a32c13810..db6bfe458 100644 --- a/UI/WebServerResources/MailerUI.js +++ b/UI/WebServerResources/MailerUI.js @@ -1,7 +1,7 @@ /* -*- Mode: js2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* JavaScript for SOGoMail */ -var accounts = {}; +var accounts = []; var mailboxTree; var mailAccounts; if (typeof textMailAccounts != 'undefined') { @@ -223,10 +223,10 @@ function mailListMarkMessage(event) { action = 'markMessageUnread'; markread = false; } - + markMailInWindow(window, msguid, markread); - var url = ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/" + var url = ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/" + msguid + "/" + action; var data = { "msguid": msguid }; @@ -260,10 +260,10 @@ function mailListFlagMessageToggle (e) { action = "markMessageUnflagged"; flagged = false; } - + flagMailInWindow(window, msguid, flagged); - - var url = ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/" + + var url = ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/" + msguid + "/" + action; var data = { "msguid": msguid }; @@ -283,7 +283,7 @@ function mailListFlagMessageToggleCallback (http) { function onUnload(event) { var url = ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/expunge"; - + new Ajax.Request(url, { asynchronous: false, method: 'get', @@ -315,7 +315,7 @@ function onDocumentKeydown(event) { if (nextRow && nextRow.id != 'rowTop' && nextRow.id != 'rowBottom') { Mailer.currentMessages[Mailer.currentMailbox] = nextRow.getAttribute("id").substr(4); row.up().deselectAll(); - + // Adjust the scollbar var viewPort = $("mailboxList"); var divDimensions = viewPort.getDimensions(); @@ -328,7 +328,7 @@ function onDocumentKeydown(event) { viewPort.scrollTop += rowBottom - divBottom + centerOffset; else if (viewPort.scrollTop > nextRow.offsetTop) viewPort.scrollTop -= rowScrollOffset.top - nextRow.offsetTop + centerOffset; - + // Select and load the next message nextRow.selectElement(); loadMessage(Mailer.currentMessages[Mailer.currentMailbox]); @@ -375,7 +375,7 @@ function deleteSelectedMessages(sender) { } else window.alert(_("Please select a message.")); - + return false; } @@ -493,10 +493,10 @@ function onMailboxTreeItemClick(event) { toggleAddressColumn("from", "to"); else toggleAddressColumn("to", "from"); - + openMailbox(mailbox); } - + Event.stop(event); } @@ -519,7 +519,7 @@ function onMailboxMenuMove(event) { var rows = messageList.getSelectedNodes(); var uids = new Array(); // message IDs var paths = new Array(); // row IDs - + Mailer.currentMessages[Mailer.currentMailbox] = null; $('messageContent').update(); @@ -611,11 +611,11 @@ function composeNewMessage() { if (Mailer.currentMailbox) account = Mailer.currentMailbox.split("/")[1]; else if (mailAccounts.length) - account = mailAccounts[0][0]; + account = "0"; else account = null; if (account) { - var url = ApplicationBaseURL + "/" + encodeURI(account) + "/compose"; + var url = ApplicationBaseURL + encodeURI(account) + "/compose"; openMailComposeWindow(url); } } @@ -624,7 +624,7 @@ function openMailbox(mailbox, reload, updateStatus) { if (mailbox != Mailer.currentMailbox || reload) { var url = ApplicationBaseURL + encodeURI(mailbox); var urlParams = new Hash(); - + if (!reload) { var messageContent = $("messageContent"); messageContent.update(); @@ -641,7 +641,7 @@ function openMailbox(mailbox, reload, updateStatus) { if (sortAttribute && sortAttribute.length > 0) { urlParams.set("sort", sorting["attribute"]); urlParams.set("asc", sorting["ascending"]); - + var sortHeader = $(sorting["attribute"] + "Header"); if (sortHeader) { 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("&"); key += "?" + p; } - + var dataSource = Mailer.dataSources.get(key); if (!dataSource || reload) { dataSource = new SOGoMailDataSource(Mailer.dataTable, url); @@ -704,7 +704,7 @@ function messageListCallback(row, data, isNew) { row.id = data['rowID']; row.writeAttribute('labels', (data['labels']?data['labels']:"")); row.className = data['rowClasses']; - + // Restore previous selection if (data['uid'] == currentMessage) row.addClassName('_selected'); @@ -755,7 +755,7 @@ function getStatusFolders() { function statusFoldersCallback(http) { var div = $('mailboxContent'); var table = $('messageList'); - + if (http.status == 200) { document.statusFoldersAjaxRequest = null; var data = http.responseText.evalJSON(true); @@ -766,7 +766,7 @@ function statusFoldersCallback(http) { function updateStatusFolders(count, isDelta) { var span = $("unseenCount"); var counter = null; - + if (span) counter = span.select("SPAN").first(); @@ -794,7 +794,7 @@ function updateMessageListCounter(count, isDelta) { var value = parseInt(cell.innerHTML); count += value; } - + if (count > 0) cell.update(count + " " + _("messages")); else @@ -820,11 +820,11 @@ function onMessageContextMenu(event) { var selectedNodes = topNode.getSelectedRows(); menu.observe("hideMenu", onMessageContextMenuHide); - + if (selectedNodes.length > 1) popupMenu(event, "messagesListMenu", selectedNodes); else - popupMenu(event, "messageListMenu", this); + popupMenu(event, "messageListMenu", this); } function onMessageContextMenuHide(event) { @@ -890,7 +890,7 @@ function deleteCachedMailboxByType(type) { var nodes = $("mailboxTree").select("DIV[datatype=" + type + "]"); if (nodes.length == 1) deleteCachedMailbox(nodes[0].readAttribute("dataname")); - + if (Mailer.currentMailboxType == type) refreshCurrentFolder(); } @@ -1154,7 +1154,7 @@ function configureiCalLinksInMessage() { delegatedTo.uidField = "c_mail"; delegatedTo.excludeGroups = true; delegatedTo.excludeLists = true; - + var editDelegate = $("editDelegate"); if (editDelegate) { // The user delegates the invitation @@ -1260,7 +1260,7 @@ function ICalendarButtonCallback(http) { function resizeMailContent() { var headerTable = document.getElementsByClassName('mailer_fieldtable')[0]; var contentDiv = document.getElementsByClassName('mailer_mailcontent')[0]; - + contentDiv.setStyle({ 'top': (Element.getHeight(headerTable) + headerTable.offsetTop) + 'px' }); @@ -1280,7 +1280,7 @@ function resizeMailContent() { function toggleDisplayHeader(event) { var row = this.up("TR"); var span = row.down("SPAN"); - + if (this.hasClassName("collapse")) { this.writeAttribute("src", ResourcesURL + '/minus.png'); this.writeAttribute("class", "expand"); @@ -1301,7 +1301,7 @@ function onMessageContentMenu(event) { var element = getTarget(event); if ((element.tagName == 'A' && element.href.substring(0,7) == "mailto:") || 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 return true; popupMenu(event, 'messageContentMenu', this); @@ -1371,7 +1371,7 @@ function loadMessageCallback(http) { resizeMailContent(); configureLoadImagesButton(); configureSignatureFlagImage(); - + if (http.callbackData) { var cachedMessage = new Array(); var msguid = http.callbackData.msguid; @@ -1538,7 +1538,7 @@ function expandUpperTree(node) { function onHeaderClick(event) { if (SOGoResizableTable._onHandle) return; - + var headerId = this.getAttribute("id"); var newSortAttribute; if (headerId == "subjectHeader") @@ -1560,9 +1560,9 @@ function onHeaderClick(event) { sorting["attribute"] = newSortAttribute; sorting["ascending"] = true; } - + refreshCurrentFolder(); - + Event.stop(event); } @@ -1581,7 +1581,7 @@ function configureMessageListEvents(headerTable, dataTable) { if (headerTable) // Sortable columns configureSortableTableHeaders(headerTable); - + if (dataTable) { dataTable.multiselect = true; // Each body row can load a message @@ -1704,7 +1704,7 @@ function initMailer(event) { initMailboxTree(); initMessageCheckTimer(); - + if (Prototype.Browser.Gecko) Event.observe(document, "keypress", onDocumentKeydown); // for FF2 else @@ -1721,7 +1721,7 @@ function initMailer(event) { onMessageListResize(); } - + onWindowResize.defer(); Event.observe(window, "resize", onWindowResize); } @@ -1773,8 +1773,8 @@ function initMailboxTree() { mailboxTree.pendingRequests = mailAccounts.length; activeAjaxRequests += mailAccounts.length; for (var i = 0; i < mailAccounts.length; i++) { - var url = ApplicationBaseURL + encodeURI(mailAccounts[i][0]) + "/mailboxes"; - triggerAjaxRequest(url, onLoadMailboxesCallback, mailAccounts[i]); + var url = ApplicationBaseURL + i + "/mailboxes"; + triggerAjaxRequest(url, onLoadMailboxesCallback, i); } } @@ -1909,9 +1909,7 @@ function generateMenuForMailbox(mailbox, prefix, callback) { callbacks.push(callback); } } - var menuWidth = parseInt(menu.offsetWidth) + 15 - menuWidth = menuWidth + "px"; - menu.style.width = menuWidth; + menu.style.width = (parseInt(menu.offsetWidth) + 15) + "px"; initMenu(menuDIV, callbacks); @@ -1940,9 +1938,9 @@ function updateMailboxMenus() { var submenuIds = new Array(); for (var i = 0; i < mailAccounts.length; i++) { - var menuEntry = mailboxMenuNode("account", mailAccounts[i][1]); + var menuEntry = mailboxMenuNode("account", mailAccounts[i]); menu.appendChild(menuEntry); - var mailbox = accounts[mailAccounts[i]]; + var mailbox = accounts[i]; var newSubmenuId = generateMenuForMailbox(mailbox, key, mailboxActions[key]); submenuIds.push(newSubmenuId); @@ -1955,9 +1953,9 @@ function onLoadMailboxesCallback(http) { if (http.status == 200) { checkAjaxRequestsState(); if (http.responseText.length > 0) { - var newAccount = buildMailboxes(http.callbackData, - http.responseText); - accounts[http.callbackData] = newAccount; + var accountIdx = parseInt(http.callbackData); + var newAccount = buildMailboxes(accountIdx, http.responseText); + accounts[accountIdx] = newAccount; mailboxTree.addMailAccount(newAccount); mailboxTree.pendingRequests--; activeAjaxRequests--; @@ -1991,17 +1989,17 @@ function onLoadMailboxesCallback(http) { // } } -function buildMailboxes(accountKeys, encoded) { - var account = new Mailbox("account", accountKeys[1], +function buildMailboxes(accountIdx, encoded) { + var account = new Mailbox("account", "" + accountIdx, undefined, //necessary, null will cause issues - accountKeys[1]); + mailAccounts[accountIdx]); var data = encoded.evalJSON(true); var mailboxes = data.mailboxes; var unseen = (data.status? data.status.unseen : 0); if (data.quotas) Mailer.quotas = data.quotas; - + for (var i = 0; i < mailboxes.length; i++) { var currentNode = account; var names = mailboxes[i].path.split("/"); @@ -2163,13 +2161,13 @@ function onMenuLabelNone() { else // Menu called from one selection in messages list view messages.push(document.menuTarget.getAttribute("id").substr(4)); - + var url = ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/"; messages.each(function(id) { triggerAjaxRequest(url + id + "/removeAllLabels", messageFlagCallback, { mailbox: Mailer.currentMailbox, msg: id, label: null } ); - }); + }); } function _onMenuLabelFlagX(flag) { @@ -2189,12 +2187,12 @@ function _onMenuLabelFlagX(flag) { // Menu called from one selection in messages list view messages.set(document.menuTarget.getAttribute("id").substr(4), document.menuTarget.getAttribute("labels")); - + var url = ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/"; messages.keys().each(function(id) { var flags = messages.get(id).split(" "); var operation = "add"; - + if (flags.indexOf("label" + flag) > -1) operation = "remove"; @@ -2484,16 +2482,16 @@ Mailbox.prototype = { function configureDraggables () { var mainElement = $("dragDropVisual"); Draggables.empty (); - + if (mainElement == null) { mainElement = new Element ("div", {id: "dragDropVisual"}); document.body.appendChild(mainElement); mainElement.absolutize (); } mainElement.hide(); - - new Draggable ("dragDropVisual", - { handle: "messageListBody", + + new Draggable ("dragDropVisual", + { handle: "messageListBody", onStart: startDragging, onEnd: stopDragging, onDrag: whileDragging, @@ -2502,11 +2500,11 @@ function configureDraggables () { function configureDroppables () { var drops = $$("div#dmailboxTree1 div.dTreeNode a.node span.nodeName"); - + Droppables.empty (); drops.each (function (drop) { drop.identify () - Droppables.add (drop.id, + Droppables.add (drop.id, { hoverclass: "genericHoverClass", onDrop: dropAction }); }); @@ -2516,10 +2514,10 @@ function startDragging (itm, e) { var target = Event.element(e); if (target.up('TBODY') == undefined) return false; - + var handle = $("dragDropVisual"); var count = $("messageListBody").getSelectedRowsId().length; - + handle.update (count); if (e.shiftKey) handle.addClassName ("copy"); @@ -2546,7 +2544,7 @@ function stopDragging () { function dropAction (dropped, zone, e) { var destination = zone.up("div.dTreeNode"); var f; - + if ($("dragDropVisual").hasClassName("copy")) { // Message(s) copied f = onMailboxMenuCopy.bind(destination); @@ -2555,6 +2553,6 @@ function dropAction (dropped, zone, e) { // Message(s) moved f = onMailboxMenuMove.bind(destination); } - + f(); }