From: helge Date: Wed, 27 Oct 2004 15:38:53 +0000 (+0000) Subject: drafts can fake being IMAP4 messages, mail editor got delete action X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=69d9f3c11e747f03776af482c114e851b0ce0d3d;p=scalable-opengroupware.org drafts can fake being IMAP4 messages, mail editor got delete action git-svn-id: http://svn.opengroupware.org/SOGo/trunk@431 d1b88da0-ebda-0310-925b-ed51d893ca5b --- diff --git a/SOGo/SoObjects/Mailer/ChangeLog b/SOGo/SoObjects/Mailer/ChangeLog index 50ad7438..36fb78e8 100644 --- a/SOGo/SoObjects/Mailer/ChangeLog +++ b/SOGo/SoObjects/Mailer/ChangeLog @@ -1,5 +1,11 @@ 2004-10-27 Helge Hess + * v0.9.42 + + * SOGoDraftObject.m: implements some SOGoMailObject methods + + * SOGoDraftsFolder.m: implemented some draft folder listing + * SOGoDraftObject.m: added mail send functionality (v0.9.41) * SOGoDraftObject.m: added ability to create NGMime objects from draft diff --git a/SOGo/SoObjects/Mailer/SOGoDraftObject.h b/SOGo/SoObjects/Mailer/SOGoDraftObject.h index 4ad00754..7f0393ed 100644 --- a/SOGo/SoObjects/Mailer/SOGoDraftObject.h +++ b/SOGo/SoObjects/Mailer/SOGoDraftObject.h @@ -35,12 +35,13 @@ */ @class NSString, NSArray, NSDictionary, NSData, NSException; -@class NGMimeMessage; +@class NGMimeMessage, NGImap4Envelope; @interface SOGoDraftObject : SOGoMailBaseObject { - NSString *path; - NSDictionary *info; /* stores the envelope information */ + NSString *path; + NSDictionary *info; /* stores the envelope information */ + NGImap4Envelope *envelope; } /* contents */ @@ -66,6 +67,10 @@ - (NSException *)delete; +/* fake being a SOGoMailObject */ + +- (id)fetchParts:(NSArray *)_parts; + @end #endif /* __Mailer_SOGoDraftObject_H__ */ diff --git a/SOGo/SoObjects/Mailer/SOGoDraftObject.m b/SOGo/SoObjects/Mailer/SOGoDraftObject.m index c6612328..47f7f016 100644 --- a/SOGo/SoObjects/Mailer/SOGoDraftObject.m +++ b/SOGo/SoObjects/Mailer/SOGoDraftObject.m @@ -27,6 +27,8 @@ #include #include #include +#include +#include #include #include "common.h" @@ -43,6 +45,7 @@ static BOOL debugOn = NO; } - (void)dealloc { + [self->envelope release]; [self->info release]; [self->path release]; [super dealloc]; @@ -647,6 +650,77 @@ static BOOL debugOn = NO; return [NSNumber numberWithBool:YES]; /* delete worked out ... */ } +/* fake being a SOGoMailObject */ + +- (id)fetchParts:(NSArray *)_parts { + return [NSDictionary dictionaryWithObject:self forKey:@"fetch"]; +} + +- (NSString *)uid { + return [self nameInContainer]; +} +- (NSArray *)flags { + static NSArray *seenFlags = nil; + seenFlags = [[NSArray alloc] initWithObjects:@"seen", nil]; + return seenFlags; +} +- (unsigned)size { + return 0; +} + +- (NSArray *)imap4EnvelopeAddressesForStrings:(NSArray *)_emails { + NSMutableArray *ma; + unsigned i, count; + + if (_emails == nil) + return nil; + if ((count = [_emails count]) == 0) + return [NSArray array]; + + ma = [NSMutableArray arrayWithCapacity:count]; + for (i = 0; i < count; i++) { + NGImap4EnvelopeAddress *envaddr; + + envaddr = [[NGImap4EnvelopeAddress alloc] + initWithString:[_emails objectAtIndex:i]]; + if ([envaddr isNotNull]) + [ma addObject:envaddr]; + [envaddr release]; + } + return ma; +} + +- (NGImap4Envelope *)envelope { + NSDictionary *lInfo; + NSString *tmp; + + if (self->envelope != nil) + return self->envelope; + if ((lInfo = [self fetchInfo]) == nil) + return nil; + + self->envelope = [[NGImap4Envelope alloc] init]; + + self->envelope->msgId = [[self nameInContainer] copy]; + self->envelope->subject = [[lInfo objectForKey:@"subject"] copy]; + + self->envelope->from = + [[NGImap4EnvelopeAddress alloc] initWithString:[self sender]]; + + if ([(tmp = [lInfo objectForKey:@"replyTo"]) length] > 0) { + self->envelope->replyTo = + [[NGImap4EnvelopeAddress alloc] initWithString:tmp]; + } + + self->envelope->to = [[self imap4EnvelopeAddressesForStrings: + [lInfo objectForKey:@"to"]] copy]; + self->envelope->cc = [[self imap4EnvelopeAddressesForStrings: + [lInfo objectForKey:@"cc"]] copy]; + self->envelope->bcc = [[self imap4EnvelopeAddressesForStrings: + [lInfo objectForKey:@"bcc"]] copy]; + return self->envelope; +} + /* debugging */ - (BOOL)isDebuggingEnabled { diff --git a/SOGo/SoObjects/Mailer/SOGoDraftsFolder.m b/SOGo/SoObjects/Mailer/SOGoDraftsFolder.m index 80cf46d7..f15c312a 100644 --- a/SOGo/SoObjects/Mailer/SOGoDraftsFolder.m +++ b/SOGo/SoObjects/Mailer/SOGoDraftsFolder.m @@ -120,8 +120,30 @@ static NSString *spoolFolder = nil; return allUids; } - (NSArray *)fetchUIDs:(NSArray *)_uids parts:(NSArray *)_parts { - [self logWithFormat:@"TODO: fetch uids (parts=%@): %@", _parts, _uids]; - return [NSArray array]; + /* FLAGS, ENVELOPE, RFC822.SIZE */ + NSMutableArray *drafts; + unsigned i, count; + + if (_uids == nil) + return nil; + if ((count = [_uids count]) == 0) + return [NSArray array]; + + drafts = [NSMutableArray arrayWithCapacity:count]; + for (i = 0; i < count; i++) { + SOGoDraftObject *draft; + id parts; + + draft = [self lookupName:[_uids objectAtIndex:i] inContext:nil acquire:NO]; + if (![draft isNotNull] || [draft isKindOfClass:[NSException class]]) + continue; + + parts = [draft fetchParts:_parts]; + if ([parts isNotNull]) + [drafts addObject:parts]; + } + + return drafts; } /* name lookup */ diff --git a/SOGo/SoObjects/Mailer/Version b/SOGo/SoObjects/Mailer/Version index 56ded08c..8638a8c5 100644 --- a/SOGo/SoObjects/Mailer/Version +++ b/SOGo/SoObjects/Mailer/Version @@ -1,6 +1,6 @@ # Version file -SUBMINOR_VERSION:=41 +SUBMINOR_VERSION:=42 # v0.9.51 requires NGMime v4.3.190 # v0.9.35 requires SOGoLogic v0.9.24 diff --git a/SOGo/UI/Mailer/ChangeLog b/SOGo/UI/Mailer/ChangeLog index 04c476f4..a3d0c808 100644 --- a/SOGo/UI/Mailer/ChangeLog +++ b/SOGo/UI/Mailer/ChangeLog @@ -1,6 +1,9 @@ 2004-10-27 Helge Hess - * v0.9.49 + * UIxMailEditor.m: default method returns a redirect to 'edit', added + 'delete' action and button (v0.9.51) + + * v0.9.50 * UIxMailEditor.m: send mail using draft object diff --git a/SOGo/UI/Mailer/UIxMailEditor.m b/SOGo/UI/Mailer/UIxMailEditor.m index 8ad6a2ea..6bae44aa 100644 --- a/SOGo/UI/Mailer/UIxMailEditor.m +++ b/SOGo/UI/Mailer/UIxMailEditor.m @@ -169,6 +169,10 @@ static NSArray *infoKeys = nil; reason:@"failed to store draft object on server!"]; } +- (id)defaultAction { + return [self redirectToLocation:@"edit"]; +} + - (id)editAction { [self logWithFormat:@"edit action, load content from: %@", [self clientObject]]; @@ -183,16 +187,22 @@ static NSArray *infoKeys = nil; - (id)sendAction { NSException *error; + NSString *mailPath; /* first, save form data */ if (![self _saveFormInfo]) return [self failedToSaveFormResponse]; + /* save mail to file (so that we can upload the mail to Cyrus */ + + mailPath = [[self clientObject] saveMimeMessageToTemporaryFile]; + /* then, send mail */ - if ((error = [[self clientObject] sendMail]) != nil) { + if ((error = [[self clientObject] sendMimeMessageAtPath:mailPath]) != nil) { // TODO: improve error handling + [[NSFileManager defaultManager] removeFileAtPath:mailPath handler:nil]; return error; } @@ -202,7 +212,11 @@ static NSArray *infoKeys = nil; /* finally store in Sent */ - [self logWithFormat:@"TODO: store mail in Sent folder ..."]; + [self logWithFormat:@"TODO: store mail in Sent folder: %@", mailPath]; +#if 0 + [[NSFileManager defaultManager] removeFileAtPath:mailPath handler:nil]; +#endif + mailPath = nil; /* delete draft */ @@ -213,4 +227,13 @@ static NSArray *infoKeys = nil; return self; } +- (id)deleteAction { + NSException *error; + + if ((error = [[self clientObject] delete]) != nil) + return error; + + return nil; +} + @end /* UIxMailEditor */ diff --git a/SOGo/UI/Mailer/mailer.js b/SOGo/UI/Mailer/mailer.js index c88ffa33..8c6f1166 100644 --- a/SOGo/UI/Mailer/mailer.js +++ b/SOGo/UI/Mailer/mailer.js @@ -87,6 +87,13 @@ function clickedEditorSave(sender) { return true; } +function clickedEditorDelete(sender) { + document.pageform.action="delete"; + document.pageform.submit(); + window.close(); + return true; +} + /* addressbook helpers */ function openAnais(sender) { diff --git a/SOGo/UI/Mailer/product.plist b/SOGo/UI/Mailer/product.plist index a9f84089..c4d605f0 100644 --- a/SOGo/UI/Mailer/product.plist +++ b/SOGo/UI/Mailer/product.plist @@ -328,6 +328,9 @@ { link = "#"; onclick = "clickedEditorSave(this);return false;"; cssClass = "tbicon_save"; label = "Save"; }, + { link = "#"; + onclick = "clickedEditorDelete(this);return false;"; + cssClass = "tbicon_delete"; label = "Delete"; }, ) ); }; @@ -347,6 +350,11 @@ pageName = "UIxMailEditor"; actionName = "save"; }; + delete = { + protectedBy = "View"; + pageName = "UIxMailEditor"; + actionName = "delete"; + }; viewAttachments = { protectedBy = "View";