async_key_management
vb 8 years ago
parent dc6a525b9b
commit 22b75f37ee

@ -174,6 +174,40 @@ struct mailmime * get_text_part(
return mime;
}
struct mailmime * get_file_part(
const char * filename,
const char * mime_type,
char * data,
size_t length
)
{
char * disposition_name;
int encoding_type;
struct mailmime_disposition * disposition;
struct mailmime_mechanism * encoding;
struct mailmime_content * content;
struct mailmime * mime;
struct mailmime_fields * mime_fields;
disposition_name = NULL;
if (filename != NULL) {
disposition_name = strdup(filename);
}
disposition =
mailmime_disposition_new_with_data(MAILMIME_DISPOSITION_TYPE_ATTACHMENT,
disposition_name, NULL, NULL, NULL, (size_t) -1);
content = mailmime_content_new_with_str(mime_type);
encoding_type = MAILMIME_MECHANISM_BASE64;
encoding = mailmime_mechanism_new(encoding_type, NULL);
mime_fields = mailmime_fields_new_with_data(encoding,
NULL, NULL, disposition, NULL);
mime = part_new_empty(content, mime_fields, NULL, 1);
mailmime_set_body_text(mime, data, length);
return mime;
}
struct mailmime * part_multiple_new(
const char * type,
const char * boundary_prefix

@ -17,6 +17,13 @@ struct mailmime * get_text_part(
int encoding_type
);
struct mailmime * get_file_part(
const char * filename,
const char * mime_type,
char * data,
size_t length
);
struct mailmime * part_multiple_new(
const char * type,
const char * boundary_prefix

@ -12,11 +12,10 @@
DYNAMIC_API PEP_STATUS mime_encode_text(
const char *plaintext,
const char *htmltext,
bloblist_t *attachments,
char **resulttext
)
{
struct mailmime * msg_mime = NULL;
struct mailimf_fields * fields = NULL;
struct mailmime * mime = NULL;
struct mailmime * submime = NULL;
int col;
@ -32,18 +31,6 @@ DYNAMIC_API PEP_STATUS mime_encode_text(
*resulttext = NULL;
msg_mime = mailmime_new_message_data(NULL);
assert(msg_mime);
if (msg_mime == NULL)
goto enomem;
fields = mailimf_fields_new_empty();
assert(fields);
if (fields == NULL)
goto enomem;
mailmime_set_imf_fields(msg_mime, fields);
if (htmltext) {
mime = part_multiple_new("multipart/alternative", NULL);
assert(mime);
@ -53,15 +40,12 @@ DYNAMIC_API PEP_STATUS mime_encode_text(
submime = get_text_part("text/plain", plaintext, strlen(plaintext),
MAILMIME_MECHANISM_QUOTED_PRINTABLE);
assert(submime);
if (submime == NULL) {
mailmime_free(msg_mime);
if (submime == NULL)
goto enomem;
}
r = mailmime_smart_add_part(mime, submime);
assert(r == MAILIMF_NO_ERROR);
if (r == MAILIMF_ERROR_MEMORY) {
mailmime_free(msg_mime);
goto enomem;
}
else {
@ -72,17 +56,13 @@ DYNAMIC_API PEP_STATUS mime_encode_text(
submime = get_text_part("text/html", htmltext, strlen(htmltext),
MAILMIME_MECHANISM_QUOTED_PRINTABLE);
assert(submime);
if (submime == NULL) {
mailmime_free(msg_mime);
if (submime == NULL)
goto enomem;
}
r = mailmime_smart_add_part(mime, submime);
assert(r == MAILIMF_NO_ERROR);
if (r == MAILIMF_ERROR_MEMORY) {
mailmime_free(msg_mime);
if (r == MAILIMF_ERROR_MEMORY)
goto enomem;
}
else {
// mailmime_smart_add_part() takes ownership of submime
submime = NULL;
@ -92,18 +72,55 @@ DYNAMIC_API PEP_STATUS mime_encode_text(
mime = get_text_part("text/plain", plaintext, strlen(plaintext),
MAILMIME_MECHANISM_QUOTED_PRINTABLE);
assert(mime);
if (mime == NULL) {
mailmime_free(msg_mime);
if (mime == NULL)
goto enomem;
}
}
r = mailmime_add_part(msg_mime, mime);
assert(r == MAILIMF_NO_ERROR);
if (r == MAILIMF_ERROR_MEMORY) {
goto enomem;
if (attachments) {
submime = mime;
mime = part_multiple_new("multipart/mixed", NULL);
assert(mime);
if (mime == NULL)
goto enomem;
r = mailmime_smart_add_part(mime, submime);
assert(r == MAILIMF_NO_ERROR);
if (r == MAILIMF_ERROR_MEMORY) {
goto enomem;
}
else {
// mailmime_smart_add_part() takes ownership of submime
submime = NULL;
}
bloblist_t *_a;
for (_a = attachments; _a != NULL; _a = _a->next) {
char * mime_type;
assert(_a->data);
assert(_a->size);
if (_a->mime_type == NULL)
mime_type = "application/octet-stream";
else
mime_type = _a->mime_type;
submime = get_file_part(_a->file_name, mime_type, _a->data, _a->size);
assert(submime);
if (submime == NULL)
goto enomem;
r = mailmime_smart_add_part(mime, submime);
assert(r == MAILIMF_NO_ERROR);
if (r == MAILIMF_ERROR_MEMORY) {
goto enomem;
}
else {
// mailmime_smart_add_part() takes ownership of submime
submime = NULL;
}
}
}
// mailmime_add_part() takes ownership of mime
char *template = strdup("/tmp/pEp.XXXXXXXXXXXXXXXXXXXX");
assert(template);
@ -182,7 +199,7 @@ DYNAMIC_API PEP_STATUS mime_encode_text(
}
fclose(file);
mailmime_free(msg_mime);
mailmime_free(mime);
*resulttext = buf;
return PEP_STATUS_OK;
@ -206,10 +223,8 @@ release:
else if (fd != -1)
close(fd);
if (msg_mime)
mailmime_free(msg_mime);
if (fields)
mailimf_fields_free(fields);
if (mime)
mailmime_free(mime);
if (submime)
mailmime_free(submime);

@ -1,6 +1,6 @@
#pragma once
#include "pEpEngine.h"
#include "transport.h"
#ifdef __cplusplus
extern "C" {
@ -13,6 +13,7 @@ extern "C" {
// plaintext (in) plaintext of message as UTF-8 string
// htmltext (in) optional HTML version of message as UTF-8
// string or NULL if it does not apply
// attachments (in) attatchments or NULL if there are none
// resulttext (out) the resulting encoded text or NULL on any error
//
// return value:
@ -25,12 +26,13 @@ extern "C" {
// PEP_OUT_OF_MEMORY if not enough memory could be allocated
//
// caveat:
// the resulttext will go to the ownership of the caller; plaintext
// and htmltext will remain in the ownership of the caller
// the resulttext will go to the ownership of the caller; plaintext,
// htmltext and attachments will remain in the ownership of the caller
DYNAMIC_API PEP_STATUS mime_encode_text(
const char *plaintext,
const char *htmltext,
bloblist_t *attachments,
char **resulttext
);

@ -203,3 +203,4 @@ long random(void)
}
} // "C"

Loading…
Cancel
Save