Mailer: replace HTML view by JSON object
parent
bd9da51e83
commit
277bdd2b1c
|
@ -22,6 +22,8 @@
|
||||||
|
|
||||||
#import <Foundation/NSDictionary.h>
|
#import <Foundation/NSDictionary.h>
|
||||||
#import <Foundation/NSException.h>
|
#import <Foundation/NSException.h>
|
||||||
|
#import <Foundation/NSValue.h>
|
||||||
|
|
||||||
#import <NGObjWeb/NSException+HTTP.h>
|
#import <NGObjWeb/NSException+HTTP.h>
|
||||||
#import <NGObjWeb/WORequest.h>
|
#import <NGObjWeb/WORequest.h>
|
||||||
#import <NGObjWeb/WOResponse.h>
|
#import <NGObjWeb/WOResponse.h>
|
||||||
|
@ -41,6 +43,7 @@
|
||||||
#import <NGImap4/NGImap4Envelope.h>
|
#import <NGImap4/NGImap4Envelope.h>
|
||||||
#import <NGImap4/NGImap4EnvelopeAddress.h>
|
#import <NGImap4/NGImap4EnvelopeAddress.h>
|
||||||
|
|
||||||
|
#import <SOGo/NSDictionary+Utilities.h>
|
||||||
#import <SOGo/NSString+Utilities.h>
|
#import <SOGo/NSString+Utilities.h>
|
||||||
#import <SOGo/SOGoBuild.h>
|
#import <SOGo/SOGoBuild.h>
|
||||||
#import <SOGo/SOGoMailer.h>
|
#import <SOGo/SOGoMailer.h>
|
||||||
|
@ -59,12 +62,17 @@
|
||||||
@interface UIxMailView : UIxComponent
|
@interface UIxMailView : UIxComponent
|
||||||
{
|
{
|
||||||
id currentAddress;
|
id currentAddress;
|
||||||
NSString *shouldAskReceipt;
|
NSNumber *shouldAskReceipt;
|
||||||
NSString *matchingIdentityEMail;
|
NSString *matchingIdentityEMail;
|
||||||
NSDictionary *attachment;
|
NSDictionary *attachment;
|
||||||
NSArray *attachmentAttrs;
|
NSArray *attachmentAttrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL) mailIsDraft;
|
||||||
|
- (NSNumber *) shouldAskReceipt;
|
||||||
|
- (NSArray *) formattedAddresses: (NSArray *) theAddresses;
|
||||||
|
- (NSString *) formattedDate;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation UIxMailView
|
@implementation UIxMailView
|
||||||
|
@ -183,6 +191,34 @@ static NSString *mailETag = nil;
|
||||||
return [UIxMailSizeFormatter sharedMailSizeFormatter];
|
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
|
- (NSString *) attachmentsText
|
||||||
{
|
{
|
||||||
if ([[self attachmentAttrs] count] > 1)
|
if ([[self attachmentAttrs] count] > 1)
|
||||||
|
@ -206,10 +242,14 @@ static NSString *mailETag = nil;
|
||||||
|
|
||||||
/* actions */
|
/* actions */
|
||||||
|
|
||||||
- (id) defaultAction
|
- (id <WOActionResults>) defaultAction
|
||||||
{
|
{
|
||||||
WOResponse *response;
|
id <WOActionResults> response;
|
||||||
NSString *s;
|
NSString *s;
|
||||||
|
NSDictionary *data;
|
||||||
|
SOGoMailObject *co;
|
||||||
|
|
||||||
|
co = [self clientObject];
|
||||||
|
|
||||||
/* check etag to see whether we really must rerender */
|
/* check etag to see whether we really must rerender */
|
||||||
/*
|
/*
|
||||||
|
@ -226,23 +266,46 @@ static NSString *mailETag = nil;
|
||||||
/* client already has the proper entity */
|
/* client already has the proper entity */
|
||||||
// [self logWithFormat:@"MATCH: %@ (tag %@)", s, mailETag];
|
// [self logWithFormat:@"MATCH: %@ (tag %@)", s, mailETag];
|
||||||
|
|
||||||
if (![[self clientObject] doesMailExist]) {
|
if (![co doesMailExist])
|
||||||
return [NSException exceptionWithHTTPStatus:404 /* Not Found */
|
{
|
||||||
reason:@"message got deleted"];
|
data = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||||
}
|
@"message got deleted", @"error",
|
||||||
|
nil];
|
||||||
|
return [self responseWithStatus: 404 /* Not Found */
|
||||||
|
andString: [data jsonRepresentation]];
|
||||||
|
}
|
||||||
|
|
||||||
response = [context response];
|
response = [self responseWithStatus: 304];
|
||||||
[response setStatus: 304 /* Not Modified */];
|
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (![self message]) // TODO: redirect to proper error
|
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 */
|
/* MDN */
|
||||||
|
@ -549,7 +612,7 @@ static NSString *mailETag = nil;
|
||||||
[self _flagMessageWithMDNSent];
|
[self _flagMessageWithMDNSent];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *) shouldAskReceipt
|
- (NSNumber *) shouldAskReceipt
|
||||||
{
|
{
|
||||||
NGMailAddress *mailAddress;
|
NGMailAddress *mailAddress;
|
||||||
NSDictionary *mailHeaders;
|
NSDictionary *mailHeaders;
|
||||||
|
@ -557,7 +620,7 @@ static NSString *mailETag = nil;
|
||||||
|
|
||||||
if (!shouldAskReceipt)
|
if (!shouldAskReceipt)
|
||||||
{
|
{
|
||||||
shouldAskReceipt = @"false";
|
shouldAskReceipt = [NSNumber numberWithBool: NO];
|
||||||
mailHeaders = [[self clientObject] mailHeaders];
|
mailHeaders = [[self clientObject] mailHeaders];
|
||||||
email = [mailHeaders objectForKey: @"disposition-notification-to"];
|
email = [mailHeaders objectForKey: @"disposition-notification-to"];
|
||||||
if (!email)
|
if (!email)
|
||||||
|
@ -584,7 +647,7 @@ static NSString *mailETag = nil;
|
||||||
action = [self _receiptAction];
|
action = [self _receiptAction];
|
||||||
if ([action isEqualToString: @"ask"])
|
if ([action isEqualToString: @"ask"])
|
||||||
{
|
{
|
||||||
shouldAskReceipt = @"true";
|
shouldAskReceipt = [NSNumber numberWithBool: YES];
|
||||||
[self _flagMessageWithMDNSent];
|
[self _flagMessageWithMDNSent];
|
||||||
}
|
}
|
||||||
else if ([action isEqualToString: @"send"])
|
else if ([action isEqualToString: @"send"])
|
||||||
|
|
|
@ -2,123 +2,8 @@
|
||||||
<container xmlns="http://www.w3.org/1999/xhtml"
|
<container xmlns="http://www.w3.org/1999/xhtml"
|
||||||
xmlns:var="http://www.skyrix.com/od/binding"
|
xmlns:var="http://www.skyrix.com/od/binding"
|
||||||
xmlns:const="http://www.skyrix.com/od/constant"
|
xmlns:const="http://www.skyrix.com/od/constant"
|
||||||
xmlns:uix="OGo:uix"
|
|
||||||
xmlns:rsrc="OGo:url"
|
xmlns:rsrc="OGo:url"
|
||||||
xmlns:label="OGo:label">
|
xmlns:label="OGo:label">
|
||||||
<var:if condition="clientObject.hasAttachment">
|
<var:component value="contentViewerComponent"
|
||||||
<div class="menu" const:id="attachmentsMenu">
|
bodyInfo="clientObject.bodyStructure" />
|
||||||
<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>
|
|
||||||
</container>
|
</container>
|
||||||
|
|
Loading…
Reference in New Issue