From: helge Date: Mon, 25 Oct 2004 22:26:00 +0000 (+0000) Subject: first version which can store draft infos X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ac545e6887238e8d97b16fb91e4eeb74dcfee6e7;p=scalable-opengroupware.org first version which can store draft infos git-svn-id: http://svn.opengroupware.org/SOGo/trunk@422 d1b88da0-ebda-0310-925b-ed51d893ca5b --- diff --git a/SOGo/Main/GNUmakefile.preamble b/SOGo/Main/GNUmakefile.preamble index dcfdd9ed..e70c8e01 100644 --- a/SOGo/Main/GNUmakefile.preamble +++ b/SOGo/Main/GNUmakefile.preamble @@ -9,6 +9,7 @@ ADDITIONAL_LIB_DIRS += \ -L../../OGoContentStore/$(GNUSTEP_OBJ_DIR)/ \ -L../../SOGoLogic/$(GNUSTEP_OBJ_DIR)/ \ -L/usr/local/lib -L/usr/lib +# todo: use syslibs ADDITIONAL_TOOL_LIBS += \ -lSOGo \ diff --git a/SOGo/SoObjects/Mailer/ChangeLog b/SOGo/SoObjects/Mailer/ChangeLog index a88df095..c2f57fbb 100644 --- a/SOGo/SoObjects/Mailer/ChangeLog +++ b/SOGo/SoObjects/Mailer/ChangeLog @@ -1,3 +1,8 @@ +2004-10-25 Helge Hess + + * SOGoDraftObject.m: added ability to manage a draft object folder + (v0.9.37) + 2004-10-21 Helge Hess * SOGoMailBaseObject.m: extract IMAP4 password from HTTP basic diff --git a/SOGo/SoObjects/Mailer/SOGoDraftObject.h b/SOGo/SoObjects/Mailer/SOGoDraftObject.h index 20398688..6e4cda41 100644 --- a/SOGo/SoObjects/Mailer/SOGoDraftObject.h +++ b/SOGo/SoObjects/Mailer/SOGoDraftObject.h @@ -34,10 +34,20 @@ folder are some kind of "mail creation transaction". */ +@class NSString, NSArray, NSDictionary; + @interface SOGoDraftObject : SOGoMailBaseObject { + NSString *path; } +/* contents */ + +- (NSDictionary *)fetchInfo; +- (BOOL)storeInfo:(NSDictionary *)_info; + +- (NSArray *)fetchAttachmentNames; + @end #endif /* __Mailer_SOGoDraftObject_H__ */ diff --git a/SOGo/SoObjects/Mailer/SOGoDraftObject.m b/SOGo/SoObjects/Mailer/SOGoDraftObject.m index 3e6c967c..8b7f3365 100644 --- a/SOGo/SoObjects/Mailer/SOGoDraftObject.m +++ b/SOGo/SoObjects/Mailer/SOGoDraftObject.m @@ -20,12 +20,145 @@ */ #include "SOGoDraftObject.h" +#include #include "common.h" @implementation SOGoDraftObject - (void)dealloc { + [self->path release]; [super dealloc]; } +/* draft folder functionality */ + +- (NSFileManager *)spoolFileManager { + return [[self container] spoolFileManager]; +} +- (NSString *)userSpoolFolderPath { + return [[self container] userSpoolFolderPath]; +} +- (BOOL)_ensureUserSpoolFolderPath { + return [[self container] _ensureUserSpoolFolderPath]; +} + +/* draft object functionality */ + +- (NSString *)draftFolderPath { + if (self->path != nil) + return self->path; + + self->path = [[[self userSpoolFolderPath] stringByAppendingPathComponent: + [self nameInContainer]] copy]; + return self->path; +} +- (BOOL)_ensureDraftFolderPath { + NSFileManager *fm; + + if (![self _ensureUserSpoolFolderPath]) + return NO; + + if ((fm = [self spoolFileManager]) == nil) { + [self logWithFormat:@"ERROR: missing spool file manager!"]; + return NO; + } + return [fm createDirectoriesAtPath:[self draftFolderPath] attributes:nil]; +} + +- (NSString *)infoPath { + return [[self draftFolderPath] + stringByAppendingPathComponent:@".info.plist"]; +} + +/* contents */ + +- (BOOL)storeInfo:(NSDictionary *)_info { + if (_info == nil) { + [self logWithFormat:@"WARNING: got no info to write for draft!"]; + return NO; + } + if (![self _ensureDraftFolderPath]) { + [self logWithFormat:@"ERROR: could not create folder for draft!"]; + return NO; + } + if (![_info writeToFile:[self infoPath] atomically:YES]) { + [self logWithFormat:@"ERROR: could not write info %@", [self infoPath]]; + return NO; + } + return YES; +} +- (NSDictionary *)fetchInfo { + NSDictionary *info; + NSString *p; + + p = [self infoPath]; + if (![[self spoolFileManager] fileExistsAtPath:p]) { + [self debugWithFormat:@"Note: info object does not yet exist: %@", p]; + return nil; + } + + if ((info = [NSDictionary dictionaryWithContentsOfFile:p]) == nil) + [self logWithFormat:@"ERROR: dictionary broken at path: %@", p]; + + return info; +} + +- (NSArray *)fetchAttachmentNames { + NSMutableArray *ma; + NSFileManager *fm; + NSArray *files; + unsigned i, count; + + fm = [self spoolFileManager]; + if ((files = [fm directoryContentsAtPath:[self draftFolderPath]]) == nil) + return nil; + + count = [files count]; + ma = [NSMutableArray arrayWithCapacity:count]; + for (i = 0; i < count; i++) { + NSString *filename; + + filename = [files objectAtIndex:i]; + if ([filename hasPrefix:@"."]) + continue; + + [ma addObject:filename]; + } + return ma; +} + +- (BOOL)isValidAttachmentName:(NSString *)_name { + NSRange r; + + if (![_name isNotNull]) return NO; + if ([_name length] == 0) return NO; + if ([_name hasPrefix:@"."]) return NO; + + r = [_name rangeOfString:@"/"]; + if (r.length > 0) return NO; + r = [_name rangeOfString:@".."]; + if (r.length > 0) return NO; + r = [_name rangeOfString:@"~"]; + if (r.length > 0) return NO; + + return YES; +} + +- (BOOL)saveAttachment:(NSData *)_attachment withName:(NSString *)_name { + NSString *p; + + if (_attachment == nil) + return NO; + + if (![self _ensureDraftFolderPath]) { + [self logWithFormat:@"ERROR: could not create folder for draft!"]; + return NO; + } + if (![self isValidAttachmentName:_name]) + return NO; + + p = [[self draftFolderPath] stringByAppendingPathComponent:_name]; + return [_attachment writeToFile:p atomically:YES]; +} + @end /* SOGoDraftObject */ diff --git a/SOGo/SoObjects/Mailer/Version b/SOGo/SoObjects/Mailer/Version index 734431d7..68464731 100644 --- a/SOGo/SoObjects/Mailer/Version +++ b/SOGo/SoObjects/Mailer/Version @@ -1,6 +1,6 @@ # Version file -SUBMINOR_VERSION:=36 +SUBMINOR_VERSION:=37 # v0.9.35 requires SOGoLogic v0.9.24 # v0.9.34 requires SOGoLogic v0.9.22 diff --git a/SOGo/UI/Mailer/ChangeLog b/SOGo/UI/Mailer/ChangeLog index c9999d70..75de6540 100644 --- a/SOGo/UI/Mailer/ChangeLog +++ b/SOGo/UI/Mailer/ChangeLog @@ -1,3 +1,12 @@ +2004-10-25 Helge Hess + + * v0.9.45 + + * uix.css: replaced invalid "text-color" with "color" + + * UIxMailEditor.wox: bind subject/text, can load/save info object in + draft + 2004-10-22 Marcus Mueller * v0.9.44 diff --git a/SOGo/UI/Mailer/UIxMailAccountView.wox b/SOGo/UI/Mailer/UIxMailAccountView.wox index 0d5e4055..b35b46c4 100644 --- a/SOGo/UI/Mailer/UIxMailAccountView.wox +++ b/SOGo/UI/Mailer/UIxMailAccountView.wox @@ -19,11 +19,12 @@
Email

-
  • Read messages
  • -
  • Write a new message
  • +
  • Read messages (TBD: link)
  • +
  • Write a new message (TBD: link)


  • +
    Screenshot

    screenshot diff --git a/SOGo/UI/Mailer/UIxMailEditor.m b/SOGo/UI/Mailer/UIxMailEditor.m index 532149ff..a280c94c 100644 --- a/SOGo/UI/Mailer/UIxMailEditor.m +++ b/SOGo/UI/Mailer/UIxMailEditor.m @@ -41,10 +41,20 @@ @end +#include #include "common.h" @implementation UIxMailEditor +static NSArray *infoKeys = nil; + ++ (void)initialize { + infoKeys = [[NSArray alloc] initWithObjects: + @"subject", @"text", @"to", @"cc", @"bcc", + @"from", @"replyTo", + nil]; +} + - (void)dealloc { [self->text release]; [self->subject release]; @@ -56,39 +66,64 @@ /* accessors */ +- (void)setFrom:(NSString *)_ignore { +} +- (NSString *)from { +#warning TODO: retrieve email of account using SOGoUserManager, -emailForUID: + return @"hh@skyrix.com"; +} +- (void)setReplyTo:(NSString *)_ignore { +} +- (NSString *)replyTo { + /* we are here for future extensibility */ + return @""; +} + - (void)setSubject:(NSString *)_value { ASSIGNCOPY(self->subject, _value); } - (NSString *)subject { - return self->subject; + return self->subject ? self->subject : @""; } - (void)setText:(NSString *)_value { ASSIGNCOPY(self->text, _value); } - (NSString *)text { - return self->text; + return [self->text isNotNull] ? self->text : @""; } - (void)setTo:(NSArray *)_value { ASSIGNCOPY(self->to, _value); } - (NSArray *)to { - return self->to; + return [self->to isNotNull] ? self->to : [NSArray array]; } - (void)setCc:(NSArray *)_value { ASSIGNCOPY(self->cc, _value); } - (NSArray *)cc { - return self->cc; + return [self->cc isNotNull] ? self->cc : [NSArray array]; } - (void)setBcc:(NSArray *)_value { ASSIGNCOPY(self->bcc, _value); } - (NSArray *)bcc { - return self->bcc; + return [self->bcc isNotNull] ? self->bcc : [NSArray array]; +} + +/* info loading */ + +- (void)loadInfo:(NSDictionary *)_info { + if (![_info isNotNull]) return; + [self debugWithFormat:@"loading info ..."]; + [self takeValuesFromDictionary:_info]; +} +- (NSDictionary *)storeInfo { + [self debugWithFormat:@"storing info ..."]; + return [self valuesForKeys:infoKeys]; } /* requests */ @@ -99,20 +134,35 @@ /* actions */ -- (id)saveAction { -#if 0 - NSException *ex; +- (id)editAction { + [self logWithFormat:@"edit action, load content from: %@", + [self clientObject]]; + + [self loadInfo:[[self clientObject] fetchInfo]]; + return self; +} - ex = [[self clientObject] saveContentString:content]; - if (ex != nil) { - [self setErrorText:[ex reason]]; - return self; +- (id)saveAction { + NSDictionary *info; + + if ((info = [self storeInfo]) != nil) { + if (![[self clientObject] storeInfo:info]) { + [self logWithFormat:@"ERROR: failed to store draft!"]; + // TODO: improve error handling + return nil; + } } - return [self redirectToLocation:[self _completeURIForMethod:@".."]]; -#else + [self logWithFormat:@"save action, store content to: %@", + [self clientObject]]; + return self; +} + +- (id)sendAction { + [self logWithFormat:@"send action, store content, send mail, store: %@", + [self clientObject]]; + // if everything is ok, close the window (send a JS closing the Window) return self; -#endif } @end /* UIxMailEditor */ diff --git a/SOGo/UI/Mailer/UIxMailEditor.wox b/SOGo/UI/Mailer/UIxMailEditor.wox index 2bdf5bca..e23d3faf 100644 --- a/SOGo/UI/Mailer/UIxMailEditor.wox +++ b/SOGo/UI/Mailer/UIxMailEditor.wox @@ -37,14 +37,15 @@ Subject: + id="compose_subject_input" type="text" + var:value="subject" />
    -