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>
* 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.

View File

@ -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;

View File

@ -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;
}
host = [self _urlHostString];
if (![host rangeOfString: @"@"].length)
[urlString appendFormat: @"%@@", [self imap4LoginFromHTTP]];
[urlString appendFormat: @"%@/", host];
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: @"/"];
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 */

View File

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

View File

@ -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;
return self;
}
user = [SOGoUser userWithLogin: [self ownerInContext: nil]];
- (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;
return [accountKeys allKeys];
user = [SOGoUser userWithLogin: [self ownerInContext: nil]];
accounts = [user mailAccounts];
max = [accounts count];
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];
// 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"];
// }
NSArray *accounts;
SOGoUser *user;
int keyCount;
/* 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])
{
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];
[obj setAccountName: accountName];
}
else
obj = [NSException exceptionWithHTTPStatus: 404 /* Not Found */];
}

View File

@ -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 <WOActionResults>) 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];

View File

@ -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') {
@ -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);
}
}
@ -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,10 +1989,10 @@ 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);