Accidentally merged the configdb branch into master. Reverting.
[citadel.git] / citadel / modules / instmsg / serv_instmsg.c
index 84acbc4f230931baacf74674a50bf825a34c731e..2c28600b665cc01d437439c6f5442499e46bfc20 100644 (file)
@@ -5,18 +5,11 @@
  *
  * 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.
- * 
- * 
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * 
- * 
- * 
- *
  */
 #include "sysdep.h"
 #include <stdlib.h>
 #include "config.h"
 #include "msgbase.h"
 #include "user_ops.h"
-
-#ifndef HAVE_SNPRINTF
-#include "snprintf.h"
-#endif
-
 #include "ctdl_module.h"
 
 struct imlog {
@@ -122,9 +110,6 @@ void log_instant_message(struct CitContext *me, struct CitContext *them, char *m
                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"
                        "<html><body>\r\n"
                        ), 0);
        }
@@ -458,6 +443,7 @@ void flush_individual_conversation(struct imlog *im) {
        struct CtdlMessage *msg;
        long msgnum = 0;
        char roomname[ROOMNAMELEN];
+       StrBuf *MsgBuf, *FullMsgBuf;
 
        StrBufAppendBufPlain(im->conversation, HKEY(
                "</body>\r\n"
@@ -465,22 +451,35 @@ 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;
        msg->cm_anon_type = MES_NORMAL;
        msg->cm_format_type = FMT_RFC822;
        if (!IsEmptyStr(im->usernames[0])) {
-               msg->cm_fields['A'] = strdup(im->usernames[0]);
+               CM_SetField(msg, eAuthor, im->usernames[0], strlen(im->usernames[0]));
        } else {
-               msg->cm_fields['A'] = strdup("Citadel");
+               CM_SetField(msg, eAuthor, HKEY("Citadel"));
        }
        if (!IsEmptyStr(im->usernames[1])) {
-               msg->cm_fields['R'] = strdup(im->usernames[1]);
+               CM_SetField(msg, eRecipient, im->usernames[1], strlen(im->usernames[1]));
        }
-       msg->cm_fields['O'] = strdup(PAGELOGROOM);
-       msg->cm_fields['N'] = strdup(NODENAME);
-       msg->cm_fields['M'] = SmashStrBuf(&im->conversation);   /* we own this memory now */
+
+       CM_SetField(msg, eOriginalRoom, HKEY(PAGELOGROOM));
+       CM_SetField(msg, eNodeName, CFG_KEY(c_nodename));
+       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.
@@ -494,7 +493,7 @@ void flush_individual_conversation(struct imlog *im) {
        snprintf(roomname, sizeof roomname, "%010ld.%s", im->usernums[1], PAGELOGROOM);
        CtdlCreateRoom(roomname, 5, "", 0, 1, 1, VIEW_BBS);
        msgnum = CtdlSubmitMsg(msg, NULL, roomname, 0);
-       CtdlFreeMessage(msg);
+       CM_Free(msg);
 
        /* If there is a valid user number in usernums[0], save a copy for them too. */
        if (im->usernums[0] > 0) {
@@ -599,11 +598,11 @@ CTDL_MODULE_INIT(instmsg)
                CtdlRegisterProtoHook(cmd_sexp, "SEXP", "Send an instant message");
                CtdlRegisterProtoHook(cmd_dexp, "DEXP", "Disable instant messages");
                CtdlRegisterProtoHook(cmd_reqt, "REQT", "Request client termination");
-               CtdlRegisterSessionHook(cmd_gexp_async, EVT_ASYNC);
-               CtdlRegisterSessionHook(delete_instant_messages, EVT_STOP);
+               CtdlRegisterSessionHook(cmd_gexp_async, EVT_ASYNC, PRIO_ASYNC + 1);
+               CtdlRegisterSessionHook(delete_instant_messages, EVT_STOP, PRIO_STOP + 1);
                CtdlRegisterXmsgHook(send_instant_message, XMSG_PRI_LOCAL);
-               CtdlRegisterSessionHook(instmsg_timer, EVT_TIMER);
-               CtdlRegisterSessionHook(instmsg_shutdown, EVT_SHUTDOWN);
+               CtdlRegisterSessionHook(instmsg_timer, EVT_TIMER, PRIO_CLEANUP + 400);
+               CtdlRegisterSessionHook(instmsg_shutdown, EVT_SHUTDOWN, PRIO_SHUTDOWN + 10);
        }
        
        /* return our module name for the log */