]> err.no Git - scalable-opengroupware.org/commitdiff
implemented attachment delete
authorhelge <helge@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Tue, 26 Oct 2004 15:12:38 +0000 (15:12 +0000)
committerhelge <helge@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Tue, 26 Oct 2004 15:12:38 +0000 (15:12 +0000)
git-svn-id: http://svn.opengroupware.org/SOGo/trunk@426 d1b88da0-ebda-0310-925b-ed51d893ca5b

SOGo/SoObjects/Mailer/ChangeLog
SOGo/SoObjects/Mailer/SOGoDraftObject.h
SOGo/SoObjects/Mailer/SOGoDraftObject.m
SOGo/SoObjects/Mailer/Version
SOGo/UI/Mailer/ChangeLog
SOGo/UI/Mailer/UIxMailEditorAttach.m
SOGo/UI/Mailer/UIxMailEditorAttach.wox
SOGo/UI/Mailer/Version

index 867e9aa4224f8dd2174105b897ac802f6d1f39aa..04f9120689caeac4341e6a565082bb15b3c1da95 100644 (file)
@@ -1,3 +1,7 @@
+2004-10-26  Helge Hess  <helge.hess@opengroupware.org>
+
+       * SOGoDraftObject.[hm]: added method to delete attachments (v0.9.39)
+
 2004-10-26  Marcus Mueller  <znek@mulle-kybernetik.com>
 
        * SOGoDraftObject.h: lF compile fix (v0.9.38)
index 1ec8bcc4cfad6b9e8e88545180733909362a7396..9a0aedc405e5b603197ef97b5a6996b8f7ba2749 100644 (file)
@@ -49,6 +49,7 @@
 - (NSArray *)fetchAttachmentNames;
 - (BOOL)isValidAttachmentName:(NSString *)_name;
 - (BOOL)saveAttachment:(NSData *)_attachment withName:(NSString *)_name;
+- (BOOL)deleteAttachmentWithName:(NSString *)_name;
 
 @end
 
index 8b7f3365108cd09e1cc6f4fe9ba31157296eb308..722ceaa5699862356b01b1971616143a0888e6a9 100644 (file)
   return [_attachment writeToFile:p atomically:YES];
 }
 
+- (BOOL)deleteAttachmentWithName:(NSString *)_name {
+  NSFileManager *fm;
+  NSString *p;
+  
+  if (![self isValidAttachmentName:_name])
+    return NO;
+  
+  fm = [self spoolFileManager];
+  p  = [[self draftFolderPath] stringByAppendingPathComponent:_name];
+  if (![fm fileExistsAtPath:p])
+    return YES; /* well, doesn't exist, so its deleted ;-) */
+  
+  return [fm removeFileAtPath:p handler:nil];
+}
+
 @end /* SOGoDraftObject */
index e89334b81628c9465adbf05885e13a3c315f9826..5c7b2848bb7d1745fb5cf4475cfcd8481fd15289 100644 (file)
@@ -1,6 +1,6 @@
 # Version file
 
-SUBMINOR_VERSION:=38
+SUBMINOR_VERSION:=39
 
 # v0.9.35 requires SOGoLogic v0.9.24
 # v0.9.34 requires SOGoLogic v0.9.22
index 7152649e6e3d7113d3e08a584292a1dc3cb46e50..acf01f5e9ee65587a9ef9a00fd3046b0065ca46e 100644 (file)
@@ -1,5 +1,7 @@
 2004-10-26  Helge Hess  <helge.hess@opengroupware.org>
 
+       * UIxMailEditorAttach.m: added attachment delete (v0.9.48)
+
        * UIxMailEditorAttach.wox, mailer.css: work on layout, added delete
          action (v0.9.47)
 
index efae6dfaf1cea88e8821bd7f0ed0fd84d6ac3cbc..d20c27197f063bc6095b5a600b1a48658da3f314 100644 (file)
@@ -40,6 +40,8 @@
   NSData   *fileData2;
   NSData   *fileData3;
   NSString *attachmentName;
+
+  NSArray *attachmentNames;
 }
 
 @end
@@ -50,6 +52,7 @@
 @implementation UIxMailEditorAttach
 
 - (void)dealloc {
+  [self->attachmentNames release];
   [self->attachmentName release];
   [self->filePath1 release];
   [self->filePath2 release];
   return self->fileData3;
 }
 
+- (NSArray *)attachmentNames {
+  NSArray *a;
+
+  if (self->attachmentNames != nil)
+    return self->attachmentNames;
+  
+  a = [[self clientObject] fetchAttachmentNames];
+  a = [a sortedArrayUsingSelector:@selector(compare:)];
+  self->attachmentNames = [a copy];
+  return self->attachmentNames;
+}
+- (BOOL)hasAttachments {
+  return [[self attachmentNames] count] > 0 ? YES : NO;
+}
+
 /* requests */
 
 - (BOOL)shouldTakeValuesFromRequest:(WORequest *)_rq inContext:(WOContext*)_c{
 
 /* operations */
 
+- (NSString *)defaultPathExtension {
+  return @"txt";
+}
+
+- (NSString *)newAttachmentName {
+  NSArray  *usedNames;
+  unsigned i;
+  
+  usedNames = [[self clientObject] fetchAttachmentNames];
+  for (i = [usedNames count]; i < 100; i++) {
+    NSString *name;
+    
+    name = [NSString stringWithFormat:@"attachment%d", i];
+    if (![usedNames containsObject:name])
+      return name;
+  }
+  [self logWithFormat:@"ERROR: too many attachments?!"];
+  return nil;
+}
+
+- (NSString *)fixupAttachmentName:(NSString *)_name {
+  NSString *pe;
+  NSRange r;
+
+  if (_name == nil)
+    return  nil;
+  
+  pe = [_name pathExtension];
+  if ([pe length] == 0)
+    /* would be better to check the content-type, but well */
+    pe = [self defaultPathExtension];
+  
+  r = [_name rangeOfString:@"/"];
+  if (r.length > 0) _name = [_name lastPathComponent];
+  
+  r = [_name rangeOfString:@" "];
+  if (r.length > 0) 
+    _name = [_name stringByReplacingString:@" " withString:@"_"];
+  
+  if ([_name hasPrefix:@"."]) {
+    _name = [@"dotfile-" stringByAppendingString:
+               [_name substringFromIndex:1]];
+  }
+  
+  // TODO: should we need to check for umlauts?
+  
+  if ([_name length] == 0)
+    return [[self newAttachmentName] stringByAppendingPathExtension:pe];
+  
+  return _name;
+}
+
 - (BOOL)saveFileData:(NSData *)_data name:(NSString *)_name {
-  [self logWithFormat:@"TODO: save attachment %@, length %d",
-       _name, [_data length]];
-  return NO;
+  if (_data == nil)
+    return NO;
+  if ([_name length] == 0) {
+    _name = [self newAttachmentName];
+    _name = [_name stringByAppendingPathExtension:[self defaultPathExtension]];
+  }
+  
+  if ((_name = [self fixupAttachmentName:_name]) == nil)
+    return nil;
+  
+  // TODO: add size limit?
+  return [[self clientObject] saveAttachment:_data withName:_name];
 }
 
 /* actions */
 
 - (id)viewAttachmentsAction {
-  [self logWithFormat:@"view attachments ..."];
+  [self debugWithFormat:@"view attachments ..."];
   return self;
 }
 
 - (id)attachAction {
-  [self logWithFormat:@"should save ..."];
-
-  // TODO: error handling!
+  BOOL ok;
   
+  ok = YES;
   if ([self->fileData1 length] > 0)
-    [self saveFileData:self->fileData1 name:[self filePath1]];
-  if ([self->fileData2 length] > 0)
-    [self saveFileData:self->fileData2 name:[self filePath2]];
-  if ([self->fileData3 length] > 0)
+    ok = [self saveFileData:self->fileData1 name:[self filePath1]];
+  if (ok && [self->fileData2 length] > 0)
+    ok = [self saveFileData:self->fileData2 name:[self filePath2]];
+  if (ok && [self->fileData3 length] > 0)
     [self saveFileData:self->fileData3 name:[self filePath3]];
   
-  return self;
+  if (!ok) {
+    // TODO: improve error handling
+    return [NSException exceptionWithHTTPStatus:500 /* server error */
+                       reason:@"failed to save attachment ..."];
+  }
+  
+  return [self redirectToLocation:@"viewAttachments"];
 }
 
 - (id)deleteAttachmentAction {
-  [self logWithFormat:@"delete attachment: %@", [self attachmentName]];
-  return self;
+  if (![[self clientObject] deleteAttachmentWithName:[self attachmentName]]) {
+    // TODO: improve error handling
+    return [NSException exceptionWithHTTPStatus:500 /* server error */
+                       reason:@"failed to delete attachment ..."];
+  }
+  
+  return [self redirectToLocation:@"viewAttachments"];
 }
 
 @end /* UIxMailEditorAttach */
index d0c4aa5f5e7a82c3ea10591719236d9c71bf5f80..fb002ce2dc5c794aba219fe425e719f68fc9ef18 100644 (file)
       </div>
   
       <div id="attachment_list">
-       <div style="padding: 4px;">
-
-        <div class="embedwhite_out">
-          <div class="embedwhite_in">
-            <table border="0" width="100%" cellspacing="0" cellpadding="1">
-              <tr class="tableview">
-                <td class="tbtv_headercell">
-                  Attachments
-                </td>
-                <td class="tbtv_headercell" width="10%">
-                  <entity name="nbsp" />
-                </td>
-              </tr>
-  
-              <var:foreach list="clientObject.fetchAttachmentNames" 
-                           item="attachmentName">
-                <tr class="tableview">
-                  <td><var:string value="attachmentName" /></td>
-                  <td>
-                    <a href="deleteAttachment" 
-                       var:_attachmentName="attachmentName"
-                       >delete</a>
-                  </td>
-                </tr>
-              </var:foreach>
-            </table>
-          </div>
+        <div style="padding: 4px;">
+          <var:if condition="hasAttachments">
+            <div class="embedwhite_out">
+              <div class="embedwhite_in">
+                <table border="0" width="100%" cellspacing="0" cellpadding="1">
+                  <tr class="tableview">
+                    <td class="tbtv_headercell">
+                      Attachments
+                    </td>
+                    <td class="tbtv_headercell" width="10%">
+                      <entity name="nbsp" />
+                    </td>
+                  </tr>
+      
+                  <var:foreach list="attachmentNames" item="attachmentName">
+                    <tr class="tableview">
+                      <td><var:string value="attachmentName" /></td>
+                      <td>
+                        <a href="deleteAttachment" 
+                           var:_attachmentName="attachmentName"
+                           >delete</a>
+                      </td>
+                    </tr>
+                  </var:foreach>
+                </table>
+              </div>
+            </div>
+          </var:if>
         </div>
-       </div>
       </div>
     </form>
   </body>
index ea2cd5d944558c4c3c17a9964750238ff9edad00..98a3496aa61b0722156afe4204584859e00a798d 100644 (file)
@@ -1,6 +1,6 @@
 # $Id$
 
-SUBMINOR_VERSION:=47
+SUBMINOR_VERSION:=48
 
 # v0.9.43 requires NGObjWeb v4.3.73
 # v0.9.42 requires NGObjWeb v4.3.72