|
|
|
@@ -12,6 +12,8 @@
|
|
|
|
|
#include "delta-connection.h"
|
|
|
|
|
#include "libdelta.h"
|
|
|
|
|
|
|
|
|
|
#define IMEX_RECEIVED_MESSAGE "Setup message received. To apply it, reply with:\nIMEX: %d nnnn-nnnn-nnnn-nnnn-nnnn-nnnn-nnnn-nnnn-nnnn\nNo whitespace in the setup-code!"
|
|
|
|
|
|
|
|
|
|
void delta_recv_im(DeltaConnectionData *conn, uint32_t msg_id);
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
@@ -30,6 +32,8 @@ _transpose_config(dc_context_t *mailbox, PurpleAccount *acct)
|
|
|
|
|
const char *smtp_pass = purple_account_get_string(acct, PLUGIN_ACCOUNT_OPT_SMTP_PASS, NULL);
|
|
|
|
|
const char *smtp_port = purple_account_get_string(acct, PLUGIN_ACCOUNT_OPT_SMTP_SERVER_PORT, NULL);
|
|
|
|
|
|
|
|
|
|
gboolean bcc_self = purple_account_get_bool(acct, PLUGIN_ACCOUNT_OPT_BCC_SELF, FALSE);
|
|
|
|
|
|
|
|
|
|
dc_set_config(mailbox, PLUGIN_ACCOUNT_OPT_ADDR, addr);
|
|
|
|
|
dc_set_config(mailbox, PLUGIN_ACCOUNT_OPT_DISPLAY_NAME, display);
|
|
|
|
|
|
|
|
|
@@ -42,6 +46,12 @@ _transpose_config(dc_context_t *mailbox, PurpleAccount *acct)
|
|
|
|
|
dc_set_config(mailbox, PLUGIN_ACCOUNT_OPT_SMTP_USER, smtp_user);
|
|
|
|
|
dc_set_config(mailbox, PLUGIN_ACCOUNT_OPT_SMTP_PASS, smtp_pass);
|
|
|
|
|
dc_set_config(mailbox, PLUGIN_ACCOUNT_OPT_SMTP_SERVER_PORT, smtp_port);
|
|
|
|
|
|
|
|
|
|
if (bcc_self) {
|
|
|
|
|
dc_set_config(mailbox, PLUGIN_ACCOUNT_OPT_BCC_SELF, "1");
|
|
|
|
|
} else {
|
|
|
|
|
dc_set_config(mailbox, PLUGIN_ACCOUNT_OPT_BCC_SELF, "0");
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
@@ -141,8 +151,6 @@ delta_event_handler(void *context)
|
|
|
|
|
dc_event_emitter_t* emitter = dc_get_event_emitter(mailbox);
|
|
|
|
|
dc_event_t* event;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME: do we still need runthreads?
|
|
|
|
|
while (conn->runthreads && (event = dc_get_next_event(emitter)) != NULL) {
|
|
|
|
|
ProcessRequest *pr = NULL;
|
|
|
|
@@ -177,10 +185,20 @@ delta_event_handler(void *context)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case DC_EVENT_MSGS_CHANGED:
|
|
|
|
|
case DC_EVENT_MSGS_CHANGED: {
|
|
|
|
|
// This event may be issued for a single message, in which case the
|
|
|
|
|
// message ID is in data2 and we should treat it as an incoming msg
|
|
|
|
|
uint32_t msg_id = dc_event_get_data2_int(event);
|
|
|
|
|
pr = delta_build_process_request(conn);
|
|
|
|
|
purple_timeout_add(0, delta_process_fresh_messages, pr);
|
|
|
|
|
if (msg_id) {
|
|
|
|
|
// FIXME: they won't all be incoming. Some will be changed
|
|
|
|
|
pr->msg_id = msg_id;
|
|
|
|
|
purple_timeout_add(0, delta_process_incoming_message, pr);
|
|
|
|
|
} else {
|
|
|
|
|
purple_timeout_add(0, delta_process_fresh_messages, pr);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case DC_EVENT_INCOMING_MSG:
|
|
|
|
|
// data1 is chat_id, which we don't seem to need yet.
|
|
|
|
@@ -297,6 +315,25 @@ delta_connection_start_login(PurpleConnection *pc)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean delta_try_process_imex(dc_context_t *mailbox, char *text) {
|
|
|
|
|
if (!g_str_has_prefix(text, "IMEX: ")) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gchar **parts = g_strsplit(text, " ", 3);
|
|
|
|
|
if (g_strv_length(parts) != 3) {
|
|
|
|
|
g_strfreev(parts);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int msg_id = atoi(parts[1]);
|
|
|
|
|
gboolean success = dc_continue_key_transfer(mailbox, msg_id, parts[2]);
|
|
|
|
|
|
|
|
|
|
g_strfreev(parts);
|
|
|
|
|
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
delta_send_im(PurpleConnection *pc, const char *who, const char *message, PurpleMessageFlags flags)
|
|
|
|
|
{
|
|
|
|
@@ -373,7 +410,9 @@ next:
|
|
|
|
|
char *stripped_message = purple_markup_strip_html(message);
|
|
|
|
|
g_assert(stripped_message != NULL);
|
|
|
|
|
if (strlen(stripped_message) > 0) {
|
|
|
|
|
dc_send_text_msg(mailbox, chat_id, stripped_message);
|
|
|
|
|
if (!delta_try_process_imex(mailbox, stripped_message)) {
|
|
|
|
|
dc_send_text_msg(mailbox, chat_id, stripped_message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
g_free(stripped_message);
|
|
|
|
|
|
|
|
|
@@ -389,7 +428,7 @@ delta_recv_im(DeltaConnectionData *conn, uint32_t msg_id)
|
|
|
|
|
PurpleConnection *pc = conn->pc;
|
|
|
|
|
g_assert(pc != NULL);
|
|
|
|
|
|
|
|
|
|
dc_msg_t* msg = dc_get_msg(mailbox, msg_id);
|
|
|
|
|
dc_msg_t *msg = dc_get_msg(mailbox, msg_id);
|
|
|
|
|
int viewtype = dc_msg_get_viewtype(msg);
|
|
|
|
|
time_t timestamp = dc_msg_get_timestamp(msg);
|
|
|
|
|
char *text = dc_msg_get_text(msg);
|
|
|
|
@@ -404,9 +443,22 @@ delta_recv_im(DeltaConnectionData *conn, uint32_t msg_id)
|
|
|
|
|
char *who = dc_contact_get_addr(contact);
|
|
|
|
|
int flags = PURPLE_MESSAGE_RECV;
|
|
|
|
|
|
|
|
|
|
// FIXME: as a massive hack, convert IMEX setup messages into a text message
|
|
|
|
|
// prompting the user how to trigger the IMEX filter in outgoing messages.
|
|
|
|
|
if (dc_msg_is_setupmessage(msg)) {
|
|
|
|
|
purple_debug_info(PLUGIN_ID, "Receiving IMEX: ID=%d\n", msg_id);
|
|
|
|
|
viewtype = DC_MSG_TEXT;
|
|
|
|
|
g_free(text);
|
|
|
|
|
text = g_strndup("", 1024);
|
|
|
|
|
g_assert(text != NULL);
|
|
|
|
|
|
|
|
|
|
g_snprintf(text, 1024, IMEX_RECEIVED_MESSAGE, msg_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch(viewtype) {
|
|
|
|
|
case DC_MSG_GIF:
|
|
|
|
|
case DC_MSG_IMAGE:
|
|
|
|
|
case DC_MSG_STICKER:
|
|
|
|
|
flags = flags | PURPLE_MESSAGE_IMAGES;
|
|
|
|
|
break;
|
|
|
|
|
case DC_MSG_TEXT:
|
|
|
|
|