From 08750cad47dd948b5a62ac82e7467371906c9bae Mon Sep 17 00:00:00 2001 From: helge Date: Wed, 6 Jul 2005 22:28:50 +0000 Subject: [PATCH] implemented trashing git-svn-id: http://svn.opengroupware.org/SOGo/trunk@679 d1b88da0-ebda-0310-925b-ed51d893ca5b --- SOGo/SoObjects/Mailer/ChangeLog | 4 +++ SOGo/SoObjects/Mailer/SOGoMailObject.h | 5 +++ SOGo/SoObjects/Mailer/SOGoMailObject.m | 34 ++++++++++++++++-- SOGo/SoObjects/Mailer/Version | 2 +- SOGo/UI/MailerUI/ChangeLog | 5 +++ SOGo/UI/MailerUI/UIxMailView.m | 50 +++++++++++++++++++++++--- SOGo/UI/MailerUI/Version | 2 +- SOGo/UI/MailerUI/product.plist | 13 +++++-- 8 files changed, 103 insertions(+), 12 deletions(-) diff --git a/SOGo/SoObjects/Mailer/ChangeLog b/SOGo/SoObjects/Mailer/ChangeLog index d3112e21..76ea86f1 100644 --- a/SOGo/SoObjects/Mailer/ChangeLog +++ b/SOGo/SoObjects/Mailer/ChangeLog @@ -1,3 +1,7 @@ +2005-07-07 Helge Hess + + * SOGoMailObject.m: implemented -trashInContext: method (v0.9.88) + 2005-07-06 Helge Hess * SOGoMailObject.m: prefetch pgp-signature parts (v0.9.87) diff --git a/SOGo/SoObjects/Mailer/SOGoMailObject.h b/SOGo/SoObjects/Mailer/SOGoMailObject.h index 3b5a0549..fc888cc1 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailObject.h +++ b/SOGo/SoObjects/Mailer/SOGoMailObject.h @@ -80,6 +80,11 @@ - (NSException *)addFlags:(id)_f; - (NSException *)removeFlags:(id)_f; +/* deletion */ + +- (BOOL)isDeletionAllowed; +- (NSException *)trashInContext:(id)_ctx; + @end #endif /* __Mailer_SOGoMailObject_H__ */ diff --git a/SOGo/SoObjects/Mailer/SOGoMailObject.m b/SOGo/SoObjects/Mailer/SOGoMailObject.m index be2ad752..44ee5592 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailObject.m +++ b/SOGo/SoObjects/Mailer/SOGoMailObject.m @@ -587,7 +587,8 @@ static BOOL debugBodyStructure = NO; Also: we cannot really take a target resource, the ID will be assigned by the IMAP4 server. - TODO: return a 'location' header instead? + We even cannot return a 'location' header instead because IMAP4 + doesn't tell us the new ID. */ NSURL *destImap4URL; @@ -622,7 +623,16 @@ static BOOL debugBodyStructure = NO; /* operations */ -- (NSException *)trashAction:(id)_ctx { +- (NSException *)trashInContext:(id)_ctx { + /* + Trashing is three actions: + a) copy to trash folder + b) mark mail as deleted + c) expunge folder + + In case b) or c) fails, we can't do anything because IMAP4 doesn't tell us + the ID used in the trash folder. + */ SOGoMailFolder *trashFolder; NSException *error; @@ -635,10 +645,28 @@ static BOOL debugBodyStructure = NO; return [NSException exceptionWithHTTPStatus:500 /* Server Error */ reason:@"Did not find Trash folder!"]; } + [trashFolder flushMailCaches]; + + /* a) copy */ + + error = [self davCopyToTargetObject:trashFolder + newName:@"fakeNewUnusedByIMAP4" /* autoassigned */ + inContext:_ctx]; + if (error != nil) return error; + + /* b) mark deleted */ - error = [self davCopyToTargetObject:trashFolder newName:nil inContext:_ctx]; + error = [[self mailManager] markURLDeleted:[self imap4URL] + password:[self imap4Password]]; if (error != nil) return error; + + /* c) expunge */ + error = [[self mailManager] expungeAtURL:[[self container] imap4URL] + password:[self imap4Password]]; + if (error != nil) return error; // TODO: unflag as deleted? + [self flushMailCaches]; + return nil; } diff --git a/SOGo/SoObjects/Mailer/Version b/SOGo/SoObjects/Mailer/Version index cb57afef..9bc59574 100644 --- a/SOGo/SoObjects/Mailer/Version +++ b/SOGo/SoObjects/Mailer/Version @@ -1,6 +1,6 @@ # Version file -SUBMINOR_VERSION:=87 +SUBMINOR_VERSION:=88 # v0.9.69 requires libNGMime v4.5.210 # v0.9.55 requires libNGExtensions v4.5.136 diff --git a/SOGo/UI/MailerUI/ChangeLog b/SOGo/UI/MailerUI/ChangeLog index c83076fe..9fb669f6 100644 --- a/SOGo/UI/MailerUI/ChangeLog +++ b/SOGo/UI/MailerUI/ChangeLog @@ -1,3 +1,8 @@ +2005-07-07 Helge Hess + + * UIxMailView.m, product.plist: added -trash button and action + (v0.9.127) + 2005-07-06 Helge Hess * product.plist: hide expunge button on mail folder when deleting is diff --git a/SOGo/UI/MailerUI/UIxMailView.m b/SOGo/UI/MailerUI/UIxMailView.m index ffe89b11..59b40bfe 100644 --- a/SOGo/UI/MailerUI/UIxMailView.m +++ b/SOGo/UI/MailerUI/UIxMailView.m @@ -72,6 +72,23 @@ return s; } +/* expunge / delete setup and permissions */ + +- (BOOL)showMarkDeletedButton { + if (![[self clientObject] isDeletionAllowed]) + return NO; + + return NO; // TODO: make configurable in profile +} + +- (BOOL)showTrashButton { + if (![[self clientObject] isDeletionAllowed]) + return NO; + // TODO: should also check for Trash write access (or add -isTrashingAllowed) + + return YES; // TODO: make configurable in profile +} + /* links (DUP to UIxMailPartViewer!) */ - (NSString *)linkToEnvelopeAddress:(NGImap4EnvelopeAddress *)_address { @@ -130,7 +147,7 @@ - (id)deleteAction { NSException *ex; - + if (![self isDeletableClientObject]) { return [NSException exceptionWithHTTPStatus:400 /* Bad Request */ reason:@"method cannot be invoked on " @@ -143,11 +160,8 @@ } if ((ex = [[self clientObject] delete]) != nil) { - // TODO: improve error handling id url; - [self debugWithFormat:@"failed to delete: %@", ex]; - url = [[ex reason] stringByEscapingURL]; url = [@"view?error=" stringByAppendingString:url]; return [self redirectToLocation:url]; @@ -166,6 +180,34 @@ return [self redirectToParentFolder]; } +- (id)trashAction { + NSException *ex; + + if ([self isInvokedBySafeMethod]) { + // TODO: fix UI to use POST for unsafe actions + [self logWithFormat:@"WARNING: method is invoked using safe HTTP method!"]; + } + + if ((ex = [[self clientObject] trashInContext:[self context]]) != nil) { + id url; + + url = [[ex reason] stringByEscapingURL]; + url = [@"view?error=" stringByAppendingString:url]; + return [self redirectToLocation:url]; + } + + if (![self isInlineViewer]) { + // if everything is ok, close the window (send a JS closing the Window) + id page; + + page = [self pageWithName:@"UIxMailWindowCloser"]; + [page takeValue:@"YES" forKey:@"refreshOpener"]; + return page; + } + + return [self redirectToParentFolder]; +} + - (id)getMailAction { // TODO: we might want to flush the caches? return [self redirectToLocation:@"view"]; diff --git a/SOGo/UI/MailerUI/Version b/SOGo/UI/MailerUI/Version index ed1862db..179f28d6 100644 --- a/SOGo/UI/MailerUI/Version +++ b/SOGo/UI/MailerUI/Version @@ -1,6 +1,6 @@ # version file -SUBMINOR_VERSION:=126 +SUBMINOR_VERSION:=127 # v0.9.100 requires libNGMime v4.5.213 # v0.9.99 requires libNGMime v4.5.212 diff --git a/SOGo/UI/MailerUI/product.plist b/SOGo/UI/MailerUI/product.plist index e4f0b930..d8ed9bf7 100644 --- a/SOGo/UI/MailerUI/product.plist +++ b/SOGo/UI/MailerUI/product.plist @@ -217,9 +217,11 @@ cssClass = "tbicon_forward"; label = "Forward"; }, ), ( // third group - { link = "delete"; - isSafe = NO; - enabled = clientObject.isDeletionAllowed; + { link = "delete"; isSafe = NO; + enabled = showMarkDeletedButton; + cssClass = "tbicon_delete"; label = "Delete"; }, + { link = "trash"; isSafe = NO; + enabled = showTrashButton; cssClass = "tbicon_delete"; label = "Delete"; }, /* TODO: enable when we know how to mark junk (#971) { link = "#"; @@ -257,6 +259,11 @@ pageName = "UIxMailView"; actionName = "delete"; }; + trash = { + protectedBy = "View"; + pageName = "UIxMailView"; + actionName = "trash"; + }; junk = { protectedBy = "View"; pageName = "UIxMailView"; -- 2.39.2