text
stringlengths
0
357
char* mime_in_reply_to = NULL;
char* mime_references = NULL;
carray* created_db_entries = carray_new(16);
int create_event_to_send = DC_EVENT_MSGS_CHANGED;
carray* rr_event_to_send = carray_new(16);
char* txt_raw = NULL;
dc_log_info(context, 0, "Receiving message %s/%lu...", server_folder? server_folder:"?", server_uid);
to_ids = dc_array_new(context, 16);
if (to_ids==NULL || created_db_entries==NULL || rr_event_to_send==NULL || mime_parser==NULL) {
dc_log_info(context, 0, "Bad param.");
goto cleanup;
}
/* parse the imf to mailimf_message {
mailimf_fields* msg_fields {
clist* fld_list; // list of mailimf_field
}
mailimf_body* msg_body { //!=NULL
const char * bd_text; //!=NULL
size_t bd_size;
}
};
normally, this is done by mailimf_message_parse(), however, as we also need the MIME data,
we use mailmime_parse() through dc_mimeparser (both call mailimf_struct_multiple_parse() somewhen, I did not found out anything
that speaks against this approach yet) */
dc_mimeparser_parse(mime_parser, imf_raw_not_terminated, imf_raw_bytes);
if (dc_hash_cnt(&mime_parser->header)==0) {
dc_log_info(context, 0, "No header.");
goto cleanup; /* Error - even adding an empty record won't help as we do not know the message ID */
}
/* messages without a Return-Path header typically are outgoing, however, if the Return-Path header
is missing for other reasons, see issue #150, foreign messages appear as own messages, this is very confusing.
as it may even be confusing when _own_ messages sent from other devices with other e-mail-adresses appear as being sent from SELF
we disabled this check for now */
#if 0
if (!dc_mimeparser_lookup_field(mime_parser, "Return-Path")) {
incoming = 0;
}
#endif
if ((field=dc_mimeparser_lookup_field(mime_parser, "Date"))!=NULL && field->fld_type==MAILIMF_FIELD_ORIG_DATE) {
struct mailimf_orig_date* orig_date = field->fld_data.fld_orig_date;
if (orig_date) {
sent_timestamp = dc_timestamp_from_date(orig_date->dt_date_time); // is not yet checked against bad times! we do this later if we have the database information.
}
}
dc_sqlite3_begin_transaction(context->sql);
transaction_pending = 1;
/* get From: and check if it is known (for known From:'s we add the other To:/Cc: in the 3rd pass)
or if From: is equal to SELF (in this case, it is any outgoing messages, we do not check Return-Path any more as this is unreliable, see issue #150 */
if ((field=dc_mimeparser_lookup_field(mime_parser, "From"))!=NULL
&& field->fld_type==MAILIMF_FIELD_FROM)
{
struct mailimf_from* fld_from = field->fld_data.fld_from;
if (fld_from)
{
int check_self;
dc_array_t* from_list = dc_array_new(context, 16);
dc_add_or_lookup_contacts_by_mailbox_list(context, fld_from->frm_mb_list, DC_ORIGIN_INCOMING_UNKNOWN_FROM, from_list, &check_self);
if (check_self)
{
incoming = 0;
if (dc_mimeparser_sender_equals_recipient(mime_parser))
{
from_id = DC_CONTACT_ID_SELF;
}
}
else
{
if (dc_array_get_cnt(from_list)>=1) /* if there is no from given, from_id stays 0 which is just fine. These messages are very rare, however, we have to add them to the database (they go to the "deaddrop" chat) to avoid a re-download from the server. See also [**] */
{
from_id = dc_array_get_id(from_list, 0);
incoming_origin = dc_get_contact_origin(context, from_id, &from_id_blocked);
}
}
dc_array_unref(from_list);
}
}
/* Make sure, to_ids starts with the first To:-address (Cc: is added in the loop below pass) */
if ((field=dc_mimeparser_lookup_field(mime_parser, "To"))!=NULL
&& field->fld_type==MAILIMF_FIELD_TO)
{
struct mailimf_to* fld_to = field->fld_data.fld_to; /* can be NULL */
if (fld_to)
{
dc_add_or_lookup_contacts_by_address_list(context, fld_to->to_addr_list /*!= NULL*/,
outgoing? DC_ORIGIN_OUTGOING_TO : (incoming_origin>=DC_ORIGIN_MIN_VERIFIED? DC_ORIGIN_INCOMING_TO : DC_ORIGIN_INCOMING_UNKNOWN_TO), to_ids, &to_self);
}
}