Mailer: replace HTML view by JSON object

pull/91/head
Francis Lachapelle 2014-11-21 15:50:01 -05:00
parent bd9da51e83
commit 277bdd2b1c
2 changed files with 80 additions and 132 deletions

View File

@ -22,6 +22,8 @@
#import <Foundation/NSDictionary.h>
#import <Foundation/NSException.h>
#import <Foundation/NSValue.h>
#import <NGObjWeb/NSException+HTTP.h>
#import <NGObjWeb/WORequest.h>
#import <NGObjWeb/WOResponse.h>
@ -41,6 +43,7 @@
#import <NGImap4/NGImap4Envelope.h>
#import <NGImap4/NGImap4EnvelopeAddress.h>
#import <SOGo/NSDictionary+Utilities.h>
#import <SOGo/NSString+Utilities.h>
#import <SOGo/SOGoBuild.h>
#import <SOGo/SOGoMailer.h>
@ -59,12 +62,17 @@
@interface UIxMailView : UIxComponent
{
id currentAddress;
NSString *shouldAskReceipt;
NSNumber *shouldAskReceipt;
NSString *matchingIdentityEMail;
NSDictionary *attachment;
NSArray *attachmentAttrs;
}
- (BOOL) mailIsDraft;
- (NSNumber *) shouldAskReceipt;
- (NSArray *) formattedAddresses: (NSArray *) theAddresses;
- (NSString *) formattedDate;
@end
@implementation UIxMailView
@ -183,6 +191,34 @@ static NSString *mailETag = nil;
return [UIxMailSizeFormatter sharedMailSizeFormatter];
}
- (NSArray *) formattedAddresses: (NSArray *) theAddresses
{
NSMutableArray *addresses;
NSFormatter *formatter;
NGImap4EnvelopeAddress *address;
int count, i;
formatter = [[self context] mailEnvelopeFullAddressFormatter];
count = [theAddresses count];
addresses = [NSMutableArray arrayWithCapacity: count];
for (i = 0; i < count; i++)
{
address = [theAddresses objectAtIndex: i];
[addresses addObject: [formatter stringForObjectValue: address]];
}
return addresses;
}
- (NSString *) formattedDate
{
NSFormatter *formatter;
formatter = [[self context] mailDateFormatter];
return [formatter stringForObjectValue: [[self clientObject] date]];
}
- (NSString *) attachmentsText
{
if ([[self attachmentAttrs] count] > 1)
@ -206,10 +242,14 @@ static NSString *mailETag = nil;
/* actions */
- (id) defaultAction
- (id <WOActionResults>) defaultAction
{
WOResponse *response;
id <WOActionResults> response;
NSString *s;
NSDictionary *data;
SOGoMailObject *co;
co = [self clientObject];
/* check etag to see whether we really must rerender */
/*
@ -226,23 +266,46 @@ static NSString *mailETag = nil;
/* client already has the proper entity */
// [self logWithFormat:@"MATCH: %@ (tag %@)", s, mailETag];
if (![[self clientObject] doesMailExist]) {
return [NSException exceptionWithHTTPStatus:404 /* Not Found */
reason:@"message got deleted"];
}
if (![co doesMailExist])
{
data = [NSDictionary dictionaryWithObjectsAndKeys:
@"message got deleted", @"error",
nil];
return [self responseWithStatus: 404 /* Not Found */
andString: [data jsonRepresentation]];
}
response = [context response];
[response setStatus: 304 /* Not Modified */];
response = [self responseWithStatus: 304];
return response;
}
}
if (![self message]) // TODO: redirect to proper error
return [NSException exceptionWithHTTPStatus:404 /* Not Found */
reason:@"did not find specified message!"];
{
data = [NSDictionary dictionaryWithObjectsAndKeys:
@"did not find specified message!", @"error",
nil];
return [self responseWithStatus: 404 /* Not Found */
andString: [data jsonRepresentation]];
}
return self;
data = [NSDictionary dictionaryWithObjectsAndKeys:
[self formattedAddresses: [co fromEnvelopeAddresses]], @"fromAddresses",
[self formattedAddresses: [co toEnvelopeAddresses]], @"toAddresses",
[self formattedAddresses: [co ccEnvelopeAddresses]], @"ccAddresses",
[self formattedAddresses: [co bccEnvelopeAddresses]], @"bccAddresses",
[self formattedAddresses: [co replyToEnvelopeAddresses]], @"replyToAddresses",
[self formattedDate], @"date",
[self attachmentAttrs], @"attachmentAttrs",
[self shouldAskReceipt], @"shouldAskReceipt",
[NSNumber numberWithBool: [self mailIsDraft]], @"isDraft",
[[self generateResponse] contentAsString], @"content",
nil];
response = [self responseWithStatus: 200
andString: [data jsonRepresentation]];
return response;
}
/* MDN */
@ -549,7 +612,7 @@ static NSString *mailETag = nil;
[self _flagMessageWithMDNSent];
}
- (NSString *) shouldAskReceipt
- (NSNumber *) shouldAskReceipt
{
NGMailAddress *mailAddress;
NSDictionary *mailHeaders;
@ -557,7 +620,7 @@ static NSString *mailETag = nil;
if (!shouldAskReceipt)
{
shouldAskReceipt = @"false";
shouldAskReceipt = [NSNumber numberWithBool: NO];
mailHeaders = [[self clientObject] mailHeaders];
email = [mailHeaders objectForKey: @"disposition-notification-to"];
if (!email)
@ -584,7 +647,7 @@ static NSString *mailETag = nil;
action = [self _receiptAction];
if ([action isEqualToString: @"ask"])
{
shouldAskReceipt = @"true";
shouldAskReceipt = [NSNumber numberWithBool: YES];
[self _flagMessageWithMDNSent];
}
else if ([action isEqualToString: @"send"])

View File

@ -2,123 +2,8 @@
<container xmlns="http://www.w3.org/1999/xhtml"
xmlns:var="http://www.skyrix.com/od/binding"
xmlns:const="http://www.skyrix.com/od/constant"
xmlns:uix="OGo:uix"
xmlns:rsrc="OGo:url"
xmlns:label="OGo:label">
<var:if condition="clientObject.hasAttachment">
<div class="menu" const:id="attachmentsMenu">
<ul>
<li><var:string label:value="Save all"/></li>
<li class="separator"><!-- separator --></li
><var:foreach list="attachmentAttrs" item="attachment">
<li var:data-url="attachment.urlAsAttachment"><img rsrc:src="attachment.gif"/><var:string value="attachment.filename"
/> <span class="muted">(<var:string value="attachment.size" formatter="sizeFormatter"/>)</span></li>
</var:foreach
></ul>
</div>
</var:if>
<span id="messageContent">
<input type="hidden" const:id="shouldAskReceipt" var:value="shouldAskReceipt"/>
<span id="actionButtons">
<var:if var:condition="mailIsDraft"
><a href="#" const:id="editDraftButton" class="button"><span><var:string label:value="Edit Draft..."/></span></a
></var:if>
<a href="#" const:name="loadImagesButton" const:id="loadImagesButton"
class="button"><span><var:string label:value="Load Images"/></span></a>
</span>
<table class="mailer_fieldtable">
<tr class="mailer_fieldrow">
<td class="mailer_fieldname" ><var:string label:value="Subject"/>:</td>
<td class="mailer_subjectfieldvalue" id="subject"><var:string value="messageSubject"/></td>
</tr>
<tr class="mailer_fieldrow">
<td class="mailer_fieldname" ><var:string label:value="From"/>:</td>
<td class="mailer_fieldvalue">
<var:foreach list="clientObject.fromEnvelopeAddresses"
item="currentAddress">
<a var:href="currentAddressLink">
<var:string value="currentAddress"
formatter="context.mailEnvelopeFullAddressFormatter" /></a>
</var:foreach>
</td>
</tr>
<tr class="mailer_fieldrow">
<td class="mailer_fieldname"><var:string label:value="Date"/>:</td>
<td class="mailer_fieldvalue">
<var:string value="clientObject.date"
formatter="context.mailDateFormatter"/>
</td>
</tr>
<tr class="mailer_fieldrow">
<td class="mailer_fieldname"><img rsrc:src="plus.png" class="collapse" style="display: none;" /><var:string label:value="To"/>:</td>
<td class="mailer_fieldvalue">
<span class="collapse"><var:foreach list="clientObject.toEnvelopeAddresses"
item="currentAddress"
><a var:href="currentAddressLink">
<var:string value="currentAddress"
formatter="context.mailEnvelopeFullAddressFormatter"
/></a>
</var:foreach></span>
</td>
</tr>
<var:if condition="hasCC">
<tr class="mailer_fieldrow">
<td class="mailer_fieldname"><img rsrc:src="plus.png" class="collapse" style="display: none;" /><var:string label:value="CC"/>:</td>
<td class="mailer_fieldvalue">
<span class="collapse"><var:foreach list="clientObject.ccEnvelopeAddresses"
item="currentAddress">
<a var:href="currentAddressLink"
><var:string value="currentAddress"
formatter="context.mailEnvelopeFullAddressFormatter"
/></a>
<!-- TODO: better to use li+CSS -->
</var:foreach></span>
</td>
</tr>
</var:if>
<var:if condition="hasBCC">
<tr class="mailer_fieldrow">
<td class="mailer_fieldname"><img rsrc:src="plus.png" class="collapse" style="display: none;" /><var:string label:value="Bcc"/>:</td>
<td class="mailer_fieldvalue">
<span class="collapse"><var:foreach list="clientObject.bccEnvelopeAddresses"
item="currentAddress">
<a var:href="currentAddressLink"
><var:string value="currentAddress"
formatter="context.mailEnvelopeFullAddressFormatter"
/></a>
<!-- TODO: better to use li+CSS -->
</var:foreach></span>
</td>
</tr>
</var:if>
<var:if condition="hasReplyTo">
<tr class="mailer_fieldrow">
<td class="mailer_fieldname"><var:string label:value="Reply-To"/>:</td>
<td class="mailer_fieldvalue">
<var:foreach list="clientObject.replyToEnvelopeAddresses"
item="currentAddress">
<a var:href="currentAddressLink"
><var:string value="currentAddress"
formatter="context.mailEnvelopeFullAddressFormatter"
/></a>
</var:foreach>
</td>
</tr>
</var:if>
<var:if condition="clientObject.hasAttachment">
<tr class="mailer_fieldrow">
<td class="mailer_fieldname"><img rsrc:src="title_attachment_14x14.png"/></td>
<td class="mailer_fieldvalue">
<a href="#" const:id="attachmentsHref"><var:string value="attachmentAttrs.count"/> <var:string value="attachmentsText"/></a>
</td>
</tr>
</var:if>
</table>
<div class="mailer_mailcontent">
<var:component value="contentViewerComponent"
bodyInfo="clientObject.bodyStructure" />
</div>
</span>
<var:component value="contentViewerComponent"
bodyInfo="clientObject.bodyStructure" />
</container>