X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Finstmsg%2Fserv_instmsg.c;h=1bf8c728a9877ca1b6cd35fa7030b70214d73c39;hb=62235cdefb9170733cafb605f8bb5ec4d57ed1d1;hp=17ed7cc629830d372d2ffdc6230ede42ab34490a;hpb=4e9952daf6d736348f34fa1e02f33a568d25d894;p=citadel.git diff --git a/citadel/modules/instmsg/serv_instmsg.c b/citadel/modules/instmsg/serv_instmsg.c index 17ed7cc62..1bf8c728a 100644 --- a/citadel/modules/instmsg/serv_instmsg.c +++ b/citadel/modules/instmsg/serv_instmsg.c @@ -1,7 +1,7 @@ /* * This module handles instant messaging between users. * - * Copyright (c) 1987-2012 by the citadel.org team + * Copyright (c) 1987-2018 by the citadel.org team * * This program is open source software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3. @@ -11,6 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ + #include "sysdep.h" #include #include @@ -109,15 +110,9 @@ void log_instant_message(struct CitContext *me, struct CitContext *them, char *m this_im->conversation = NewStrBuf(); this_im->next = imlist; imlist = this_im; - StrBufAppendBufPlain(this_im->conversation, HKEY( - "Content-type: text/html\r\n" - "Content-transfer-encoding: 7bit\r\n" - "\r\n" - "\r\n" - ), 0); + StrBufAppendBufPlain(this_im->conversation, HKEY("\r\n"), 0); } - /* Since it's possible for this function to get called more than once if a user is logged * in on multiple sessions, we use the message's serial number to keep track of whether * we've already logged it. @@ -154,7 +149,6 @@ void delete_instant_messages(void) { } - /* * Retrieve instant messages */ @@ -177,7 +171,7 @@ void cmd_gexp(char *argbuf) { (long)ptr->timestamp, /* time sent */ ptr->flags, /* flags */ ptr->sender, /* sender of msg */ - config.c_nodename, /* static for now (and possibly deprecated) */ + CtdlGetConfigStr("c_nodename"), /* static for now (and possibly deprecated) */ ptr->sender_email /* email or jid of sender */ ); @@ -190,6 +184,7 @@ void cmd_gexp(char *argbuf) { free(ptr); } + /* * Asynchronously deliver instant messages */ @@ -204,6 +199,7 @@ void cmd_gexp_async(void) { cprintf("%d instant msg\n", ASYNC_MSG + ASYNC_GEXP); } + /* * Back end support function for send_instant_message() and company */ @@ -229,8 +225,6 @@ void add_xmsg_to_context(struct CitContext *ccptr, struct ExpressMessage *newmsg } - - /* * This is the back end to the instant message sending function. * Returns the number of users to which the message was sent. @@ -245,7 +239,7 @@ int send_instant_message(char *lun, char *lem, char *x_user, char *x_msg) int do_send = 0; /* 1 = send message; 0 = only check for valid recipient */ static int serial_number = 0; /* this keeps messages from getting logged twice */ - if (strlen(x_msg) > 0) { + if (!IsEmptyStr(x_msg)) { do_send = 1; } @@ -291,6 +285,7 @@ int send_instant_message(char *lun, char *lem, char *x_user, char *x_msg) return (message_sent); } + /* * send instant messages */ @@ -307,10 +302,12 @@ void cmd_sexp(char *argbuf) cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN); return; } - if (CC->fake_username[0]) + if (CC->fake_username[0]) { lun = CC->fake_username; - else + } + else { lun = CC->user.fullname; + } lem = CC->cs_inet_email; @@ -360,21 +357,24 @@ void cmd_sexp(char *argbuf) message_sent = PerformXmsgHooks(lun, lem, x_user, x_msg); if (message_sent > 0) { - if (!IsEmptyStr(x_msg)) + if (!IsEmptyStr(x_msg)) { cprintf("%d Message sent", CIT_OK); - else + } + else { cprintf("%d Ok to send message", CIT_OK); - if (message_sent > 1) + } + if (message_sent > 1) { cprintf(" to %d users", message_sent); + } cprintf(".\n"); } else { - if (CtdlGetUser(NULL, x_user)) - cprintf("%d '%s' does not exist.\n", - ERROR + NO_SUCH_USER, x_user); - else - cprintf("%d '%s' is not logged in " - "or is not accepting pages.\n", + if (CtdlGetUser(NULL, x_user)) { + cprintf("%d '%s' does not exist.\n", ERROR + NO_SUCH_USER, x_user); + } + else { + cprintf("%d '%s' is not logged in or is not accepting instant messages.\n", ERROR + RESOURCE_NOT_OPEN, x_user); + } } @@ -382,7 +382,6 @@ void cmd_sexp(char *argbuf) } - /* * Enter or exit paging-disabled mode */ @@ -446,6 +445,7 @@ void flush_individual_conversation(struct imlog *im) { struct CtdlMessage *msg; long msgnum = 0; char roomname[ROOMNAMELEN]; + StrBuf *MsgBuf, *FullMsgBuf; StrBufAppendBufPlain(im->conversation, HKEY( "\r\n" @@ -453,6 +453,19 @@ void flush_individual_conversation(struct imlog *im) { ), 0 ); + MsgBuf = StrBufRFC2047encodeMessage(im->conversation); + FlushStrBuf(im->conversation); + FullMsgBuf = NewStrBufPlain(NULL, StrLength(im->conversation) + 100); + + StrBufAppendBufPlain(FullMsgBuf, HKEY( + "Content-type: text/html; charset=UTF-8\r\n" + "Content-Transfer-Encoding: quoted-printable\r\n" + "\r\n" + ), 0 + ); + StrBufAppendBuf (FullMsgBuf, MsgBuf, 0); + FreeStrBuf(&MsgBuf); + msg = malloc(sizeof(struct CtdlMessage)); memset(msg, 0, sizeof(struct CtdlMessage)); msg->cm_magic = CTDLMESSAGE_MAGIC; @@ -468,8 +481,7 @@ void flush_individual_conversation(struct imlog *im) { } CM_SetField(msg, eOriginalRoom, HKEY(PAGELOGROOM)); - CM_SetField(msg, eNodeName, CFG_KEY(c_nodename)); - CM_SetAsFieldSB(msg, eMesageText, &im->conversation); /* we own this memory now */ + CM_SetAsFieldSB(msg, eMesageText, &FullMsgBuf); /* we own this memory now */ /* Start with usernums[1] because it's guaranteed to be higher than usernums[0], * so if there's only one party, usernums[0] will be zero but usernums[1] won't. @@ -493,9 +505,9 @@ void flush_individual_conversation(struct imlog *im) { } /* Finally, if we're logging instant messages globally, do that now. */ - if (!IsEmptyStr(config.c_logpages)) { - CtdlCreateRoom(config.c_logpages, 3, "", 0, 1, 1, VIEW_BBS); - CtdlSaveMsgPointerInRoom(config.c_logpages, msgnum, 0, NULL); + if (!IsEmptyStr(CtdlGetConfigStr("c_logpages"))) { + CtdlCreateRoom(CtdlGetConfigStr("c_logpages"), 3, "", 0, 1, 1, VIEW_BBS); + CtdlSaveMsgPointerInRoom(CtdlGetConfigStr("c_logpages"), msgnum, 0, NULL); } }