aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/smtp/MCSMTPSession.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/smtp/MCSMTPSession.cpp')
-rw-r--r--src/core/smtp/MCSMTPSession.cpp51
1 files changed, 39 insertions, 12 deletions
diff --git a/src/core/smtp/MCSMTPSession.cpp b/src/core/smtp/MCSMTPSession.cpp
index d0711c65..8bcaefff 100644
--- a/src/core/smtp/MCSMTPSession.cpp
+++ b/src/core/smtp/MCSMTPSession.cpp
@@ -617,7 +617,7 @@ void SMTPSession::sendMessage(Address * from, Array * recipients, Data * message
}
messageData = dataWithFilteredBcc(messageData);
-
+
mProgressCallback = callback;
bodyProgress(0, messageData->length());
@@ -717,13 +717,28 @@ void SMTPSession::sendMessage(Address * from, Array * recipients, Data * message
mProgressCallback = NULL;
}
+void SMTPSession::sendMessage(Address * from, Array * recipients, String * messagePath,
+ SMTPProgressCallback * callback, ErrorCode * pError)
+{
+ Data * messageData = Data::dataWithContentsOfFile(messagePath);
+ if (!messageData) {
+ * pError = ErrorFile;
+ return;
+ }
+
+ return sendMessage(from, recipients, messageData, callback, pError);
+}
+
+static void mmapStringDeallocator(char * bytes, unsigned int length) {
+ mmap_string_unref(bytes);
+}
+
Data * SMTPSession::dataWithFilteredBcc(Data * data)
{
int r;
size_t idx;
struct mailimf_message * msg;
- MMAPString * str;
-
+
idx = 0;
r = mailimf_message_parse(data->bytes(), data->length(), &idx, &msg);
if (r != MAILIMF_NO_ERROR) {
@@ -734,15 +749,16 @@ Data * SMTPSession::dataWithFilteredBcc(Data * data)
int col = 0;
int hasRecipient = 0;
- str = mmap_string_new("");
+ bool bccWasActuallyRemoved = false;
for(clistiter * cur = clist_begin(fields->fld_list) ; cur != NULL ; cur = clist_next(cur)) {
struct mailimf_field * field = (struct mailimf_field *) clist_content(cur);
if (field->fld_type == MAILIMF_FIELD_BCC) {
mailimf_field_free(field);
clist_delete(fields->fld_list, cur);
+ bccWasActuallyRemoved = true;
break;
}
- else if ((field->fld_type == MAILIMF_FIELD_TO) || (field->fld_type == MAILIMF_FIELD_CC) || (field->fld_type == MAILIMF_FIELD_BCC)) {
+ else if ((field->fld_type == MAILIMF_FIELD_TO) || (field->fld_type == MAILIMF_FIELD_CC)) {
hasRecipient = 1;
}
}
@@ -754,13 +770,24 @@ Data * SMTPSession::dataWithFilteredBcc(Data * data)
struct mailimf_field * field = mailimf_field_new(MAILIMF_FIELD_TO, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, toField, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
mailimf_fields_add(fields, field);
}
- mailimf_fields_write_mem(str, &col, fields);
- mmap_string_append(str, "\n");
- mmap_string_append_len(str, msg->msg_body->bd_text, msg->msg_body->bd_size);
-
- Data * result = Data::dataWithBytes(str->str, (unsigned int) str->len);
-
- mmap_string_free(str);
+
+ Data * result;
+ if (!hasRecipient || bccWasActuallyRemoved) {
+ MMAPString * str = mmap_string_new("");
+ mailimf_fields_write_mem(str, &col, fields);
+ mmap_string_append(str, "\n");
+ mmap_string_append_len(str, msg->msg_body->bd_text, msg->msg_body->bd_size);
+
+ mmap_string_ref(str);
+
+ result = Data::data();
+ result->takeBytesOwnership(str->str, (unsigned int) str->len, mmapStringDeallocator);
+ }
+ else {
+ // filter Bcc and modify To: only if necessary.
+ result = data;
+ }
+
mailimf_message_free(msg);
return result;