Added support for MailDAV PUT

Monotone-Parent: 90509c89f14ff1a8b0d7884244366bd33783ccc1
Monotone-Revision: 8515028ade639f5e3e38f20b4eba28b16a1250b1

Monotone-Author: crobert@inverse.ca
Monotone-Date: 2009-09-29T20:13:36
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
C Robert committed 2009-09-29 20:13:36 +00:00
1 parent 0aaaf59814
commit 9493a33729
17 files changed
+344 -52

No files matched your search

+3 -16
View File
@@ -365,19 +365,6 @@ static BOOL showTextAttachmentsInline = NO;
return IMAP4ID;
}
- (int) _IMAP4IDFromAppendResult: (NSDictionary *) result
{
NSDictionary *results;
NSString *flag, *newIdString;
results = [[result objectForKey: @"RawResponse"]
objectForKey: @"ResponseResult"];
flag = [results objectForKey: @"flag"];
newIdString = [[flag componentsSeparatedByString: @" "] objectAtIndex: 2];
return [newIdString intValue];
}
- (NSException *) save
{
NGImap4Client *client;
@@ -405,7 +392,7 @@ static BOOL showTextAttachmentsInline = NO;
{
if (IMAP4ID > -1)
error = [imap4 markURLDeleted: [self imap4URL]];
IMAP4ID = [self _IMAP4IDFromAppendResult: result];
IMAP4ID = [self IMAP4IDFromAppendResult: result];
[self storeInfo];
}
else
@@ -695,7 +682,7 @@ static BOOL showTextAttachmentsInline = NO;
else
{
// TODO: use subject for filename?
// error = [newDraft saveAttachment:content withName:@"forward.mail"];
// error = [newDraft saveAttachment:content withName:@"forward.eml"];
signature = [currentUser signature];
if ([signature length])
[self setText: [NSString stringWithFormat: @"\n-- \n%@", signature]];
@@ -936,7 +923,7 @@ static BOOL showTextAttachmentsInline = NO;
if ([_ext isEqualToString: @"gif"]) return @"image/gif";
if ([_ext isEqualToString: @"jpg"]) return @"image/jpeg";
if ([_ext isEqualToString: @"jpeg"]) return @"image/jpeg";
if ([_ext isEqualToString: @"mail"]) return @"message/rfc822";
if ([_ext isEqualToString: @"eml"]) return @"message/rfc822";
return @"application/octet-stream";
}
+3
View File
@@ -42,12 +42,15 @@
@interface SOGoMailAccount : SOGoMailBaseObject
{
NSString *accountName;
SOGoMailFolder *inboxFolder;
SOGoDraftsFolder *draftsFolder;
SOGoSentFolder *sentFolder;
SOGoTrashFolder *trashFolder;
}
- (void) setAccountName: (NSString *) newAccountName;
- (BOOL) supportsQuotas;
/* folder pathes */
+14 -9
View File
@@ -121,6 +121,7 @@ static NSString *fallbackIMAP4Server = nil;
draftsFolder = nil;
sentFolder = nil;
trashFolder = nil;
accountName = nil;
}
return self;
@@ -132,9 +133,15 @@ static NSString *fallbackIMAP4Server = nil;
[draftsFolder release];
[sentFolder release];
[trashFolder release];
[accountName release];
[super dealloc];
}
- (void) setAccountName: (NSString *) newAccountName
{
ASSIGN (accountName, newAccountName);
}
/* shared accounts */
- (BOOL) isSharedAccount
@@ -142,7 +149,7 @@ static NSString *fallbackIMAP4Server = nil;
NSString *s;
NSRange r;
s = [self nameInContainer];
s = accountName;
r = [s rangeOfString:@"@"];
if (r.length == 0) /* regular HTTP logins are never a shared mailbox */
return NO;
@@ -275,7 +282,7 @@ static NSString *fallbackIMAP4Server = nil;
NSDictionary *mailAccount;
NSString *username, *escUsername, *hostString;
mailAccount = [[context activeUser] accountWithName: nameInContainer];
mailAccount = [[context activeUser] accountWithName: accountName];
if (mailAccount)
{
username = [mailAccount objectForKey: @"userName"];
@@ -536,21 +543,19 @@ static NSString *fallbackIMAP4Server = nil;
- (NSString *) shortTitle
{
NSString *s, *login, *host;
NSString *login, *host;
NSRange r;
s = [self nameInContainer];
r = [s rangeOfString:@"@"];
r = [accountName rangeOfString:@"@"];
if (r.length > 0)
{
login = [s substringToIndex:r.location];
host = [s substringFromIndex:(r.location + r.length)];
login = [accountName substringToIndex:r.location];
host = [accountName substringFromIndex:(r.location + r.length)];
}
else
{
login = nil;
host = s;
host = accountName;
}
r = [host rangeOfString:@"."];
+5
View File
@@ -38,10 +38,15 @@
*/
@class NSArray;
@class NSMutableDictionary;
@interface SOGoMailAccounts : SOGoFolder
{
NSMutableDictionary *accountKeys;
}
- (NSArray *) toManyRelationshipKeys;
- (NSDictionary *) accountKeys;
@end
+58 -13
View File
@@ -19,6 +19,7 @@
02111-1307, USA.
*/
#import <Foundation/NSDictionary.h>
#import <Foundation/NSString.h>
#import <NGObjWeb/NSException+HTTP.h>
@@ -27,6 +28,7 @@
#import <NGExtensions/NSObject+Logs.h>
#import "../SOGo/NSArray+Utilities.h"
#import "../SOGo/NSString+Utilities.h"
#import "../SOGo/SOGoUser.h"
#import "SOGoMailAccount.h"
@@ -41,22 +43,59 @@
// return [[container nameInContainer] isEqualToString: userLogin];
// }
- (NSArray *) toManyRelationshipKeys
- (id) init
{
if ((self = [super init]))
{
accountKeys = nil;
}
return self;
}
- (void) dealloc
{
[accountKeys release];
[super dealloc];
}
- (void) _initAccountKeys
{
NSArray *accounts;
NSString *currentName;
int count, max;
accounts = [[context activeUser] mailAccounts];
if (!accountKeys)
{
accountKeys = [NSMutableDictionary new];
return [accounts objectsForKey: @"name" notFoundMarker: nil];
accounts = [[context activeUser] mailAccounts];
max = [accounts count];
for (count = 0; count < max; count++)
{
currentName = [[accounts objectAtIndex: count] objectForKey: @"name"];
[accountKeys setObject: currentName
forKey: [currentName asCSSIdentifier]];
}
}
}
- (NSDictionary *) accountKeys
{
[self _initAccountKeys];
return accountKeys;
}
- (NSArray *) toManyRelationshipKeys
{
[self _initAccountKeys];
return [accountKeys allKeys];
}
/* name lookup */
- (BOOL) isValidMailAccountName: (NSString *) _key
{
return [[self toManyRelationshipKeys] containsObject: _key];
}
// - (id) mailAccountWithName: (NSString *) _key
// inContext: (id) _ctx
// {
@@ -76,10 +115,11 @@
// }
- (id) lookupName: (NSString *) _key
inContext: (id) _ctx
acquire: (BOOL) _flag
inContext: (id) _ctx
acquire: (BOOL) _flag
{
id obj;
NSString *accountName;
// NSString *userLogin;
// userLogin = [[context activeUser] login];
@@ -96,10 +136,15 @@
obj = [super lookupName:_key inContext:_ctx acquire:NO];
if (!obj)
{
if ([self isValidMailAccountName: _key])
obj = [SOGoMailAccount objectWithName: _key inContainer: self];
[self _initAccountKeys];
accountName = [accountKeys objectForKey: _key];
if ([accountName length])
{
obj = [SOGoMailAccount objectWithName: _key inContainer: self];
[obj setAccountName: accountName];
}
else
obj = [NSException exceptionWithHTTPStatus: 404 /* Not Found */];
obj = [NSException exceptionWithHTTPStatus: 404 /* Not Found */];
}
return obj;
+2
View File
@@ -78,6 +78,8 @@
- (BOOL) isBodyPartKey: (NSString *) key;
- (int) IMAP4IDFromAppendResult: (NSDictionary *) result;
@end
#endif /* __Mailer_SOGoMailBaseObject_H__ */
+14
View File
@@ -21,6 +21,7 @@
#import <Foundation/NSCharacterSet.h>
#import <Foundation/NSString.h>
#import <Foundation/NSDictionary.h>
#import <NGObjWeb/SoObject+SoDAV.h>
#import <NGExtensions/NSNull+misc.h>
@@ -230,4 +231,17 @@ static BOOL debugOn = YES;
return nil;
}
- (int) IMAP4IDFromAppendResult: (NSDictionary *) result
{
NSDictionary *results;
NSString *flag, *newIdString;
results = [[result objectForKey: @"RawResponse"]
objectForKey: @"ResponseResult"];
flag = [results objectForKey: @"flag"];
newIdString = [[flag componentsSeparatedByString: @" "] objectAtIndex: 2];
return [newIdString intValue];
}
@end /* SOGoMailBaseObject */
+1 -1
View File
@@ -446,7 +446,7 @@ static BOOL debugOn = NO;
return NSClassFromString(@"SOGoVCardMailBodyPart");
break;
case 4:
if ([pe isEqualToString:@"mail"])
if ([pe isEqualToString:@"eml"])
return NSClassFromString(@"SOGoMessageMailBodyPart");
break;
default:
+4
View File
@@ -94,6 +94,10 @@ typedef enum {
- (NSString *) userSpoolFolderPath;
- (BOOL) ensureSpoolFolderPath;
- (id) appendMessage: (NSData *) message
inContext: (WOContext *) _ctx
usingId: (int *) imap4id;
@end
@interface SOGoSpecialMailFolder : SOGoMailFolder
+78 -1
View File
@@ -259,7 +259,7 @@ static NSString *spoolFolder = nil;
max = [uids count];
for (count = 0; count < max; count++)
{
filename = [NSString stringWithFormat: @"%@.mail",
filename = [NSString stringWithFormat: @"%@.eml",
[uids objectAtIndex: count]];
[filenames addObject: filename];
}
@@ -1102,6 +1102,83 @@ static NSString *spoolFolder = nil;
return [self nameInContainer];
}
// For DAV PUT
- (NSException *) _appendMessageData: (NSData *) data
usingId: (int *) imap4id;
{
NGImap4Client *client;
NSString *folderName;
NSException *error;
id result;
error = nil;
client = [imap4 client];
folderName = [imap4 imap4FolderNameForURL: [self imap4URL]];
result = [client append: data toFolder: folderName withFlags: nil];
if ([[result objectForKey: @"result"] boolValue])
*imap4id = [self IMAP4IDFromAppendResult: result];
else
error = [NSException exceptionWithHTTPStatus: 500 /* Server Error */
reason: @"Failed to store message"];
return error;
}
- (id) appendMessage: (NSData *) message
inContext: (WOContext *) _ctx
usingId: (int *) imap4id
{
NSException *error;
WOResponse *response;
NSString *location;
id msg;
error = [self _appendMessageData: message
usingId: imap4id];
if (error)
response = (WOResponse *) error;
else
{
response = [_ctx response];
[response setStatus: 201];
msg = [SOGoMailObject objectWithName:
[NSString stringWithFormat: @"%d", imap4id]
inContainer: self];
if (msg)
{
location = [NSString stringWithFormat: @"%@%d.eml",
[self davURL], *imap4id];
[response setHeader: location forKey: @"location"];
}
}
return response;
}
- (id) PUTAction: (WOContext *) _ctx
{
WORequest *rq;
NSException *error;
WOResponse *response;
int imap4id;
error = [self matchesRequestConditionInContext: _ctx];
if (error)
response = (WOResponse *) error;
else
{
rq = [_ctx request];
response = [self appendMessage: [rq content]
inContext: _ctx
usingId: &imap4id];
}
return response;
}
@end /* SOGoMailFolder */
@implementation SOGoSpecialMailFolder
+30
View File
@@ -1239,4 +1239,34 @@ static BOOL debugSoParts = NO;
return debugOn;
}
// For DAV PUT
- (id) PUTAction: (WOContext *) _ctx
{
WORequest *rq;
NSException *error;
WOResponse *response;
SOGoMailFolder *folder;
int imap4id;
error = [self matchesRequestConditionInContext: _ctx];
if (error)
response = (WOResponse *) error;
else
{
rq = [_ctx request];
folder = [self container];
if ([self doesMailExist])
response = [NSException exceptionWithHTTPStatus: 403
reason: @"Can't overwrite messages"];
else
response = [folder appendMessage: [rq content]
inContext: _ctx
usingId: &imap4id];
}
return response;
}
@end /* SOGoMailObject */