text
stringlengths
0
357
/*******************************************************************************
* Render
******************************************************************************/
static int is_file_size_okay(const dc_msg_t* msg)
{
int file_size_okay = 1;
char* pathNfilename = dc_param_get(msg->param, DC_PARAM_FILE, NULL);
uint64_t bytes = dc_get_filebytes(msg->context, pathNfilename);
if (bytes>DC_MSGSIZE_UPPER_LIMIT) {
file_size_okay = 0;
}
free(pathNfilename);
return file_size_okay;
}
static struct mailmime* build_body_text(char* text)
{
struct mailmime_fields* mime_fields = NULL;
struct mailmime* message_part = NULL;
struct mailmime_content* content = NULL;
content = mailmime_content_new_with_str("text/plain");
clist_append(content->ct_parameters, mailmime_param_new_with_data("charset", "utf-8")); /* format=flowed currently does not really affect us, see https://www.ietf.org/rfc/rfc3676.txt */
mime_fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT);
message_part = mailmime_new_empty(content, mime_fields);
mailmime_set_body_text(message_part, text, strlen(text));
return message_part;
}
static struct mailmime* build_body_file(const dc_msg_t* msg, const char* base_name, char** ret_file_name_as_sent)
{
struct mailmime_fields* mime_fields = NULL;
struct mailmime* mime_sub = NULL;
struct mailmime_content* content = NULL;
char* pathNfilename = dc_param_get(msg->param, DC_PARAM_FILE, NULL);
char* mimetype = dc_param_get(msg->param, DC_PARAM_MIMETYPE, NULL);
char* suffix = dc_get_filesuffix_lc(pathNfilename);
char* filename_to_send = NULL;
char* filename_encoded = NULL;
if (pathNfilename==NULL) {
goto cleanup;
}
/* get file name to use for sending (for privacy purposes, we do not transfer the original filenames eg. for images; these names are normally not needed and contain timesamps, running numbers etc.) */
if (msg->type==DC_MSG_VOICE) {
struct tm wanted_struct;
memcpy(&wanted_struct, localtime(&msg->timestamp_sort), sizeof(struct tm));
filename_to_send = dc_mprintf("voice-message_%04i-%02i-%02i_%02i-%02i-%02i.%s",
(int)wanted_struct.tm_year+1900, (int)wanted_struct.tm_mon+1, (int)wanted_struct.tm_mday,
(int)wanted_struct.tm_hour, (int)wanted_struct.tm_min, (int)wanted_struct.tm_sec,
suffix? suffix : "dat");
}
else if (msg->type==DC_MSG_AUDIO) {
filename_to_send = dc_get_filename(pathNfilename);
}
else if (msg->type==DC_MSG_IMAGE || msg->type==DC_MSG_GIF) {
if (base_name==NULL) {
base_name = "image";
}
filename_to_send = dc_mprintf("%s.%s", base_name, suffix? suffix : "dat");
}
else if (msg->type==DC_MSG_VIDEO) {
filename_to_send = dc_mprintf("video.%s", suffix? suffix : "dat");
}
else {
filename_to_send = dc_get_filename(pathNfilename);
}
/* check mimetype */
if (mimetype==NULL) {
if (suffix==NULL) {
mimetype = dc_strdup("application/octet-stream");
}
else if (strcmp(suffix, "png")==0) {
mimetype = dc_strdup("image/png");
}
else if (strcmp(suffix, "jpg")==0 || strcmp(suffix, "jpeg")==0 || strcmp(suffix, "jpe")==0) {
mimetype = dc_strdup("image/jpeg");
}
else if (strcmp(suffix, "gif")==0) {
mimetype = dc_strdup("image/gif");
}
else {
mimetype = dc_strdup("application/octet-stream");
}
}