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/NSDictionary.h>
|
|
|
|
#import <Foundation/NSEnumerator.h>
|
|
|
|
|
2007-07-27 19:34:32 +02:00
|
|
|
#import <NGObjWeb/WORequest.h>
|
|
|
|
#import <NGExtensions/NSNull+misc.h>
|
|
|
|
#import <NGMail/NGMailAddress.h>
|
|
|
|
#import <NGMail/NGMailAddressParser.h>
|
|
|
|
|
|
|
|
#import <SOGoUI/UIxComponent.h>
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
UIxMailToSelection
|
|
|
|
|
|
|
|
Select a set of address headers for composing an email.
|
|
|
|
|
|
|
|
Bindings:
|
|
|
|
to - array of strings suitable for placement in a To: header
|
|
|
|
cc - array of strings suitable for placement in a Cc: header
|
|
|
|
bcc - array of strings suitable for placement in a Bcc: header
|
|
|
|
|
|
|
|
Sample:
|
|
|
|
<var:component className="UIxMailToSelection"
|
|
|
|
to="to"
|
|
|
|
cc="cc"
|
|
|
|
bcc="bcc"
|
|
|
|
/>
|
|
|
|
*/
|
|
|
|
|
|
|
|
@class NSArray;
|
|
|
|
|
|
|
|
@interface UIxMailToSelection : UIxComponent
|
|
|
|
{
|
|
|
|
NSArray *to;
|
|
|
|
NSArray *cc;
|
|
|
|
NSArray *bcc;
|
|
|
|
id item;
|
|
|
|
id address;
|
|
|
|
NSArray *addressList;
|
|
|
|
int currentIndex;
|
|
|
|
}
|
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
- (void) setTo: (NSArray *) _to;
|
|
|
|
- (NSArray *) to;
|
|
|
|
- (void) setCc: (NSArray *) _cc;
|
|
|
|
- (NSArray *) cc;
|
|
|
|
- (void) setBcc: (NSArray *) _bcc;
|
|
|
|
- (NSArray *) bcc;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
- (void) getAddressesFromFormValues: (NSDictionary *) _dict;
|
|
|
|
- (NSString *) getIndexFromIdentifier: (NSString *) _identifier;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation UIxMailToSelection
|
|
|
|
|
|
|
|
static NSArray *headers = nil;
|
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
+ (void) initialize
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
static BOOL didInit = NO;
|
2007-08-21 16:46:07 +02:00
|
|
|
if (!didInit)
|
|
|
|
{
|
|
|
|
didInit = YES;
|
|
|
|
headers = [[NSArray alloc] initWithObjects: @"to", @"cc", @"bcc", nil];
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
2007-12-04 23:47:41 +01:00
|
|
|
currentIndex = -1;
|
2007-08-21 16:46:07 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[to release];
|
|
|
|
[cc release];
|
|
|
|
[bcc release];
|
|
|
|
[item release];
|
|
|
|
[address release];
|
|
|
|
[addressList release];
|
2006-06-15 21:34:10 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* accessors */
|
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
- (void) setTo: (NSArray *) _to
|
2006-07-11 19:53:09 +02:00
|
|
|
{
|
2007-11-16 22:15:38 +01:00
|
|
|
ASSIGN (to, _to);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2006-07-11 19:53:09 +02:00
|
|
|
|
|
|
|
- (NSArray *) to
|
|
|
|
{
|
|
|
|
NSString *mailto;
|
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
mailto = [self queryParameterForKey: @"mailto"];
|
2006-07-11 19:53:09 +02:00
|
|
|
if ([mailto length] > 0 && ![to count])
|
2006-10-19 19:36:19 +02:00
|
|
|
{
|
|
|
|
to = [NSArray arrayWithObject: mailto];
|
|
|
|
[to retain];
|
|
|
|
}
|
2006-07-11 19:53:09 +02:00
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
return to;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
- (void) setCc: (NSArray *) _cc
|
|
|
|
{
|
2007-11-16 22:15:38 +01:00
|
|
|
ASSIGN (cc, _cc);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2006-07-11 19:53:09 +02:00
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
- (NSArray *) cc
|
|
|
|
{
|
|
|
|
return cc;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
- (void) setBcc: (NSArray *) _bcc
|
|
|
|
{
|
2007-11-16 22:15:38 +01:00
|
|
|
ASSIGN (bcc, _bcc);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-08-21 16:46:07 +02:00
|
|
|
|
|
|
|
- (NSArray *) bcc
|
|
|
|
{
|
|
|
|
return bcc;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
- (void) setAddressList: (NSArray *) _addressList
|
|
|
|
{
|
|
|
|
ASSIGN (addressList, _addressList);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-08-21 16:46:07 +02:00
|
|
|
|
|
|
|
- (NSArray *) addressList
|
|
|
|
{
|
|
|
|
return addressList;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
- (void) setAddress: (id) _address
|
|
|
|
{
|
|
|
|
ASSIGN (address, _address);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-08-21 16:46:07 +02:00
|
|
|
|
|
|
|
- (id) address
|
|
|
|
{
|
|
|
|
return address;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
- (void) setItem: (id) _item
|
|
|
|
{
|
|
|
|
ASSIGN (item, _item);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-08-21 16:46:07 +02:00
|
|
|
|
|
|
|
- (id) item
|
|
|
|
{
|
|
|
|
return item;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
- (NSArray *) addressLists
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSMutableArray *ma;
|
2008-09-11 23:59:31 +02:00
|
|
|
NSArray *tmp;
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
ma = [NSMutableArray arrayWithCapacity:3];
|
2007-11-17 00:02:21 +01:00
|
|
|
if ([to isNotNull] && [to count] > 0)
|
2007-08-21 16:46:07 +02:00
|
|
|
[ma addObject: to];
|
|
|
|
if ([cc isNotNull])
|
|
|
|
[ma addObject: cc];
|
|
|
|
if ([bcc isNotNull])
|
|
|
|
[ma addObject: bcc];
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* ensure that at least one object is available */
|
2007-08-21 16:46:07 +02:00
|
|
|
if ([ma count] == 0)
|
|
|
|
{
|
2008-09-11 23:59:31 +02:00
|
|
|
tmp = [NSArray arrayWithObject: @""];
|
2007-08-21 16:46:07 +02:00
|
|
|
ASSIGN (to, tmp);
|
2008-09-11 23:59:31 +02:00
|
|
|
[ma addObject: to];
|
2007-08-21 16:46:07 +02:00
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return ma;
|
|
|
|
}
|
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
- (NSArray *) headers
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return headers;
|
|
|
|
}
|
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
- (NSString *) currentHeader
|
|
|
|
{
|
|
|
|
if (addressList == to)
|
2006-06-15 21:34:10 +02:00
|
|
|
return @"to";
|
2007-08-21 16:46:07 +02:00
|
|
|
else if (addressList == cc)
|
2006-06-15 21:34:10 +02:00
|
|
|
return @"cc";
|
2007-08-21 16:46:07 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return @"bcc";
|
|
|
|
}
|
|
|
|
|
|
|
|
/* identifiers */
|
|
|
|
|
2007-12-05 00:24:40 +01:00
|
|
|
- (NSString *) nextId
|
|
|
|
{
|
|
|
|
currentIndex++;
|
|
|
|
|
|
|
|
return @"";
|
|
|
|
}
|
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
- (NSString *) currentRowId
|
|
|
|
{
|
2007-12-04 23:47:41 +01:00
|
|
|
[self nextId];
|
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
return [NSString stringWithFormat: @"row_%d", currentIndex];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
- (NSString *) currentPopUpId
|
|
|
|
{
|
2007-12-04 23:47:41 +01:00
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
return [NSString stringWithFormat: @"popup_%d", currentIndex];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
- (NSString *) currentAddressId
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat: @"addr_%d", currentIndex];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* handling requests */
|
|
|
|
|
2007-11-06 22:22:10 +01:00
|
|
|
- (void) _fillAddresses: (NSMutableArray *) addresses
|
|
|
|
withObject: (id) object
|
|
|
|
{
|
|
|
|
NSEnumerator *list;
|
|
|
|
NSString *currentAddress;
|
|
|
|
|
|
|
|
if ([object isKindOfClass: [NSString class]])
|
|
|
|
[addresses addObject: object];
|
|
|
|
else if ([object isKindOfClass: [NSArray class]])
|
|
|
|
{
|
|
|
|
list = [object objectEnumerator];
|
|
|
|
while ((currentAddress
|
|
|
|
= [[list nextObject] stringByTrimmingSpaces]))
|
|
|
|
if ([currentAddress length])
|
|
|
|
[addresses addObject: currentAddress];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
- (void) getAddressesFromFormValues: (NSDictionary *) _dict
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSMutableArray *rawTo, *rawCc, *rawBcc;
|
2007-11-06 22:22:10 +01:00
|
|
|
NSString *idx, *popupKey, *popupValue;
|
2006-06-15 21:34:10 +02:00
|
|
|
NSArray *keys;
|
|
|
|
unsigned i, count;
|
2007-11-06 22:22:10 +01:00
|
|
|
id addr;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
rawTo = [NSMutableArray arrayWithCapacity:4];
|
|
|
|
rawCc = [NSMutableArray arrayWithCapacity:4];
|
|
|
|
rawBcc = [NSMutableArray arrayWithCapacity:2];
|
|
|
|
|
|
|
|
keys = [_dict allKeys];
|
|
|
|
count = [keys count];
|
2007-08-21 16:46:07 +02:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
NSString *key;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
key = [keys objectAtIndex:i];
|
|
|
|
if ([key hasPrefix:@"addr_"])
|
|
|
|
{
|
2007-11-06 22:22:10 +01:00
|
|
|
addr = [_dict objectForKey:key];
|
2007-08-21 16:46:07 +02:00
|
|
|
idx = [self getIndexFromIdentifier:key];
|
|
|
|
popupKey = [NSString stringWithFormat:@"popup_%@", idx];
|
|
|
|
popupValue = [[_dict objectForKey:popupKey] lastObject];
|
|
|
|
if([popupValue isEqualToString:@"0"])
|
2007-11-06 22:22:10 +01:00
|
|
|
[self _fillAddresses: rawTo withObject: addr];
|
2007-08-21 16:46:07 +02:00
|
|
|
else if([popupValue isEqualToString:@"1"])
|
2007-11-06 22:22:10 +01:00
|
|
|
[self _fillAddresses: rawCc withObject: addr];
|
2007-08-21 16:46:07 +02:00
|
|
|
else
|
2007-11-06 22:22:10 +01:00
|
|
|
[self _fillAddresses: rawBcc withObject: addr];
|
2007-08-21 16:46:07 +02:00
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
[self setTo: rawTo];
|
|
|
|
[self setCc: rawCc];
|
|
|
|
[self setBcc: rawBcc];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
- (NSString *) getIndexFromIdentifier: (NSString *) _identifier
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSRange r;
|
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
r = [_identifier rangeOfString: @"_"];
|
|
|
|
|
|
|
|
return [_identifier substringFromIndex: NSMaxRange(r)];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
- (void) takeValuesFromRequest: (WORequest *) _rq
|
|
|
|
inContext: (WOContext *) _ctx
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
/* OK, we have a special form value processor */
|
|
|
|
NSDictionary *d;
|
|
|
|
|
|
|
|
if ((d = [_rq formValues]) == nil)
|
|
|
|
return;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
[self debugWithFormat:@"Note: will take values ..."];
|
|
|
|
NSLog(@"%s formValues: %@",
|
|
|
|
__PRETTY_FUNCTION__,
|
|
|
|
d);
|
|
|
|
#endif
|
2007-08-21 16:46:07 +02:00
|
|
|
[self getAddressesFromFormValues: d];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-08-21 16:46:07 +02:00
|
|
|
- (int) addressCount
|
|
|
|
{
|
|
|
|
return [to count] + [cc count] + [bcc count];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@end /* UIxMailToSelection */
|