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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
UIxMailListView
|
|
|
|
|
|
|
|
This component represent a list of mails and is attached to an SOGoMailFolder
|
|
|
|
object.
|
|
|
|
*/
|
|
|
|
|
2007-06-19 20:07:21 +02:00
|
|
|
#import <Foundation/NSCalendarDate.h>
|
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <Foundation/NSValue.h>
|
|
|
|
#import <NGObjWeb/WOResponse.h>
|
|
|
|
#import <NGObjWeb/WORequest.h>
|
|
|
|
#import <NGObjWeb/SoObject+SoDAV.h>
|
|
|
|
#import <NGObjWeb/NSException+HTTP.h>
|
|
|
|
#import <NGExtensions/NSNull+misc.h>
|
|
|
|
#import <NGExtensions/NSString+misc.h>
|
|
|
|
|
2007-06-27 23:26:44 +02:00
|
|
|
#import <EOControl/EOQualifier.h>
|
|
|
|
|
2007-06-19 20:07:21 +02:00
|
|
|
#import <SoObjects/Mailer/SOGoMailFolder.h>
|
|
|
|
#import <SoObjects/Mailer/SOGoMailObject.h>
|
2007-10-29 21:46:59 +01:00
|
|
|
#import <SoObjects/SOGo/NSArray+Utilities.h>
|
2007-06-19 20:07:21 +02:00
|
|
|
#import <SoObjects/SOGo/SOGoDateFormatter.h>
|
|
|
|
#import <SoObjects/SOGo/SOGoUser.h>
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
#import "UIxMailListView.h"
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-06-19 20:07:21 +02:00
|
|
|
#define messagesPerPage 50
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
@implementation UIxMailListView
|
|
|
|
|
2007-06-27 23:26:44 +02:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
SOGoUser *user;
|
|
|
|
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
qualifier = nil;
|
|
|
|
user = [context activeUser];
|
|
|
|
ASSIGN (dateFormatter, [user dateFormatterInContext: context]);
|
|
|
|
ASSIGN (userTimeZone, [user timeZone]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
2007-06-27 23:26:44 +02:00
|
|
|
[qualifier release];
|
|
|
|
[sortedUIDs release];
|
|
|
|
[messages release];
|
|
|
|
[message release];
|
2007-06-19 20:07:21 +02:00
|
|
|
[dateFormatter release];
|
|
|
|
[userTimeZone release];
|
2006-06-15 21:34:10 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* accessors */
|
|
|
|
|
2007-06-27 23:26:44 +02:00
|
|
|
- (void) setMessage: (id) _msg
|
2006-07-29 00:59:11 +02:00
|
|
|
{
|
2007-10-29 21:46:59 +01:00
|
|
|
ASSIGN (message, _msg);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
|
|
|
|
- (id) message
|
|
|
|
{
|
2007-06-27 23:26:44 +02:00
|
|
|
return message;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-06-19 20:07:21 +02:00
|
|
|
- (NSString *) messageDate
|
|
|
|
{
|
|
|
|
NSCalendarDate *messageDate;
|
|
|
|
|
2007-07-13 15:45:37 +02:00
|
|
|
messageDate = [[message valueForKey: @"envelope"] date];
|
2007-06-19 20:07:21 +02:00
|
|
|
[messageDate setTimeZone: userTimeZone];
|
|
|
|
|
|
|
|
return [dateFormatter formattedDateAndTime: messageDate];
|
|
|
|
}
|
|
|
|
|
2007-09-17 19:24:22 +02:00
|
|
|
- (NSString *) messageSubject
|
|
|
|
{
|
2007-11-05 17:37:17 +01:00
|
|
|
id baseSubject;
|
2007-09-17 19:24:22 +02:00
|
|
|
NSString *subject;
|
|
|
|
|
2007-11-05 17:37:17 +01:00
|
|
|
baseSubject = [[message valueForKey: @"envelope"] subject];
|
|
|
|
subject = [baseSubject decodedSubject];
|
|
|
|
if (![subject length])
|
|
|
|
subject = [self labelForKey: @"Untitled"];
|
2007-09-17 19:24:22 +02:00
|
|
|
|
|
|
|
return subject;
|
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (BOOL) showToAddress
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSString *ftype;
|
|
|
|
|
|
|
|
ftype = [[self clientObject] valueForKey:@"outlookFolderClass"];
|
|
|
|
return [ftype isEqual:@"IPF.Sent"];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* title */
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (NSString *) objectTitle
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [[self clientObject] nameInContainer];
|
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
|
|
|
|
- (NSString *) panelTitle
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSString *s;
|
|
|
|
|
|
|
|
s = [self labelForKey:@"View Mail Folder"];
|
|
|
|
s = [s stringByAppendingString:@": "];
|
|
|
|
s = [s stringByAppendingString:[self objectTitle]];
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* derived accessors */
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (BOOL) isMessageDeleted
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSArray *flags;
|
|
|
|
|
|
|
|
flags = [[self message] valueForKey:@"flags"];
|
|
|
|
return [flags containsObject:@"deleted"];
|
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (BOOL) isMessageRead
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSArray *flags;
|
|
|
|
|
|
|
|
flags = [[self message] valueForKey:@"flags"];
|
|
|
|
return [flags containsObject:@"seen"];
|
|
|
|
}
|
2007-09-10 22:58:57 +02:00
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (NSString *) messageUidString
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [[[self message] valueForKey:@"uid"] stringValue];
|
|
|
|
}
|
|
|
|
|
2007-06-14 00:06:01 +02:00
|
|
|
- (NSString *) messageRowStyleClass
|
2006-07-29 00:59:11 +02:00
|
|
|
{
|
|
|
|
return [self isMessageDeleted]
|
|
|
|
? @"mailer_listcell_deleted"
|
|
|
|
: @"mailer_listcell_regular";
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) messageSubjectCellStyleClass
|
|
|
|
{
|
2007-10-25 22:07:56 +02:00
|
|
|
NSArray *flags;
|
|
|
|
NSString *cellClass;
|
|
|
|
|
|
|
|
flags = [[self message] valueForKey:@"flags"];
|
|
|
|
|
|
|
|
if ([flags containsObject: @"seen"])
|
|
|
|
{
|
|
|
|
if ([flags containsObject: @"answered"])
|
|
|
|
{
|
|
|
|
if ([flags containsObject: @"$forwarded"])
|
|
|
|
cellClass = @"mailer_forwardedrepliedmailsubject";
|
|
|
|
else
|
|
|
|
cellClass = @"mailer_repliedmailsubject";
|
|
|
|
}
|
|
|
|
else if ([flags containsObject: @"$forwarded"])
|
|
|
|
cellClass = @"mailer_forwardedmailsubject";
|
|
|
|
else
|
|
|
|
cellClass = @"mailer_readmailsubject";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cellClass = @"mailer_unreadmailsubject";
|
|
|
|
|
|
|
|
return cellClass;
|
|
|
|
// return ([self isMessageRead]
|
|
|
|
// ? @"mailer_readmailsubject"
|
|
|
|
// : @"mailer_unreadmailsubject");
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2006-07-12 00:29:19 +02:00
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (BOOL) hasMessageAttachment
|
|
|
|
{
|
2007-10-29 21:46:59 +01:00
|
|
|
NSArray *parts;
|
|
|
|
NSEnumerator *dispositions;
|
|
|
|
NSDictionary *currentDisp;
|
|
|
|
BOOL hasAttachment;
|
|
|
|
|
2007-11-01 18:09:58 +01:00
|
|
|
hasAttachment = NO;
|
|
|
|
|
2007-10-29 21:46:59 +01:00
|
|
|
parts = [[message objectForKey: @"body"] objectForKey: @"parts"];
|
|
|
|
if ([parts count] > 1)
|
|
|
|
{
|
|
|
|
dispositions
|
|
|
|
= [[parts objectsForKey: @"disposition"] objectEnumerator];
|
|
|
|
while (!hasAttachment
|
|
|
|
&& (currentDisp = [dispositions nextObject]))
|
|
|
|
hasAttachment = ([[currentDisp objectForKey: @"type"]
|
|
|
|
isEqualToString: @"ATTACHMENT"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hasAttachment;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* fetching messages */
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (NSArray *) fetchKeys
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
/* Note: see SOGoMailManager.m for allowed IMAP4 keys */
|
|
|
|
static NSArray *keys = nil;
|
2007-10-29 21:46:59 +01:00
|
|
|
|
|
|
|
if (!keys)
|
2007-06-28 20:28:33 +02:00
|
|
|
keys = [[NSArray alloc] initWithObjects: @"UID",
|
2007-10-29 21:46:59 +01:00
|
|
|
@"FLAGS", @"ENVELOPE", @"RFC822.SIZE",
|
|
|
|
@"BODYSTRUCTURE", nil];
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return keys;
|
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (NSString *) defaultSortKey
|
|
|
|
{
|
2007-06-28 20:28:33 +02:00
|
|
|
return @"ARRIVAL";
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2006-07-31 22:16:45 +02:00
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (NSString *) imap4SortKey
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSString *sort;
|
|
|
|
|
2007-06-28 20:28:33 +02:00
|
|
|
sort = [[context request] formValueForKey: @"sort"];
|
2006-08-01 19:56:51 +02:00
|
|
|
|
2007-06-28 20:28:33 +02:00
|
|
|
if (![sort length])
|
2006-06-15 21:34:10 +02:00
|
|
|
sort = [self defaultSortKey];
|
2006-08-01 19:56:51 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return [sort uppercaseString];
|
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (NSString *) imap4SortOrdering
|
|
|
|
{
|
2007-06-28 20:28:33 +02:00
|
|
|
NSString *sort, *ascending;
|
2006-08-01 19:56:51 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
sort = [self imap4SortKey];
|
2006-08-01 19:56:51 +02:00
|
|
|
|
2007-06-28 20:28:33 +02:00
|
|
|
ascending = [[context request] formValueForKey: @"asc"];
|
|
|
|
if (![ascending boolValue])
|
2006-08-01 19:56:51 +02:00
|
|
|
sort = [@"REVERSE " stringByAppendingString: sort];
|
|
|
|
|
|
|
|
return sort;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (NSRange) fetchRange
|
|
|
|
{
|
2007-06-27 23:26:44 +02:00
|
|
|
if (firstMessageNumber == 0)
|
2006-07-31 22:16:45 +02:00
|
|
|
return NSMakeRange(0, messagesPerPage);
|
2007-06-27 23:26:44 +02:00
|
|
|
return NSMakeRange(firstMessageNumber - 1, messagesPerPage);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (NSArray *) sortedUIDs
|
|
|
|
{
|
2007-09-11 17:07:30 +02:00
|
|
|
EOQualifier *fetchQualifier, *notDeleted;
|
2007-10-29 19:58:14 +01:00
|
|
|
|
2006-08-01 19:56:51 +02:00
|
|
|
if (!sortedUIDs)
|
|
|
|
{
|
2007-09-11 17:07:30 +02:00
|
|
|
notDeleted = [EOQualifier qualifierWithQualifierFormat:
|
|
|
|
@"(not (flags = %@))",
|
|
|
|
@"deleted"];
|
|
|
|
if (qualifier)
|
|
|
|
{
|
|
|
|
fetchQualifier = [[EOAndQualifier alloc] initWithQualifiers:
|
|
|
|
notDeleted, qualifier,
|
|
|
|
nil];
|
|
|
|
[fetchQualifier autorelease];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
fetchQualifier = notDeleted;
|
|
|
|
|
2007-06-28 20:28:33 +02:00
|
|
|
sortedUIDs
|
2007-09-11 17:07:30 +02:00
|
|
|
= [[self clientObject] fetchUIDsMatchingQualifier: fetchQualifier
|
2007-06-28 20:28:33 +02:00
|
|
|
sortOrdering: [self imap4SortOrdering]];
|
2006-08-01 19:56:51 +02:00
|
|
|
[sortedUIDs retain];
|
|
|
|
}
|
2006-07-31 22:16:45 +02:00
|
|
|
|
2007-06-27 23:26:44 +02:00
|
|
|
return sortedUIDs;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
|
|
|
|
- (unsigned int) totalMessageCount
|
|
|
|
{
|
2007-06-27 23:26:44 +02:00
|
|
|
return [sortedUIDs count];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
|
|
|
|
- (BOOL) showsAllMessages
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return ([[self sortedUIDs] count] <= [self fetchRange].length) ? YES : NO;
|
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (NSRange) fetchBlock
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSRange r;
|
|
|
|
unsigned len;
|
|
|
|
NSArray *uids;
|
|
|
|
|
|
|
|
r = [self fetchRange];
|
|
|
|
uids = [self sortedUIDs];
|
|
|
|
|
|
|
|
/* only need to restrict if we have a lot */
|
|
|
|
if ((len = [uids count]) <= r.length) {
|
|
|
|
r.location = 0;
|
|
|
|
r.length = len;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len < r.location) {
|
|
|
|
// TODO: CHECK CONDITION (< vs <=)
|
|
|
|
/* out of range, recover at first block */
|
|
|
|
r.location = 0;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r.location + r.length > len)
|
|
|
|
r.length = len - r.location;
|
|
|
|
return r;
|
|
|
|
}
|
2006-07-31 22:16:45 +02:00
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (unsigned int) firstMessageNumber
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [self fetchBlock].location + 1;
|
|
|
|
}
|
2006-07-31 22:16:45 +02:00
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (unsigned int) lastMessageNumber
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSRange r;
|
|
|
|
|
|
|
|
r = [self fetchBlock];
|
|
|
|
return r.location + r.length;
|
|
|
|
}
|
2006-07-31 22:16:45 +02:00
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (BOOL) hasPrevious
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [self fetchBlock].location == 0 ? NO : YES;
|
|
|
|
}
|
2006-07-31 22:16:45 +02:00
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (BOOL) hasNext
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSRange r = [self fetchBlock];
|
|
|
|
return r.location + r.length >= [[self sortedUIDs] count] ? NO : YES;
|
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (unsigned int) nextFirstMessageNumber
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [self firstMessageNumber] + [self fetchRange].length;
|
|
|
|
}
|
2006-07-31 22:16:45 +02:00
|
|
|
|
2007-10-29 19:58:14 +01:00
|
|
|
- (unsigned int) lastFirstMessageNumber
|
|
|
|
{
|
|
|
|
unsigned int max, modulo;
|
|
|
|
|
|
|
|
if (!sortedUIDs)
|
|
|
|
[self sortedUIDs];
|
|
|
|
|
|
|
|
max = [sortedUIDs count];
|
|
|
|
modulo = (max % messagesPerPage);
|
|
|
|
if (modulo == 0)
|
|
|
|
modulo = messagesPerPage;
|
|
|
|
|
|
|
|
return (max + 1 - modulo);
|
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (unsigned int) prevFirstMessageNumber
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSRange r;
|
|
|
|
unsigned idx;
|
|
|
|
|
|
|
|
idx = [self firstMessageNumber];
|
|
|
|
r = [self fetchRange];
|
|
|
|
if (idx > r.length)
|
|
|
|
return (idx - r.length);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (NSArray *) messages
|
|
|
|
{
|
2007-10-29 21:46:59 +01:00
|
|
|
NSArray *uids;
|
|
|
|
NSDictionary *msgs;
|
|
|
|
NSRange r;
|
2006-06-15 21:34:10 +02:00
|
|
|
unsigned len;
|
|
|
|
|
2007-10-29 21:46:59 +01:00
|
|
|
if (!messages)
|
|
|
|
{
|
|
|
|
r = [self fetchBlock];
|
|
|
|
uids = [self sortedUIDs];
|
|
|
|
len = [uids count];
|
|
|
|
if (len > r.length)
|
|
|
|
/* only need to restrict if we have a lot */
|
|
|
|
uids = [uids subarrayWithRange: r];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-10-29 21:46:59 +01:00
|
|
|
msgs = [[self clientObject] fetchUIDs: uids parts: [self fetchKeys]];
|
|
|
|
messages = [[msgs objectForKey: @"fetch"] retain];
|
|
|
|
}
|
2007-06-27 23:26:44 +02:00
|
|
|
|
|
|
|
return messages;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* URL processing */
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (NSString *) messageViewTarget
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat: @"SOGo_msg_%@",
|
|
|
|
[self messageUidString]];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
|
|
|
|
- (NSString *) messageViewURL
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
// TODO: noframe only when view-target is empty
|
|
|
|
// TODO: markread only if the message is unread
|
|
|
|
NSString *s;
|
|
|
|
|
|
|
|
s = [[self messageUidString] stringByAppendingString:@"/view?noframe=1"];
|
|
|
|
if (![self isMessageRead]) s = [s stringByAppendingString:@"&markread=1"];
|
|
|
|
return s;
|
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
- (NSString *) markReadURL
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [@"markMessageRead?uid=" stringByAppendingString:
|
|
|
|
[self messageUidString]];
|
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
- (NSString *) markUnreadURL
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [@"markMessageUnread?uid=" stringByAppendingString:
|
|
|
|
[self messageUidString]];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* JavaScript */
|
|
|
|
|
2006-07-12 00:29:19 +02:00
|
|
|
- (NSString *)msgRowID
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [@"row_" stringByAppendingString:[self messageUidString]];
|
|
|
|
}
|
2006-07-12 00:29:19 +02:00
|
|
|
|
|
|
|
- (NSString *)msgDivID
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [@"div_" stringByAppendingString:[self messageUidString]];
|
|
|
|
}
|
|
|
|
|
2006-07-12 00:29:19 +02:00
|
|
|
- (NSString *)msgIconReadImgID
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [@"readdiv_" stringByAppendingString:[self messageUidString]];
|
|
|
|
}
|
2006-07-12 00:29:19 +02:00
|
|
|
|
|
|
|
- (NSString *)msgIconUnreadImgID
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [@"unreaddiv_" stringByAppendingString:[self messageUidString]];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* error redirects */
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (id) redirectToViewWithError: (id) _error
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
// TODO: DUP in UIxMailAccountView
|
|
|
|
// TODO: improve, localize
|
|
|
|
// TODO: there is a bug in the treeview which preserves the current URL for
|
|
|
|
// the active object (displaying the error again)
|
|
|
|
id url;
|
|
|
|
|
|
|
|
if (![_error isNotNull])
|
|
|
|
return [self redirectToLocation:@"view"];
|
|
|
|
|
|
|
|
if ([_error isKindOfClass:[NSException class]])
|
|
|
|
_error = [_error reason];
|
|
|
|
else if ([_error isKindOfClass:[NSString class]])
|
|
|
|
_error = [_error stringValue];
|
|
|
|
|
|
|
|
url = [_error stringByEscapingURL];
|
|
|
|
url = [@"view?error=" stringByAppendingString:url];
|
|
|
|
return [self redirectToLocation:url];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* actions */
|
|
|
|
|
2006-07-31 22:16:45 +02:00
|
|
|
- (int) firstMessageOfPageFor: (int) messageNbr
|
|
|
|
{
|
|
|
|
NSArray *messageNbrs;
|
|
|
|
int nbrInArray;
|
|
|
|
int firstMessage;
|
|
|
|
|
|
|
|
messageNbrs = [self sortedUIDs];
|
|
|
|
nbrInArray
|
|
|
|
= [messageNbrs indexOfObject: [NSNumber numberWithInt: messageNbr]];
|
|
|
|
if (nbrInArray > -1)
|
|
|
|
firstMessage = ((int) (nbrInArray / messagesPerPage)
|
|
|
|
* messagesPerPage) + 1;
|
|
|
|
else
|
|
|
|
firstMessage = 1;
|
|
|
|
|
|
|
|
return firstMessage;
|
|
|
|
}
|
|
|
|
|
2007-06-27 23:26:44 +02:00
|
|
|
- (void) _setQualifierForCriteria: (NSString *) criteria
|
|
|
|
andValue: (NSString *) value
|
|
|
|
{
|
|
|
|
[qualifier release];
|
|
|
|
|
|
|
|
if ([criteria isEqualToString: @"subject"])
|
|
|
|
qualifier = [EOQualifier qualifierWithQualifierFormat:
|
2007-09-11 17:07:30 +02:00
|
|
|
@"(subject doesContain: %@)", value];
|
2007-06-27 23:26:44 +02:00
|
|
|
else if ([criteria isEqualToString: @"sender"])
|
|
|
|
qualifier = [EOQualifier qualifierWithQualifierFormat:
|
2007-09-13 20:22:23 +02:00
|
|
|
@"(from doesContain: %@)", value];
|
2007-06-27 23:26:44 +02:00
|
|
|
else if ([criteria isEqualToString: @"subject_or_sender"])
|
|
|
|
qualifier = [EOQualifier qualifierWithQualifierFormat:
|
2007-09-13 20:22:23 +02:00
|
|
|
@"((subject doesContain: %@)"
|
2007-09-10 22:58:57 +02:00
|
|
|
@" OR (from doesContain: %@))",
|
2007-06-27 23:26:44 +02:00
|
|
|
value, value];
|
|
|
|
else if ([criteria isEqualToString: @"to_or_cc"])
|
|
|
|
qualifier = [EOQualifier qualifierWithQualifierFormat:
|
2007-09-10 22:58:57 +02:00
|
|
|
@"((to doesContain: %@)"
|
|
|
|
@" OR (cc doesContain: %@))",
|
2007-06-27 23:26:44 +02:00
|
|
|
value, value];
|
|
|
|
else if ([criteria isEqualToString: @"entire_message"])
|
|
|
|
qualifier = [EOQualifier qualifierWithQualifierFormat:
|
2007-09-10 22:58:57 +02:00
|
|
|
@"(body doesContain: %@)", value];
|
2007-06-27 23:26:44 +02:00
|
|
|
else
|
|
|
|
qualifier = nil;
|
|
|
|
|
|
|
|
[qualifier retain];
|
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (id) defaultAction
|
|
|
|
{
|
2006-07-31 22:16:45 +02:00
|
|
|
WORequest *request;
|
2007-06-27 23:26:44 +02:00
|
|
|
NSString *specificMessage, *searchCriteria, *searchValue;
|
2007-10-26 16:26:01 +02:00
|
|
|
SOGoUserFolder *co;
|
2006-07-31 22:16:45 +02:00
|
|
|
|
2007-06-28 20:28:33 +02:00
|
|
|
request = [context request];
|
2007-01-30 19:18:16 +01:00
|
|
|
|
2007-10-26 16:26:01 +02:00
|
|
|
co = [self clientObject];
|
|
|
|
[co flushMailCaches];
|
|
|
|
[co expungeLastMarkedFolder];
|
2007-01-30 19:18:16 +01:00
|
|
|
|
2006-07-31 22:16:45 +02:00
|
|
|
specificMessage = [request formValueForKey: @"pageforuid"];
|
2007-06-27 23:26:44 +02:00
|
|
|
searchCriteria = [request formValueForKey: @"search"];
|
|
|
|
searchValue = [request formValueForKey: @"value"];
|
2007-09-10 22:58:57 +02:00
|
|
|
if ([searchValue length])
|
2007-06-27 23:26:44 +02:00
|
|
|
[self _setQualifierForCriteria: searchCriteria
|
|
|
|
andValue: searchValue];
|
|
|
|
|
|
|
|
firstMessageNumber
|
2006-07-31 22:16:45 +02:00
|
|
|
= ((specificMessage)
|
|
|
|
? [self firstMessageOfPageFor: [specificMessage intValue]]
|
|
|
|
: [[request formValueForKey:@"idx"] intValue]);
|
2007-10-26 16:26:01 +02:00
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) getMailAction
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
// TODO: we might want to flush the caches?
|
|
|
|
id client;
|
2006-07-31 22:16:45 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
if ((client = [self clientObject]) == nil) {
|
|
|
|
return [NSException exceptionWithHTTPStatus:404 /* Not Found */
|
|
|
|
reason:@"did not find mail folder"];
|
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
|
|
|
|
if (![client respondsToSelector:@selector(flushMailCaches) ])
|
|
|
|
{
|
2006-07-31 22:16:45 +02:00
|
|
|
return [NSException exceptionWithHTTPStatus: 500 /* Server Error */
|
2006-07-29 00:59:11 +02:00
|
|
|
reason:
|
|
|
|
@"invalid client object (does not support flush)"];
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
[client flushMailCaches];
|
2006-07-29 00:59:11 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return [self redirectToLocation:@"view"];
|
|
|
|
}
|
|
|
|
|
2007-10-22 23:59:20 +02:00
|
|
|
- (NSString *) msgLabels
|
|
|
|
{
|
|
|
|
NSMutableArray *labels;
|
|
|
|
NSEnumerator *flags;
|
|
|
|
NSString *currentFlag;
|
|
|
|
|
|
|
|
labels = [NSMutableArray new];
|
|
|
|
[labels autorelease];
|
|
|
|
|
|
|
|
flags = [[message objectForKey: @"flags"] objectEnumerator];
|
|
|
|
while ((currentFlag = [flags nextObject]))
|
|
|
|
if ([currentFlag hasPrefix: @"$label"])
|
|
|
|
[labels addObject: [currentFlag substringFromIndex: 1]];
|
|
|
|
|
|
|
|
return [labels componentsJoinedByString: @" "];
|
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
@end
|
|
|
|
|
|
|
|
/* UIxMailListView */
|