Monotone-Parent: 5a9d1a37ff5b7e57b7c92db2cc2c56d3af92d80c

Monotone-Revision: 1c7442ef9f84ce58c394c1539163f94d731b3545

Monotone-Author: flachapelle@inverse.ca
Monotone-Date: 2008-07-08T11:32:43
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Francis Lachapelle
2008-07-08 11:32:43 +00:00
parent fe445c22f1
commit a19563f78b
9 changed files with 197 additions and 168 deletions
+78 -7
View File
@@ -23,18 +23,23 @@
#import <Foundation/NSUserDefaults.h>
#import <Foundation/NSValue.h>
#import <NGCards/NGVCard.h>
#import <NGObjWeb/WOContext.h>
#import <NGObjWeb/WORequest.h>
#import <NGObjWeb/WOResponse.h>
#import <NGObjWeb/SoComponent.h>
#import <NGExtensions/NSString+misc.h>
#import <Contacts/SOGoContactObject.h>
#import <Contacts/SOGoContactFolders.h>
#import <SoObjects/Mailer/SOGoMailObject.h>
#import <SoObjects/Mailer/SOGoMailAccount.h>
#import <SoObjects/Mailer/SOGoMailAccounts.h>
#import <SoObjects/SOGo/NSDictionary+URL.h>
#import <SoObjects/SOGo/NSArray+Utilities.h>
#import <SoObjects/SOGo/SOGoUser.h>
#import <SoObjects/SOGo/SOGoUserFolder.h>
#import <SOGoUI/UIxComponent.h>
#import "UIxMailMainFrame.h"
@@ -144,18 +149,84 @@
- (id <WOActionResults>) composeAction
{
NSArray *accounts;
NSString *firstAccount, *newLocation, *parameters;
id <SOGoContactObject> contact;
NSArray *accounts, *contactsId;
NSString *firstAccount, *newLocation, *parameters, *folderId, *uid, *email;
NSMutableString *fn;
NSEnumerator *uids;
NSMutableArray *addresses;
NGVCard *card;
SOGoMailAccounts *co;
NSDictionary *formValues;
SOGoContactFolders *folders;
SOGoParentFolder *folder;
WORequest *request;
parameters = nil;
co = [self clientObject];
// We use the first mail account
accounts = [[context activeUser] mailAccounts];
firstAccount = [[accounts objectsForKey: @"name"] objectAtIndex: 0];
formValues = [[context request] formValues];
parameters = ([formValues count] > 0
? [formValues asURLParameters]
: @"?mailto=");
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];
fn = [NSMutableString stringWithString: [card fn]];
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=";
newLocation = [NSString stringWithFormat: @"%@/%@/compose%@",
[co baseURLInContext: context],
firstAccount,