mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 08:56:30 +03:00
Implement receiving mailing lists (#1964)
* Copypaste-merge my old work * Start implementing mailinglists the new way * Create pseudo contact * Fine-tune docs * Remove some unnecessary changes * style * Make a stock str * Fix a crash. Yes, this line caused a panic when reconfiguring on Android (without a reasonable error log). Also, I could not receive any messages anymore. * rfmt * Add tests and make them pass * Even more tests * rfmt * Enhance test and fix bug * Don't update the sender name when prefetching because maybe it's a mailing list * Use an enum instead of numbers for the decision * Don't remove anyone from mailing lists * Fix bug in the regex * Adjust error msg * Compile error after rebase * Correctly emit event * Add dc_msg_is_mailing_list so that you can find out whether messages in the deaddrop belong to mailing lists. * Add received headers to unit tests * Comments, small tweaks * Use dc_msg_get_override_sender_name instead of dc_msg_get_sender_name * Add dc_msg_get_sender_first_name() because sometimes the first name was not correctly shown in mailing lists * small fixes, don't let the user modify mailing list groups * Hide contacts for addresses like noreply@github.com and reply+AEJ...@reply.github.com When testing mailing lists, I noticed that sometimes a mailing list contact got a name (like, hocuri <noreply@github.com>). It turned out that ages ago, I had accidentally written an email to - in this example - hocuri <noreply@github.com> and it had been added to the contacts list. This hides email addresses from the contacts list that are obviously not meant to be written at and prevents updating the names. * Comment, clippy * Replace u32 with ChatId * Resolve lost of small issues from the reviews * remove dc_msg_get_sender_first_name * add dc_msg_get_real_chat_id() this allows to check if a contact request belongs to a mailing list and to show name/avatar/whatever of the mailinglist. another approach was to duplicate some chat-apis for messages (eg. dc_msg_is_mailing_list()) however that would require far more new apis. the idea to change the behavior of dc_msg_get_chat_id() would be more clean, however, that easily breaks existing implementations and can led to hard to find bugs. * remove now unused Message.is_mailing_list() * if a name for a mailing list is missing, use List-ID * fix comment * fix error message * document how dc_get_chat_contacts() works for mailing lists * refine decide api (#2185) * add DC_DECIDE* constants to deltachat.h, tweak documentation * use StartChat/Block/NotNow instead of Yes/Never/NotNow * decide_on_contact_request works on ctx/msg-id functions working on message-objects usually do not read or write directly on the database. therefore, decide_on_contact_request() should not work with message-objects as well, it is even a bit misleading, as eg. chat-id of the object is not modified. instead, the function works on context, similar to dc_send_msg(), dc_create_chat() and so on. for now, i moved it to context, could maybe be part od MsgId. * Update src/chatlist.rs Co-authored-by: Hocuri <hocuri@gmx.de> Co-authored-by: Hocuri <hocuri@gmx.de> * refine documentation * re-add accidentally deleted Param::MailingList * remove pseudo-contact in domain @mailing.list 1. the pseudo-contact was added to the mailing list contacts, which is not needed. might be that we want to add the recent contacts there in a subsequent pr (we do not know all contacts of a mailing list) 2. the pseudo-contact was used to block mailing lists; this is done by setting the chat to Blocked::Manually now 3- the pseudo-contact was used for unblocking; as it is very neat not to require additional ui for mailing list unblocking, might be that we introduce a similar pseudo-contact for this limited purpose in a subsequent pr, however, the pseudo-contact needs to exist only during unblocking then, maybe also the special domain is not needed, we'll see :) * Move dc_decide_on_contact_request() up to the dc_context section as it's a member of dc_context now More specifically, to the "handle messages" section * re-introduce Chattype::Mailinglist (#2195) * re-introduce Chattype::Mailinglist * exhaustive chattype-check in fetch_existing_msgs() and get_summary2() * exhaustive chattype-check in ndn_maybe_add_info_msg() * exhaustive chattype-check in message::fill() * remove dc_chat_is_mailing_list() from ffi Co-authored-by: B. Petersen <r10s@b44t.com>
This commit is contained in:
@@ -629,9 +629,8 @@ int dc_preconfigure_keypair (dc_context_t* context, const cha
|
||||
* messages from addresses that have no relationship to the configured account.
|
||||
* The last of these messages is represented by DC_CHAT_ID_DEADDROP and you can retrieve details
|
||||
* about it with dc_chatlist_get_msg_id(). Typically, the UI asks the user "Do you want to chat with NAME?"
|
||||
* and offers the options "Yes" (call dc_create_chat_by_msg_id()), "Never" (call dc_block_contact())
|
||||
* or "Not now".
|
||||
* The UI can also offer a "Close" button that calls dc_marknoticed_contact() then.
|
||||
* and offers the options "Start chat", "Block" or "Not now".
|
||||
* Call dc_decide_on_contact_request() when the user selected one of these options.
|
||||
* - DC_CHAT_ID_ARCHIVED_LINK (6) - this special chat is present if the user has
|
||||
* archived _any_ chat using dc_set_chat_visibility(). The UI should show a link as
|
||||
* "Show archived chats", if the user clicks this item, the UI should show a
|
||||
@@ -673,6 +672,8 @@ dc_chatlist_t* dc_get_chatlist (dc_context_t* context, int flags,
|
||||
// handle chats
|
||||
|
||||
/**
|
||||
* DEPRECATED Use dc_decide_on_contact_request().
|
||||
*
|
||||
* Create a normal chat or a group chat by a messages ID that comes typically
|
||||
* from the deaddrop, DC_CHAT_ID_DEADDROP (1).
|
||||
*
|
||||
@@ -692,6 +693,7 @@ dc_chatlist_t* dc_get_chatlist (dc_context_t* context, int flags,
|
||||
* same group may be shown or not - so, all in all, it is fine to show the
|
||||
* contact name only.
|
||||
*
|
||||
* @deprecated Use dc_decide_on_contact_request() instead
|
||||
* @memberof dc_context_t
|
||||
* @param context The context object as returned from dc_context_new().
|
||||
* @param msg_id The message ID to create the chat for.
|
||||
@@ -1087,7 +1089,7 @@ dc_array_t* dc_get_fresh_msgs (dc_context_t* context);
|
||||
* (IMAP/MDNs is not done for noticed messages).
|
||||
*
|
||||
* Calling this function usually results in the event #DC_EVENT_MSGS_NOTICED.
|
||||
* See also dc_marknoticed_contact() and dc_markseen_msgs().
|
||||
* See also dc_markseen_msgs().
|
||||
*
|
||||
* @memberof dc_context_t
|
||||
* @param context The context object as returned from dc_context_new().
|
||||
@@ -1213,6 +1215,11 @@ void dc_delete_chat (dc_context_t* context, uint32_t ch
|
||||
*
|
||||
* - for the deaddrop, the list is empty
|
||||
*
|
||||
* - for mailing lists, the behavior is not documented currently, we will decide on that later.
|
||||
* for now, the UI should not show the list for mailing lists.
|
||||
* (we do not know all members and there is not always a global mailing list address,
|
||||
* so we could return only SELF or the known members; this is not decided yet)
|
||||
*
|
||||
* @memberof dc_context_t
|
||||
* @param context The context object as returned from dc_context_new().
|
||||
* @param chat_id Chat ID to get the belonging contact IDs for.
|
||||
@@ -1540,6 +1547,8 @@ void dc_forward_msgs (dc_context_t* context, const uint3
|
||||
|
||||
|
||||
/**
|
||||
* DEPRECATED
|
||||
*
|
||||
* Mark all messages sent by the given contact as _noticed_.
|
||||
* This function is typically used to ignore a user in the deaddrop temporarily ("Not now" button).
|
||||
*
|
||||
@@ -1548,6 +1557,9 @@ void dc_forward_msgs (dc_context_t* context, const uint3
|
||||
*
|
||||
* See also dc_marknoticed_chat() and dc_markseen_msgs()
|
||||
*
|
||||
* @deprecated Use dc_decide_on_contact_request() if the user just hit "Not now" on a button in the deaddrop,
|
||||
* dc_marknoticed_chat() if the user has entered a chat
|
||||
* and dc_markseen_msgs() if the user actually _saw_ a message.
|
||||
* @memberof dc_context_t
|
||||
* @param context The context object.
|
||||
* @param contact_id The contact ID of which all messages should be marked as noticed.
|
||||
@@ -1559,7 +1571,7 @@ void dc_marknoticed_contact (dc_context_t* context, uint32_t co
|
||||
* Mark a message as _seen_, updates the IMAP state and
|
||||
* sends MDNs. If the message is not in a real chat (e.g. a contact request), the
|
||||
* message is only marked as NOTICED and no IMAP/MDNs is done. See also
|
||||
* dc_marknoticed_chat() and dc_marknoticed_contact()
|
||||
* dc_marknoticed_chat().
|
||||
*
|
||||
* Moreover, if messages belong to a chat with ephemeral messages enabled,
|
||||
* the ephemeral timer is started for these messages.
|
||||
@@ -1589,6 +1601,53 @@ void dc_markseen_msgs (dc_context_t* context, const uint3
|
||||
dc_msg_t* dc_get_msg (dc_context_t* context, uint32_t msg_id);
|
||||
|
||||
|
||||
#define DC_DECISION_START_CHAT 0
|
||||
#define DC_DECISION_BLOCK 1
|
||||
#define DC_DECISION_NOT_NOW 2
|
||||
|
||||
|
||||
/**
|
||||
* Call this when the user decided about a deaddrop message ("Do you want to chat with NAME?").
|
||||
*
|
||||
* Possible decisions are:
|
||||
* - DC_DECISION_START_CHAT (0)
|
||||
* - This will create a new chat and return the chat id.
|
||||
* - DC_DECISION_BLOCK (1)
|
||||
* - This will block the sender.
|
||||
* - When a new message from the sender arrives,
|
||||
* that will not result in a new contact request.
|
||||
* - The blocked sender will be returned by dc_get_blocked_contacts()
|
||||
* typically, the UI offers an option to unblock senders from there.
|
||||
* - DC_DECISION_NOT_NOW (2)
|
||||
* - This will mark all messages from this sender as noticed.
|
||||
* - That the contact request is removed from the chat list.
|
||||
* - When a new message from the sender arrives,
|
||||
* a new contact request with the new message will pop up in the chatlist.
|
||||
* - The contact request stays available in the explicit deaddrop.
|
||||
* - If the contact request is already noticed, nothing happens.
|
||||
*
|
||||
* If the message belongs to a mailing list,
|
||||
* the function makes sure that all messages
|
||||
* from the mailing list are blocked or marked as noticed.
|
||||
*
|
||||
* The user should be asked whether they want to chat with the _contact_ belonging to the message;
|
||||
* the group names may be really weird when taken from the subject of implicit (= ad-hoc)
|
||||
* groups and this may look confusing. Moreover, this function also scales up the origin of the contact.
|
||||
*
|
||||
* If the chat belongs to a mailing list, you can also ask
|
||||
* "Would you like to read MAILING LIST NAME?"
|
||||
* (use dc_msg_get_real_chat_id() to get the chat-id for the contact request
|
||||
* and then dc_chat_is_mailing_list(), dc_chat_get_name() and so on)
|
||||
*
|
||||
* @memberof dc_context_t
|
||||
* @param context The context object.
|
||||
* @param msg_id ID of Message to decide on.
|
||||
* @param decision One of the DC_DECISION_* values.
|
||||
* @return The chat id of the created chat, if any.
|
||||
*/
|
||||
uint32_t dc_decide_on_contact_request (dc_context_t* context, uint32_t msg_id, int decision);
|
||||
|
||||
|
||||
// handle contacts
|
||||
|
||||
/**
|
||||
@@ -2818,6 +2877,7 @@ char* dc_chat_get_info_json (dc_context_t* context, size_t chat
|
||||
#define DC_CHAT_TYPE_UNDEFINED 0
|
||||
#define DC_CHAT_TYPE_SINGLE 100
|
||||
#define DC_CHAT_TYPE_GROUP 120
|
||||
#define DC_CHAT_TYPE_MAILINGLIST 140
|
||||
|
||||
|
||||
/**
|
||||
@@ -2858,6 +2918,11 @@ uint32_t dc_chat_get_id (const dc_chat_t* chat);
|
||||
* - DC_CHAT_TYPE_GROUP (120) - a group chat, chats_contacts contain all group
|
||||
* members, incl. DC_CONTACT_ID_SELF
|
||||
*
|
||||
* - DC_CHAT_TYPE_MAILINGLIST (140) - a mailing list, this is similar to groups,
|
||||
* however, the member list cannot be retrieved completely
|
||||
* and cannot be changed using this api.
|
||||
* moreover, for now, mailist lists are read-only.
|
||||
*
|
||||
* @memberof dc_chat_t
|
||||
* @param chat The chat object.
|
||||
* @return Chat type.
|
||||
@@ -3120,6 +3185,7 @@ uint32_t dc_msg_get_from_id (const dc_msg_t* msg);
|
||||
* To get details about the chat, pass the returned ID to dc_get_chat().
|
||||
* If a message is still in the deaddrop, the ID DC_CHAT_ID_DEADDROP is returned
|
||||
* although internally another ID is used.
|
||||
* (to get that internal id, use dc_msg_get_real_chat_id())
|
||||
*
|
||||
* @memberof dc_msg_t
|
||||
* @param msg The message object.
|
||||
@@ -3128,6 +3194,19 @@ uint32_t dc_msg_get_from_id (const dc_msg_t* msg);
|
||||
uint32_t dc_msg_get_chat_id (const dc_msg_t* msg);
|
||||
|
||||
|
||||
/**
|
||||
* Get the ID of chat the message belongs to.
|
||||
* To get details about the chat, pass the returned ID to dc_get_chat().
|
||||
* In contrast to dc_msg_get_chat_id(), this function returns the chat-id also
|
||||
* for messages in the deaddrop.
|
||||
*
|
||||
* @memberof dc_msg_t
|
||||
* @param msg The message object.
|
||||
* @return The ID of the chat the message belongs to, 0 on errors.
|
||||
*/
|
||||
uint32_t dc_msg_get_real_chat_id (const dc_msg_t* msg);
|
||||
|
||||
|
||||
/**
|
||||
* Get the type of the message.
|
||||
*
|
||||
@@ -3144,7 +3223,7 @@ int dc_msg_get_viewtype (const dc_msg_t* msg);
|
||||
*
|
||||
* Incoming message states:
|
||||
* - DC_STATE_IN_FRESH (10) - Incoming _fresh_ message. Fresh messages are neither noticed nor seen and are typically shown in notifications. Use dc_get_fresh_msgs() to get all fresh messages.
|
||||
* - DC_STATE_IN_NOTICED (13) - Incoming _noticed_ message. E.g. chat opened but message not yet read - noticed messages are not counted as unread but did not marked as read nor resulted in MDNs. Use dc_marknoticed_chat() or dc_marknoticed_contact() to mark messages as being noticed.
|
||||
* - DC_STATE_IN_NOTICED (13) - Incoming _noticed_ message. E.g. chat opened but message not yet read - noticed messages are not counted as unread but were not marked as read nor resulted in MDNs. Use dc_marknoticed_chat() to mark messages as being noticed.
|
||||
* - DC_STATE_IN_SEEN (16) - Incoming message, really _seen_ by the user. Marked as read on IMAP and MDN may be sent. Use dc_markseen_msgs() to mark messages as being seen.
|
||||
*
|
||||
* Outgoing message states:
|
||||
@@ -3426,6 +3505,24 @@ dc_lot_t* dc_msg_get_summary (const dc_msg_t* msg, const dc_cha
|
||||
char* dc_msg_get_summarytext (const dc_msg_t* msg, int approx_characters);
|
||||
|
||||
|
||||
/**
|
||||
* Get the name that should be shown over the message (in a group chat) instead of the contact
|
||||
* display name.
|
||||
*
|
||||
* In mailing lists, sender display name and sender address do not always belong together.
|
||||
* In this case, this function gives you the name that should actually be shown over the message.
|
||||
*
|
||||
* @memberof dc_msg_t
|
||||
* @param msg The message object.
|
||||
* @return the name to show over this message or NULL.
|
||||
* If this returns NULL, call `dc_contact_get_display_name()`.
|
||||
* The returned string must be released using dc_str_unref().
|
||||
* Returns an empty string on errors, never returns NULL.
|
||||
*/
|
||||
char* dc_msg_get_override_sender_name(const dc_msg_t* msg);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Check if a message has a deviating timestamp.
|
||||
* A message has a deviating timestamp
|
||||
@@ -3595,7 +3692,8 @@ char* dc_msg_get_setupcodebegin (const dc_msg_t* msg);
|
||||
* If the message is no videochat invitation, NULL is returned.
|
||||
* Must be released using dc_str_unref() when done.
|
||||
*/
|
||||
char* dc_msg_get_videochat_url (const dc_msg_t* msg);
|
||||
char* dc_msg_get_videochat_url (const dc_msg_t* msg);
|
||||
|
||||
|
||||
/**
|
||||
* Gets the error status of the message.
|
||||
@@ -3938,6 +4036,9 @@ char* dc_contact_get_name (const dc_contact_t* contact);
|
||||
* This name is typically used in lists.
|
||||
* To get the name editable in a formular, use dc_contact_get_name().
|
||||
*
|
||||
* In a group, you should show the sender's name over a message. To get it, call dc_msg_get_override_sender_name()
|
||||
* first and if it returns NULL, call dc_contact_get_display_name().
|
||||
*
|
||||
* @memberof dc_contact_t
|
||||
* @param contact The contact object.
|
||||
* @return String with the name to display, must be released using dc_str_unref().
|
||||
@@ -4741,7 +4842,7 @@ void dc_event_unref(dc_event_t* event);
|
||||
* Messages were marked noticed or seen.
|
||||
* The UI may update badge counters or stop showing a chatlist-item with a bold font.
|
||||
*
|
||||
* This event is emitted e.g. when calling dc_markseen_msgs(), dc_marknoticed_chat() or dc_marknoticed_contact()
|
||||
* This event is emitted e.g. when calling dc_markseen_msgs() or dc_marknoticed_chat()
|
||||
* or when a chat is answered on another device.
|
||||
* Do not try to derive the state of an item from just the fact you received the event;
|
||||
* use e.g. dc_msg_get_state() or dc_get_fresh_msg_cnt() for this purpose.
|
||||
|
||||
@@ -2591,6 +2591,16 @@ pub unsafe extern "C" fn dc_msg_get_chat_id(msg: *mut dc_msg_t) -> u32 {
|
||||
ffi_msg.message.get_chat_id().to_u32()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_msg_get_real_chat_id(msg: *mut dc_msg_t) -> u32 {
|
||||
if msg.is_null() {
|
||||
eprintln!("ignoring careless call to dc_msg_get_real_chat_id()");
|
||||
return 0;
|
||||
}
|
||||
let ffi_msg = &*msg;
|
||||
ffi_msg.message.get_real_chat_id().to_u32()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_msg_get_viewtype(msg: *mut dc_msg_t) -> libc::c_int {
|
||||
if msg.is_null() {
|
||||
@@ -2810,6 +2820,17 @@ pub unsafe extern "C" fn dc_msg_get_summarytext(
|
||||
.strdup()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_msg_get_override_sender_name(msg: *mut dc_msg_t) -> *mut libc::c_char {
|
||||
if msg.is_null() {
|
||||
eprintln!("ignoring careless call to dc_msg_get_override_sender_name()");
|
||||
return "".strdup();
|
||||
}
|
||||
let ffi_msg = &mut *msg;
|
||||
|
||||
ffi_msg.message.get_override_sender_name().strdup()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_msg_has_deviating_timestamp(msg: *mut dc_msg_t) -> libc::c_int {
|
||||
if msg.is_null() {
|
||||
@@ -2915,6 +2936,32 @@ pub unsafe extern "C" fn dc_msg_get_videochat_url(msg: *mut dc_msg_t) -> *mut li
|
||||
.strdup()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_decide_on_contact_request(
|
||||
context: *mut dc_context_t,
|
||||
msg_id: u32,
|
||||
decision: libc::c_int,
|
||||
) -> u32 {
|
||||
if context.is_null() || msg_id <= constants::DC_MSG_ID_LAST_SPECIAL as u32 {
|
||||
eprintln!("ignoring careless call to dc_decide_on_contact_request()");
|
||||
}
|
||||
let ctx = &*context;
|
||||
|
||||
match from_prim(decision) {
|
||||
None => {
|
||||
warn!(ctx, "{} is not a valid decision, ignoring", decision);
|
||||
0
|
||||
}
|
||||
Some(d) => block_on(message::decide_on_contact_request(
|
||||
ctx,
|
||||
MsgId::new(msg_id),
|
||||
d,
|
||||
))
|
||||
.unwrap_or_default()
|
||||
.to_u32(),
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_msg_get_videochat_type(msg: *mut dc_msg_t) -> libc::c_int {
|
||||
if msg.is_null() {
|
||||
|
||||
Reference in New Issue
Block a user