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>
|
|
|
|
|
|
|
|
#import <SoObjects/Mailer/SOGoMailFolder.h>
|
|
|
|
#import <SoObjects/Mailer/SOGoMailObject.h>
|
|
|
|
#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
|
|
|
static int attachmentFlagSize = 8096;
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
@implementation UIxMailListView
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
[self->qualifier release];
|
|
|
|
[self->sortedUIDs release];
|
|
|
|
[self->messages release];
|
|
|
|
[self->message release];
|
2007-06-19 20:07:21 +02:00
|
|
|
[dateFormatter release];
|
|
|
|
[userTimeZone release];
|
2006-06-15 21:34:10 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* notifications */
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (void) sleep
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
[self->qualifier release]; self->qualifier = nil;
|
|
|
|
[self->sortedUIDs release]; self->sortedUIDs = nil;
|
|
|
|
[self->messages release]; self->messages = nil;
|
|
|
|
[self->message release]; self->message = nil;
|
|
|
|
[super sleep];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* accessors */
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (void)setMessage:(id)_msg
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
ASSIGN(self->message, _msg);
|
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
|
|
|
|
- (id) message
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return self->message;
|
|
|
|
}
|
|
|
|
|
2007-06-19 20:07:21 +02:00
|
|
|
- (NSString *) messageDate
|
|
|
|
{
|
|
|
|
NSCalendarDate *messageDate;
|
|
|
|
|
|
|
|
messageDate = [[message objectForKey: @"envelope"] date];
|
|
|
|
[messageDate setTimeZone: userTimeZone];
|
|
|
|
|
|
|
|
return [dateFormatter formattedDateAndTime: messageDate];
|
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (void) setQualifier: (EOQualifier *) _msg
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
ASSIGN(self->qualifier, _msg);
|
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
|
|
|
|
- (EOQualifier *) qualifier
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return self->qualifier;
|
|
|
|
}
|
|
|
|
|
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"];
|
|
|
|
}
|
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-06-14 00:06:01 +02:00
|
|
|
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
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
/* we detect attachments by size ... */
|
|
|
|
unsigned size;
|
|
|
|
|
|
|
|
size = [[[self message] valueForKey:@"size"] intValue];
|
|
|
|
return size > attachmentFlagSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
if (keys == nil) {
|
|
|
|
keys = [[NSArray alloc] initWithObjects:
|
|
|
|
@"FLAGS", @"ENVELOPE", @"RFC822.SIZE", nil];
|
|
|
|
}
|
|
|
|
return keys;
|
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (NSString *) defaultSortKey
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return @"DATE";
|
|
|
|
}
|
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;
|
|
|
|
|
|
|
|
sort = [[[self context] request] formValueForKey:@"sort"];
|
2006-08-01 19:56:51 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
if ([sort length] == 0)
|
|
|
|
sort = [self defaultSortKey];
|
2006-08-01 19:56:51 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return [sort uppercaseString];
|
|
|
|
}
|
|
|
|
|
2006-08-01 19:56:51 +02:00
|
|
|
- (BOOL) isSortedDescending
|
2006-07-29 00:59:11 +02:00
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSString *desc;
|
2006-08-01 19:56:51 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
desc = [[[self context] request] formValueForKey:@"desc"];
|
2006-08-01 19:56:51 +02:00
|
|
|
|
|
|
|
return ((desc)
|
|
|
|
? [desc boolValue]
|
|
|
|
: YES);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (NSString *) imap4SortOrdering
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSString *sort;
|
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
|
|
|
|
|
|
|
if ([self isSortedDescending])
|
|
|
|
sort = [@"REVERSE " stringByAppendingString: sort];
|
|
|
|
|
|
|
|
return sort;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (NSRange) fetchRange
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
if (self->firstMessageNumber == 0)
|
2006-07-31 22:16:45 +02:00
|
|
|
return NSMakeRange(0, messagesPerPage);
|
|
|
|
return NSMakeRange(self->firstMessageNumber - 1, messagesPerPage);
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (NSArray *) sortedUIDs
|
|
|
|
{
|
2006-08-01 19:56:51 +02:00
|
|
|
if (!sortedUIDs)
|
|
|
|
{
|
|
|
|
sortedUIDs
|
|
|
|
= [[self clientObject] fetchUIDsMatchingQualifier: [self qualifier]
|
|
|
|
sortOrdering: [self imap4SortOrdering]];
|
|
|
|
[sortedUIDs retain];
|
|
|
|
}
|
2006-07-31 22:16:45 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return self->sortedUIDs;
|
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
|
|
|
|
- (unsigned int) totalMessageCount
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [self->sortedUIDs count];
|
|
|
|
}
|
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
|
|
|
|
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
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSArray *uids;
|
|
|
|
NSArray *msgs;
|
|
|
|
NSRange r;
|
|
|
|
unsigned len;
|
2007-06-19 20:07:21 +02:00
|
|
|
SOGoUser *user;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
if (self->messages != nil)
|
|
|
|
return self->messages;
|
2007-06-19 20:07:21 +02:00
|
|
|
|
|
|
|
user = [context activeUser];
|
|
|
|
if (!dateFormatter)
|
|
|
|
dateFormatter = [user dateFormatterInContext: context];
|
|
|
|
if (!userTimeZone)
|
|
|
|
ASSIGN (userTimeZone, [user timeZone]);
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
r = [self fetchBlock];
|
|
|
|
uids = [self sortedUIDs];
|
|
|
|
if ((len = [uids count]) > r.length)
|
|
|
|
/* only need to restrict if we have a lot */
|
|
|
|
uids = [uids subarrayWithRange:r];
|
|
|
|
|
|
|
|
msgs = [[self clientObject] fetchUIDs:uids parts:[self fetchKeys]];
|
|
|
|
self->messages = [[msgs valueForKey:@"fetch"] retain];
|
|
|
|
return self->messages;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* active message */
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (SOGoMailObject *) lookupActiveMessage
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSString *uid;
|
|
|
|
|
|
|
|
if ((uid = [[[self context] request] formValueForKey:@"uid"]) == nil)
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
return [[self clientObject] lookupName:uid inContext:[self context]
|
|
|
|
acquire:NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* actions */
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (BOOL) isJavaScriptRequest
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [[[[self context] request] formValueForKey:@"jsonly"] boolValue];
|
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
|
|
|
|
- (id) javaScriptOK
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
WOResponse *r;
|
|
|
|
|
|
|
|
r = [[self context] response];
|
|
|
|
[r setStatus:200 /* OK */];
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (id) defaultAction
|
|
|
|
{
|
2006-07-31 22:16:45 +02:00
|
|
|
WORequest *request;
|
2006-08-01 19:56:51 +02:00
|
|
|
NSString *specificMessage;
|
2006-07-31 22:16:45 +02:00
|
|
|
|
|
|
|
request = [[self context] request];
|
2007-01-30 19:18:16 +01:00
|
|
|
|
|
|
|
[[self clientObject] flushMailCaches];
|
|
|
|
|
2006-07-31 22:16:45 +02:00
|
|
|
specificMessage = [request formValueForKey: @"pageforuid"];
|
|
|
|
self->firstMessageNumber
|
|
|
|
= ((specificMessage)
|
|
|
|
? [self firstMessageOfPageFor: [specificMessage intValue]]
|
|
|
|
: [[request formValueForKey:@"idx"] intValue]);
|
2006-07-29 00:59:11 +02:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) viewAction
|
|
|
|
{
|
|
|
|
return [self defaultAction];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) markMessageUnreadAction
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSException *error;
|
|
|
|
|
|
|
|
if ((error = [[self lookupActiveMessage] removeFlags:@"seen"]) != nil)
|
|
|
|
// TODO: improve error handling
|
|
|
|
return error;
|
|
|
|
|
|
|
|
if ([self isJavaScriptRequest])
|
|
|
|
return [self javaScriptOK];
|
|
|
|
|
|
|
|
return [self redirectToLocation:@"view"];
|
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
|
|
|
|
- (id) markMessageReadAction
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSException *error;
|
|
|
|
|
|
|
|
if ((error = [[self lookupActiveMessage] addFlags:@"seen"]) != nil)
|
|
|
|
// TODO: improve error handling
|
|
|
|
return error;
|
|
|
|
|
|
|
|
if ([self isJavaScriptRequest])
|
|
|
|
return [self javaScriptOK];
|
|
|
|
|
|
|
|
return [self redirectToLocation:@"view"];
|
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (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"];
|
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (id) expungeAction
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
// TODO: we might want to flush the caches?
|
|
|
|
NSException *error;
|
|
|
|
id client;
|
|
|
|
|
|
|
|
if ((client = [self clientObject]) == nil) {
|
|
|
|
return [NSException exceptionWithHTTPStatus:404 /* Not Found */
|
|
|
|
reason:@"did not find mail folder"];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((error = [[self clientObject] expunge]) != nil)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
if ([client respondsToSelector:@selector(flushMailCaches)])
|
|
|
|
[client flushMailCaches];
|
|
|
|
return [self redirectToLocation:@"view"];
|
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
@end
|
|
|
|
|
|
|
|
/* UIxMailListView */
|