X-Git-Url: https://jfr.im/git/irc/evilnet/x3.git/blobdiff_plain/fc4a50fc25d1fc680f9c46f61f9ae4486df1b9cb..ef5e03051fd86d66844d61f3fcc1c7a82957826a:/src/mod-memoserv.c diff --git a/src/mod-memoserv.c b/src/mod-memoserv.c index c193843..58d1c01 100644 --- a/src/mod-memoserv.c +++ b/src/mod-memoserv.c @@ -6,7 +6,7 @@ * * x3 is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -44,6 +44,7 @@ #include "nickserv.h" #include "opserv.h" #include "saxdb.h" +#include "sendmail.h" #include "timeq.h" #define KEY_MAIN_ACCOUNTS "accounts" @@ -67,8 +68,8 @@ static const struct message_entry msgtab[] = { { "MSMSG_MEMO_SENT", "Message sent to $b%s$b (ID# %d)." }, { "MSMSG_NO_MESSAGES", "You have no messages." }, { "MSMSG_MEMOS_FOUND", "Found $b%d$b matches." }, - { "MSMSG_HOWTO_READ", "Use /msg $S READ to read a message." }, - { "MSMSG_CLEAN_INBOX", "You have $b%d$b or more messages, please clean out your inbox.\nUse /msg $S READ to read a message." }, + { "MSMSG_HOWTO_READ", "Use READ to read a message." }, + { "MSMSG_CLEAN_INBOX", "You have $b%d$b or more messages, please clean out your inbox.\nUse READ to read a message." }, { "MSMSG_LIST_HEAD", "$bID$b $bFrom$b $bTime Sent$b" }, { "MSMSG_LIST_FORMAT", "%-2u %s $b%s$b %s" }, { "MSMSG_HISTORY_HEADER", "$bID$b $bTo$b $bTime Sent$b" }, @@ -85,11 +86,11 @@ static const struct message_entry msgtab[] = { { "MSMSG_EXPIRY_OFF", "I am currently not expiring messages. (turned off)" }, { "MSMSG_EXPIRY", "Messages will be expired when they are %s old (%d seconds)." }, { "MSMSG_MESSAGES_EXPIRED", "$b%lu$b message(s) expired." }, - { "MSMSG_MEMOS_INBOX", "You have $b%d$b new message(s) in your inbox and %d old messages. Use /msg $S LIST to list them." }, - { "MSMSG_NEW_MESSAGE", "You have a new message from $b%s$b. /msg $S LIST" }, + { "MSMSG_MEMOS_INBOX", "You have $b%d$b new message(s) in your inbox and %d old messages. Use LIST to list them." }, + { "MSMSG_NEW_MESSAGE", "You have a new message from $b%s$b. Use LIST to see your messages." }, { "MSMSG_FULL_INBOX", "$b%s$b cannot recieve anymore memos as their inbox is full" }, { "MSMSG_DELETED_ALL", "Deleted all of your messages." }, - { "MSMSG_USE_CONFIRM", "Please use /msg $S DELETE * $bCONFIRM$b to delete $uall$u of your messages." }, + { "MSMSG_USE_CONFIRM", "Please use DELETE * $bCONFIRM$b to delete $uall$u of your messages." }, { "MSMSG_STATUS_HIST_TOTAL", "I have $b%u$b history entries in my database." }, { "MSMSG_STATUS_TOTAL", "I have $b%u$b memos in my database." }, @@ -111,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 } @@ -400,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); @@ -453,7 +460,20 @@ static MODCMD_FUNC(cmd_send) struct userNode *other; for (other = ma->handle->users; other; other = other->next_authed) - send_message_type((ma->flags & MEMO_USE_PRIVMSG)? MSG_TYPE_PRIVMSG : MSG_TYPE_NOTICE, other, cmd->parent->bot, "MSMSG_NEW_MESSAGE", user->nick); + 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); @@ -547,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) { @@ -578,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);