2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2004-2005 SKYRIX Software AG
|
|
|
|
|
|
|
|
This file is part of OpenGroupware.org.
|
|
|
|
|
|
|
|
OGo is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License as published by the
|
|
|
|
Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
later version.
|
|
|
|
|
|
|
|
OGo is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with OGo; see the file COPYING. If not, write to the
|
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2008-07-04 18:06:09 +02:00
|
|
|
#import <Foundation/NSEnumerator.h>
|
2008-02-01 17:28:53 +01:00
|
|
|
#import <Foundation/NSValue.h>
|
2008-10-02 17:00:13 +02:00
|
|
|
#import <Foundation/NSUserDefaults.h>
|
2007-12-17 16:29:06 +01:00
|
|
|
|
2008-07-08 13:32:43 +02:00
|
|
|
#import <NGCards/NGVCard.h>
|
2007-11-09 00:18:52 +01:00
|
|
|
#import <NGObjWeb/WOContext.h>
|
2007-07-27 19:30:37 +02:00
|
|
|
#import <NGObjWeb/WORequest.h>
|
2007-12-17 16:29:06 +01:00
|
|
|
#import <NGObjWeb/WOResponse.h>
|
2007-07-27 19:30:37 +02:00
|
|
|
#import <NGObjWeb/SoComponent.h>
|
|
|
|
#import <NGExtensions/NSString+misc.h>
|
|
|
|
|
2008-07-08 13:32:43 +02:00
|
|
|
#import <Contacts/SOGoContactObject.h>
|
|
|
|
#import <Contacts/SOGoContactFolders.h>
|
|
|
|
|
2007-05-25 23:19:31 +02:00
|
|
|
#import <SoObjects/Mailer/SOGoMailObject.h>
|
2008-02-01 17:28:53 +01:00
|
|
|
#import <SoObjects/Mailer/SOGoMailAccount.h>
|
2007-05-25 23:19:31 +02:00
|
|
|
#import <SoObjects/Mailer/SOGoMailAccounts.h>
|
2007-08-21 16:49:48 +02:00
|
|
|
#import <SoObjects/SOGo/NSDictionary+URL.h>
|
2007-08-15 23:09:50 +02:00
|
|
|
#import <SoObjects/SOGo/NSArray+Utilities.h>
|
|
|
|
#import <SoObjects/SOGo/SOGoUser.h>
|
2008-07-08 13:32:43 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoUserFolder.h>
|
2006-07-29 00:59:11 +02:00
|
|
|
#import <SOGoUI/UIxComponent.h>
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-07-27 19:30:37 +02:00
|
|
|
#import "UIxMailMainFrame.h"
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
@implementation UIxMailMainFrame
|
|
|
|
|
2007-12-13 22:07:09 +01:00
|
|
|
- (void) _setupContext
|
|
|
|
{
|
|
|
|
SOGoUser *activeUser;
|
|
|
|
NSString *login, *module;
|
|
|
|
SOGoMailAccounts *clientObject;
|
|
|
|
|
|
|
|
activeUser = [context activeUser];
|
|
|
|
login = [activeUser login];
|
|
|
|
clientObject = [self clientObject];
|
|
|
|
|
|
|
|
module = [clientObject nameInContainer];
|
|
|
|
|
|
|
|
ud = [activeUser userSettings];
|
|
|
|
moduleSettings = [ud objectForKey: module];
|
|
|
|
if (!moduleSettings)
|
|
|
|
{
|
|
|
|
moduleSettings = [NSMutableDictionary new];
|
|
|
|
[moduleSettings autorelease];
|
|
|
|
}
|
|
|
|
[ud setObject: moduleSettings forKey: module];
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* accessors */
|
2008-10-23 17:35:20 +02:00
|
|
|
|
|
|
|
#warning this method is a duplication of SOGoMailAccounts:toManyRelationShipKeys
|
2007-05-25 23:19:31 +02:00
|
|
|
- (NSString *) mailAccounts
|
|
|
|
{
|
2007-08-15 23:09:50 +02:00
|
|
|
NSArray *accounts, *accountNames;
|
2007-05-25 23:19:31 +02:00
|
|
|
|
2007-08-15 23:09:50 +02:00
|
|
|
accounts = [[context activeUser] mailAccounts];
|
2008-10-23 17:35:20 +02:00
|
|
|
accountNames = [accounts objectsForKey: @"name" notFoundMarker: nil];
|
2007-05-25 23:19:31 +02:00
|
|
|
|
2007-08-15 23:09:50 +02:00
|
|
|
return [accountNames jsonRepresentation];
|
2007-05-25 23:19:31 +02:00
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-10-02 17:00:13 +02:00
|
|
|
- (NSString *) defaultColumnsOrder
|
|
|
|
{
|
|
|
|
NSArray *defaultColumnsOrder;
|
|
|
|
NSUserDefaults *sud;
|
|
|
|
|
|
|
|
sud = [NSUserDefaults standardUserDefaults];
|
|
|
|
defaultColumnsOrder = [NSArray arrayWithArray: [sud arrayForKey: @"SOGoMailListViewColumnsOrder"]];
|
2008-10-02 17:16:50 +02:00
|
|
|
if ( [defaultColumnsOrder count] == 0 )
|
|
|
|
{
|
|
|
|
defaultColumnsOrder = [NSArray arrayWithObjects: @"Invisible", @"Attachment", @"Subject",
|
|
|
|
@"From", @"Unread", @"Date", @"Priority", nil];
|
|
|
|
}
|
2008-10-02 17:00:13 +02:00
|
|
|
|
2008-10-02 17:16:50 +02:00
|
|
|
return [defaultColumnsOrder jsonRepresentation];
|
2008-10-02 17:00:13 +02:00
|
|
|
}
|
|
|
|
|
2007-08-15 23:09:50 +02:00
|
|
|
- (NSString *) pageFormURL
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSString *u;
|
|
|
|
NSRange r;
|
|
|
|
|
|
|
|
u = [[[self context] request] uri];
|
|
|
|
if ((r = [u rangeOfString:@"?"]).length > 0) {
|
|
|
|
/* has query parameters */
|
|
|
|
// TODO: this is ugly, create reusable link facility in SOPE
|
|
|
|
// TODO: remove 'search' and 'filterpopup', preserve sorting
|
|
|
|
NSMutableString *ms;
|
|
|
|
NSArray *qp;
|
|
|
|
unsigned i, count;
|
|
|
|
|
|
|
|
qp = [[u substringFromIndex:(r.location + r.length)]
|
|
|
|
componentsSeparatedByString:@"&"];
|
|
|
|
count = [qp count];
|
|
|
|
ms = [NSMutableString stringWithCapacity:count * 12];
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
NSString *s;
|
|
|
|
|
|
|
|
s = [qp objectAtIndex:i];
|
|
|
|
|
|
|
|
/* filter out */
|
|
|
|
if ([s hasPrefix:@"search="]) continue;
|
|
|
|
if ([s hasPrefix:@"filterpopup="]) continue;
|
|
|
|
|
|
|
|
if ([ms length] > 0) [ms appendString:@"&"];
|
|
|
|
[ms appendString:s];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([ms length] == 0) {
|
|
|
|
/* no other query params */
|
|
|
|
u = [u substringToIndex:r.location];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
u = [u substringToIndex:r.location + r.length];
|
|
|
|
u = [u stringByAppendingString:ms];
|
|
|
|
}
|
|
|
|
return u;
|
|
|
|
}
|
|
|
|
return [u hasSuffix:@"/"] ? @"view" : @"#";
|
|
|
|
}
|
|
|
|
|
2007-08-21 16:49:48 +02:00
|
|
|
- (id <WOActionResults>) composeAction
|
|
|
|
{
|
2008-07-08 13:32:43 +02:00
|
|
|
id <SOGoContactObject> contact;
|
2008-09-26 23:08:26 +02:00
|
|
|
NSArray *accounts, *contactsId, *n;
|
|
|
|
NSString *firstAccount, *newLocation, *parameters, *folderId, *uid, *email;
|
2008-07-08 13:32:43 +02:00
|
|
|
NSMutableString *fn;
|
|
|
|
NSEnumerator *uids;
|
|
|
|
NSMutableArray *addresses;
|
|
|
|
NGVCard *card;
|
2007-08-21 16:49:48 +02:00
|
|
|
SOGoMailAccounts *co;
|
2008-07-08 13:32:43 +02:00
|
|
|
SOGoContactFolders *folders;
|
|
|
|
SOGoParentFolder *folder;
|
|
|
|
WORequest *request;
|
2008-08-21 19:42:31 +02:00
|
|
|
unsigned int max;
|
2007-08-21 16:49:48 +02:00
|
|
|
|
2008-07-08 13:32:43 +02:00
|
|
|
parameters = nil;
|
2007-08-21 16:49:48 +02:00
|
|
|
co = [self clientObject];
|
2008-07-08 13:32:43 +02:00
|
|
|
|
|
|
|
// We use the first mail account
|
2007-08-21 16:49:48 +02:00
|
|
|
accounts = [[context activeUser] mailAccounts];
|
2008-10-23 17:35:20 +02:00
|
|
|
firstAccount = [[accounts objectsForKey: @"name" notFoundMarker: nil]
|
|
|
|
objectAtIndex: 0];
|
2008-07-08 13:32:43 +02:00
|
|
|
request = [context request];
|
|
|
|
|
|
|
|
if ((folderId = [request formValueForKey: @"folder"]) &&
|
|
|
|
(contactsId = [request formValuesForKey: @"uid"]))
|
|
|
|
{
|
|
|
|
// Retrieve the email addresses from the specified address book
|
|
|
|
// and contact IDs
|
|
|
|
folders = [[[self clientObject] container] privateContacts: @"Contacts"
|
|
|
|
inContext: nil];
|
|
|
|
folder = [folders lookupName: folderId
|
|
|
|
inContext: nil
|
|
|
|
acquire: NO];
|
|
|
|
if (folder)
|
|
|
|
{
|
|
|
|
uids = [contactsId objectEnumerator];
|
|
|
|
uid = [uids nextObject];
|
|
|
|
|
|
|
|
addresses = [NSMutableArray new];
|
|
|
|
|
|
|
|
while (uid)
|
|
|
|
{
|
|
|
|
contact = [folder lookupName: uid
|
|
|
|
inContext: [self context]
|
|
|
|
acquire: NO];
|
|
|
|
if (![(NSObject*)contact isKindOfClass: [NSException class]])
|
|
|
|
{
|
|
|
|
// We fetch the preferred email address of the contact or
|
|
|
|
// the first defined email address
|
|
|
|
card = [contact vCard];
|
|
|
|
email = [card preferredEMail];
|
|
|
|
if (email == nil)
|
|
|
|
email = (NSString*)[card firstChildWithTag: @"EMAIL"];
|
|
|
|
if (email)
|
|
|
|
{
|
|
|
|
email = [NSString stringWithFormat: @"<%@>", email];
|
2008-08-21 19:42:31 +02:00
|
|
|
|
|
|
|
// We append the contact's name
|
2008-07-08 13:32:43 +02:00
|
|
|
fn = [NSMutableString stringWithString: [card fn]];
|
2008-08-21 19:42:31 +02:00
|
|
|
if ([fn length] == 0)
|
|
|
|
{
|
|
|
|
n = [card n];
|
|
|
|
if (n)
|
|
|
|
{
|
|
|
|
max = [n count];
|
|
|
|
if (max > 0)
|
|
|
|
{
|
|
|
|
if (max > 1)
|
|
|
|
fn = [NSMutableString stringWithFormat: @"%@ %@", [n objectAtIndex: 1], [n objectAtIndex: 0]];
|
|
|
|
else
|
|
|
|
fn = [NSMutableString stringWithString: [n objectAtIndex: 0]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-07-08 13:32:43 +02:00
|
|
|
if (fn)
|
|
|
|
{
|
|
|
|
[fn appendFormat: @" %@", email];
|
|
|
|
[addresses addObject: fn];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[addresses addObject: email];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uid = [uids nextObject];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([addresses count] > 0)
|
|
|
|
parameters = [NSString stringWithFormat: @"?mailto=%@", [addresses componentsJoinedByString: @","]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ([[request formValues] objectForKey: @"mailto"])
|
|
|
|
// We use the email addresses defined in the request
|
|
|
|
parameters = [[request formValues] asURLParameters];
|
|
|
|
|
|
|
|
if (!parameters)
|
|
|
|
// No parameter passed; simply open the compose window
|
|
|
|
parameters = @"?mailto=";
|
|
|
|
|
2007-08-21 16:49:48 +02:00
|
|
|
newLocation = [NSString stringWithFormat: @"%@/%@/compose%@",
|
|
|
|
[co baseURLInContext: context],
|
|
|
|
firstAccount,
|
2007-12-17 16:51:37 +01:00
|
|
|
parameters];
|
2007-08-21 16:49:48 +02:00
|
|
|
|
|
|
|
return [self redirectToLocation: newLocation];
|
|
|
|
}
|
|
|
|
|
2008-03-25 20:59:13 +01:00
|
|
|
- (WOResponse *) getFoldersStateAction
|
2008-02-01 19:44:58 +01:00
|
|
|
{
|
2008-03-25 20:59:13 +01:00
|
|
|
NSString *expandedFolders;
|
2008-02-01 19:44:58 +01:00
|
|
|
|
|
|
|
[self _setupContext];
|
2008-03-25 20:59:13 +01:00
|
|
|
expandedFolders = [moduleSettings objectForKey: @"ExpandedFolders"];
|
2008-02-01 19:44:58 +01:00
|
|
|
|
2008-03-25 20:59:13 +01:00
|
|
|
return [self responseWithStatus: 200 andString: expandedFolders];
|
|
|
|
}
|
2008-02-04 23:22:14 +01:00
|
|
|
|
2008-03-25 20:59:13 +01:00
|
|
|
- (NSString *) verticalDragHandleStyle
|
|
|
|
{
|
|
|
|
NSString *vertical;
|
|
|
|
|
|
|
|
[self _setupContext];
|
|
|
|
vertical = [moduleSettings objectForKey: @"DragHandleVertical"];
|
|
|
|
|
2008-08-30 01:58:16 +02:00
|
|
|
return ((vertical && [vertical intValue] > 0) ? [vertical stringByAppendingFormat: @"px"] : nil);
|
2008-02-01 19:44:58 +01:00
|
|
|
}
|
|
|
|
|
2008-03-25 20:59:13 +01:00
|
|
|
- (NSString *) horizontalDragHandleStyle
|
2007-12-13 22:07:09 +01:00
|
|
|
{
|
2008-03-25 20:59:13 +01:00
|
|
|
NSString *horizontal;
|
2007-12-13 22:07:09 +01:00
|
|
|
|
2008-03-25 20:59:13 +01:00
|
|
|
[self _setupContext];
|
|
|
|
horizontal = [moduleSettings objectForKey: @"DragHandleHorizontal"];
|
2007-12-13 22:07:09 +01:00
|
|
|
|
2008-08-30 01:58:16 +02:00
|
|
|
return ((horizontal && [horizontal intValue] > 0) ? [horizontal stringByAppendingFormat: @"px"] : nil);
|
2008-03-25 20:59:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) mailboxContentStyle
|
|
|
|
{
|
|
|
|
NSString *height;
|
|
|
|
|
|
|
|
[self _setupContext];
|
|
|
|
height = [moduleSettings objectForKey: @"DragHandleVertical"];
|
|
|
|
|
2008-08-30 01:58:16 +02:00
|
|
|
return ((height && [height intValue] > 0) ? [NSString stringWithFormat: @"%ipx", ([height intValue] - 27)] : nil);
|
2007-12-13 22:07:09 +01:00
|
|
|
}
|
|
|
|
|
2008-02-04 23:22:14 +01:00
|
|
|
- (WOResponse *) saveDragHandleStateAction
|
2008-02-01 19:44:58 +01:00
|
|
|
{
|
|
|
|
WORequest *request;
|
2008-02-04 23:22:14 +01:00
|
|
|
NSString *dragHandle;
|
2008-02-01 19:44:58 +01:00
|
|
|
|
|
|
|
[self _setupContext];
|
|
|
|
request = [context request];
|
|
|
|
|
2008-02-04 23:22:14 +01:00
|
|
|
if ((dragHandle = [request formValueForKey: @"vertical"]) != nil)
|
|
|
|
[moduleSettings setObject: dragHandle
|
|
|
|
forKey: @"DragHandleVertical"];
|
|
|
|
else if ((dragHandle = [request formValueForKey: @"horizontal"]) != nil)
|
|
|
|
[moduleSettings setObject: dragHandle
|
|
|
|
forKey: @"DragHandleHorizontal"];
|
|
|
|
else
|
|
|
|
return [self responseWithStatus: 400];
|
|
|
|
|
2008-02-01 19:44:58 +01:00
|
|
|
[ud synchronize];
|
2008-02-04 23:22:14 +01:00
|
|
|
|
2008-02-01 19:44:58 +01:00
|
|
|
return [self responseWithStatus: 204];
|
|
|
|
}
|
|
|
|
|
2007-12-13 22:07:09 +01:00
|
|
|
- (WOResponse *) saveFoldersStateAction
|
|
|
|
{
|
|
|
|
WORequest *request;
|
|
|
|
NSString *expandedFolders;
|
|
|
|
|
|
|
|
[self _setupContext];
|
|
|
|
request = [context request];
|
|
|
|
expandedFolders = [request formValueForKey: @"expandedFolders"];
|
|
|
|
|
|
|
|
[moduleSettings setObject: expandedFolders
|
|
|
|
forKey: @"ExpandedFolders"];
|
|
|
|
|
|
|
|
[ud synchronize];
|
|
|
|
|
|
|
|
return [self responseWithStatus: 204];
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
@end /* UIxMailMainFrame */
|