]> jfr.im git - irc/evilnet/x3.git/blobdiff - src/mod-memoserv.c
Added 3 new hooks available for python scripts: new_user, nick_change, and server_link
[irc/evilnet/x3.git] / src / mod-memoserv.c
index ce3542b155b38c393e484464e77e5d53649ab827..58d1c01c4749266cb6ed8506417a7f8b1e9be4c9 100644 (file)
@@ -44,6 +44,7 @@
 #include "nickserv.h"
 #include "opserv.h"
 #include "saxdb.h"
+#include "sendmail.h"
 #include "timeq.h"
 
 #define KEY_MAIN_ACCOUNTS "accounts"
@@ -56,7 +57,6 @@
 #define KEY_RECIPIENT "to"
 #define KEY_FROM "from"
 #define KEY_MESSAGE "msg"
-#undef KEY_READ /* thanks microsoft! */
 #define KEY_READ "read"
 #define KEY_RECIEPT "reciept"
 #define KEY_ID "id"
@@ -112,6 +112,9 @@ static const struct message_entry msgtab[] = {
     { "MSMSG_LIST_END",        "--------------End of Memos--------------" },
     { "MSMSG_BAR",             "----------------------------------------"},
 
+    { "MSEMAIL_NEWMEMO_SUBJECT", "New %s %s message from %s" },
+    { "MSEMAIL_NEWMEMO_BODY", "This email has been sent to let you know that %s has sent you a message via %s.\n\n  The message is: %s.\n\nTo delete this message just type in /msg %s delete %d when on %s next." },
+
     { "MSMSG_DEFCON_NO_NEW_MEMOS", "You cannot send new memos at this time, please try again soon." },
 
     { NULL, NULL }
@@ -401,10 +404,13 @@ static struct memo *find_memo(struct userNode *user, struct svccmd *cmd, struct
 static MODCMD_FUNC(cmd_send)
 {
     char *message;
-    int reciept = 0, inc = 2;
+    int reciept = 0, inc = 2, email = 0;
     struct handle_info *hi;
     struct memo_account *ma, *sender;
     struct memo *memo;
+    char subject[128], body[4096];
+    char *estr;
+    const char *netname, *fmt;
 
     MEMOSERV_MIN_PARAMS(3);
 
@@ -457,6 +463,19 @@ static MODCMD_FUNC(cmd_send)
             send_message_type((ma->flags & MEMO_USE_PRIVMSG)? MSG_TYPE_PRIVMSG : MSG_TYPE_NOTICE, other, memoserv ? memoserv : cmd->parent->bot, "MSMSG_NEW_MESSAGE", user->nick);
     }
 
+    estr = conf_get_data("services/nickserv/email_enabled", RECDB_QSTRING);
+    netname = conf_get_data("server/network", RECDB_QSTRING);
+    email = atoi(estr);
+    if (email && (ma->flags & MEMO_NOTIFY_NEW)) {
+        fmt = handle_find_message(hi, "MSEMAIL_NEWMEMO_SUBJECT");
+        snprintf(subject, sizeof(subject), fmt, netname, memoserv->nick, user->nick);
+
+        fmt = handle_find_message(hi, "MSEMAIL_NEWMEMO_BODY");
+        snprintf(body, sizeof(body), fmt, user->nick, memoserv->nick, message, memoserv->nick, memo_id, netname);
+
+        sendmail(memoserv, hi, subject, body, 0);
+    }
+
     reply("MSMSG_MEMO_SENT", ma->handle->handle, memo_id);
     return 1;
 }
@@ -548,11 +567,6 @@ static MODCMD_FUNC(cmd_read)
     char posted[24];
     struct tm tm;
 
-    if (!(ma = memoserv_get_account(user->handle_info)))
-        return 0;
-    if (!(memo = find_memo(user, cmd, ma, argv[1], &memoid)))
-        return 0;
-
     if (argc > 2) {
         char *argtwo = argv[2];
         while (*argtwo) {
@@ -579,6 +593,12 @@ static MODCMD_FUNC(cmd_read)
         }
     }
 
+    if (!(ma = memoserv_get_account(user->handle_info)))
+        return 0;
+    
+    if (!(memo = find_memo(user, cmd, ma, argv[1], &memoid)))
+        return 0;
+
     localtime_r(&memo->sent, &tm);
     strftime(posted, sizeof(posted), "%I:%M %p, %m/%d/%Y", &tm);
 
@@ -1357,7 +1377,7 @@ memoserv_finalize(void) {
     if (str) {
         memoserv = memoserv_conf.bot;
         const char *modes = conf_get_data("modules/memoserv/modes", RECDB_QSTRING);
-        memoserv = AddLocalUser(str, str, NULL, "User-User Memorandum Services", modes ? modes : NULL);
+        memoserv = AddService(str, modes ? modes : NULL, "User-User Memorandum Services", NULL);
 
     } else {
         log_module(MS_LOG, LOG_ERROR, "database_get_data for memoserv_conf.bot failed!");