aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2014-09-22 23:10:16 -0700
committerGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2014-09-22 23:10:16 -0700
commit7a77d98f7ee0cbb6c8d526290097b52003ea3484 (patch)
treefcdaa57784de88ca7c272fb0282cec091a689d4f /src
parentde2b44501bf3da0eed83905f44eed75059e9e401 (diff)
Generate message data for signature or encryption (never use 7bit or 8bit encoding)
Diffstat (limited to 'src')
-rw-r--r--src/core/rfc822/MCAttachment.cc3
-rw-r--r--src/core/rfc822/MCMessageBuilder.cc44
-rw-r--r--src/core/rfc822/MCMessageBuilder.h3
-rw-r--r--src/objc/rfc822/MCOMessageBuilder.h3
-rw-r--r--src/objc/rfc822/MCOMessageBuilder.mm5
5 files changed, 41 insertions, 17 deletions
diff --git a/src/core/rfc822/MCAttachment.cc b/src/core/rfc822/MCAttachment.cc
index eae40cb0..63551b6a 100644
--- a/src/core/rfc822/MCAttachment.cc
+++ b/src/core/rfc822/MCAttachment.cc
@@ -87,6 +87,9 @@ HashMap * Attachment::readMimeTypesFile(String * filename)
String * Attachment::mimeTypeForFilename(String * filename)
{
+ if (filename == NULL) {
+ return NULL;
+ }
static HashMap * mimeTypes = NULL;
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_lock(&lock);
diff --git a/src/core/rfc822/MCMessageBuilder.cc b/src/core/rfc822/MCMessageBuilder.cc
index 3e63ce4a..933a022b 100644
--- a/src/core/rfc822/MCMessageBuilder.cc
+++ b/src/core/rfc822/MCMessageBuilder.cc
@@ -177,15 +177,21 @@ static struct mailmime * get_text_part(const char * mime_type, const char * char
static struct mailmime * get_plain_text_part(const char * mime_type, const char * charset, const char * content_id,
const char * description,
- const char * text, size_t length, clist * contentTypeParameters)
+ const char * text, size_t length, clist * contentTypeParameters, bool forEncryption)
{
bool needsQuotedPrintable;
int mechanism;
needsQuotedPrintable = false;
- for(size_t i = 0 ; i < length ; i ++) {
- if ((text[i] & (1 << 7)) != 0) {
- needsQuotedPrintable = true;
+ if (forEncryption) {
+ needsQuotedPrintable = true;
+ }
+ if (!needsQuotedPrintable) {
+ for(size_t i = 0 ; i < length ; i ++) {
+ if ((text[i] & (1 << 7)) != 0) {
+ needsQuotedPrintable = true;
+ break;
+ }
}
}
@@ -272,7 +278,7 @@ static clist * content_type_parameters_from_attachment(Attachment * att)
return contentTypeParameters;
}
-static struct mailmime * mime_from_attachment(Attachment * att)
+static struct mailmime * mime_from_attachment(Attachment * att, bool forEncryption)
{
struct mailmime * mime;
Data * data;
@@ -295,7 +301,8 @@ static struct mailmime * mime_from_attachment(Attachment * att)
MCUTF8(att->contentID()),
MIME_ENCODED_STR(att->contentDescription()),
data->bytes(), data->length(),
- contentTypeParameters);
+ contentTypeParameters,
+ forEncryption);
}
else if (att->isInlineAttachment() && att->mimeType()->lowercaseString()->hasPrefix(MCSTR("text/"))) {
mime = get_other_text_part(MCUTF8(att->mimeType()), MCUTF8(att->charset()),
@@ -320,7 +327,7 @@ static struct mailmime * mime_from_attachment(Attachment * att)
}
static struct mailmime * multipart_related_from_attachments(Attachment * htmlAttachment,
- Array * attachments, const char * boundary_prefix)
+ Array * attachments, const char * boundary_prefix, bool forEncryption)
{
if ((attachments != NULL) && (attachments->count() > 0)) {
struct mailmime * submime;
@@ -328,14 +335,14 @@ static struct mailmime * multipart_related_from_attachments(Attachment * htmlAtt
mime = get_multipart_related(boundary_prefix);
- submime = mime_from_attachment(htmlAttachment);
+ submime = mime_from_attachment(htmlAttachment, forEncryption);
add_attachment(mime, submime, boundary_prefix);
for(unsigned int i = 0 ; i < attachments->count() ; i ++) {
Attachment * attachment;
attachment = (Attachment *) attachments->objectAtIndex(i);
- submime = mime_from_attachment(attachment);
+ submime = mime_from_attachment(attachment, forEncryption);
add_attachment(mime, submime, boundary_prefix);
}
@@ -344,7 +351,7 @@ static struct mailmime * multipart_related_from_attachments(Attachment * htmlAtt
else {
struct mailmime * mime;
- mime = mime_from_attachment(htmlAttachment);
+ mime = mime_from_attachment(htmlAttachment, forEncryption);
return mime;
}
@@ -655,7 +662,7 @@ String * MessageBuilder::boundaryPrefix()
return mBoundaryPrefix;
}
-Data * MessageBuilder::dataAndFilterBcc(bool filterBcc)
+Data * MessageBuilder::dataAndFilterBccAndForEncryption(bool filterBcc, bool forEncryption)
{
Data * data;
MMAPString * str;
@@ -676,20 +683,20 @@ Data * MessageBuilder::dataAndFilterBcc(bool filterBcc)
htmlAttachment = Attachment::attachmentWithHTMLString(htmlBody());
htmlPart = multipart_related_from_attachments(htmlAttachment, mRelatedAttachments,
- MCUTF8(mBoundaryPrefix));
+ MCUTF8(mBoundaryPrefix), forEncryption);
}
if (textBody() != NULL) {
Attachment * textAttachment;
textAttachment = Attachment::attachmentWithText(textBody());
- textPart = mime_from_attachment(textAttachment);
+ textPart = mime_from_attachment(textAttachment, forEncryption);
}
else if (htmlBody() != NULL) {
Attachment * textAttachment;
textAttachment = Attachment::attachmentWithText(htmlBody()->flattenHTML());
- textPart = mime_from_attachment(textAttachment);
+ textPart = mime_from_attachment(textAttachment, forEncryption);
}
if ((textPart != NULL) && (htmlPart != NULL)) {
@@ -724,7 +731,7 @@ Data * MessageBuilder::dataAndFilterBcc(bool filterBcc)
struct mailmime * submime;
attachment = (Attachment *) attachments()->objectAtIndex(i);
- submime = mime_from_attachment(attachment);
+ submime = mime_from_attachment(attachment, forEncryption);
add_attachment(mime, submime, MCUTF8(mBoundaryPrefix));
}
}
@@ -741,7 +748,12 @@ Data * MessageBuilder::dataAndFilterBcc(bool filterBcc)
Data * MessageBuilder::data()
{
- return dataAndFilterBcc(false);
+ return dataAndFilterBccAndForEncryption(false, false);
+}
+
+Data * MessageBuilder::dataForEncryption()
+{
+ return dataAndFilterBccAndForEncryption(false, true);
}
String * MessageBuilder::htmlRendering(HTMLRendererTemplateCallback * htmlCallback)
diff --git a/src/core/rfc822/MCMessageBuilder.h b/src/core/rfc822/MCMessageBuilder.h
index 413d1a4d..d3b32a4f 100644
--- a/src/core/rfc822/MCMessageBuilder.h
+++ b/src/core/rfc822/MCMessageBuilder.h
@@ -39,6 +39,7 @@ namespace mailcore {
virtual String * boundaryPrefix();
virtual Data * data();
+ virtual Data * dataForEncryption();
virtual String * htmlRendering(HTMLRendererTemplateCallback * htmlCallback = NULL);
virtual String * htmlBodyRendering();
@@ -58,7 +59,7 @@ namespace mailcore {
Array * /* Attachment */ mRelatedAttachments;
String * mBoundaryPrefix;
void init();
- Data * dataAndFilterBcc(bool filterBcc);
+ Data * dataAndFilterBccAndForEncryption(bool filterBcc, bool forEncryption);
};
};
diff --git a/src/objc/rfc822/MCOMessageBuilder.h b/src/objc/rfc822/MCOMessageBuilder.h
index a52afc0f..93e2a387 100644
--- a/src/objc/rfc822/MCOMessageBuilder.h
+++ b/src/objc/rfc822/MCOMessageBuilder.h
@@ -58,6 +58,9 @@
/** RFC 822 formatted message.*/
- (NSData *) data;
+/** RFC 822 formatted message for encryption.*/
+- (NSData *) dataForEncryption;
+
/** HTML rendering of the message to be displayed in a web view. The delegate can be nil.*/
- (NSString *) htmlRenderingWithDelegate:(id <MCOHTMLRendererDelegate>)delegate;
diff --git a/src/objc/rfc822/MCOMessageBuilder.mm b/src/objc/rfc822/MCOMessageBuilder.mm
index c884386f..023697e3 100644
--- a/src/objc/rfc822/MCOMessageBuilder.mm
+++ b/src/objc/rfc822/MCOMessageBuilder.mm
@@ -66,6 +66,11 @@ MCO_OBJC_SYNTHESIZE_STRING(setBoundaryPrefix, boundaryPrefix)
return MCO_OBJC_BRIDGE_GET(data);
}
+- (NSData *) dataForEncryption
+{
+ return MCO_OBJC_BRIDGE_GET(dataForEncryption);
+}
+
- (NSString *) htmlRenderingWithDelegate:(id <MCOHTMLRendererDelegate>)delegate
{
MCOAbstractMessageRendererCallback * htmlRenderCallback = new MCOAbstractMessageRendererCallback(self, delegate, NULL);