4 BEGIN { json_load("var/mail.txt", mail_enable) }
5 END { json_save("var/mail.txt", mail_enable) }
9 mail_hist = 60 # Send 60 seconds of backlog
10 mail_delay = 60 # Wait 60 seconds after last mention before mailing
12 mail_from = NICK "<andy753421@gmail.com>"
13 mail_err = "If you received this message in error,\n" \
14 "someone in #rhnoise is being a jerk"
16 for (_user in mail_enable)
17 debug("watching " mail_enable[_user] " for " _user)
20 function mail_send(addr, subj, body,
23 gsub(/[^a-zA-Z0-9_+@.-]/, "", addr)
24 sendmail = "/usr/sbin/sendmail " addr
25 print "To: " addr | sendmail
26 print "From: " mail_from | sendmail
27 print "Subject: " subj | sendmail
30 print mail_err | sendmail
34 function mail_prep(user, chan,
39 addr = mail_enable[user]
40 sn = asorti(mail_log[chan], ss)
42 for (si = 1; si <= sn; si++) {
44 mn = length(mail_log[chan][sec])
45 for (mi = 0; mi < mn; mi++) {
46 msg = mail_log[chan][sec][mi]
47 if (sec > mail_ready[user][chan] - mail_hist) {
56 privmsg(chan, "notifying " user " at " addr)
57 mail_send(addr, "Message for " user " in " chan, body)
58 delete mail_ready[user][chan]
61 function mail_run( user, chan, ready, time)
63 for (user in mail_ready)
64 for (chan in mail_ready[user]) {
65 ready = mail_ready[user][chan]
66 delay = systime() - ready
67 if (ready && delay > mail_delay)
75 reply("notifying " $2 " for " $3)
83 gsub(/[^a-zA-Z0-9_+@.-]/, "", _user)
84 gsub(/[^a-zA-Z0-9_+@.-]/, "", _addr)
85 reply("notifying " _addr " for " _user)
86 mail_enable[_user] = _addr
92 reply("well fine then")
93 delete mail_enable[$2]
99 reply("well fine then")
100 delete mail_enable[FROM]
101 delete mail_ready[FROM]
106 for (_user in mail_enable)
107 reply("\"" _user "\" <" mail_enable[_user] ">")
111 for (_user in mail_enable)
112 if ($0 ~ "\\<"_user"\\>") {
113 mail_ready[_user][DST] = systime()
114 debug("queueing messages to " DST " for " _user)
118 FROM in mail_enable {
119 delete mail_ready[FROM]
120 debug("clearing message for " FROM)
125 _i = length(mail_log[DST][_t])
126 if (_i==0) delete mail_log[DST][_t]
127 mail_log[DST][_t][_i] = DST " " strftime("(%H:%M:%S) ") FROM ": " $0
128 #debug("log["DST"]["_t"]["_i"] = "mail_log[DST][_t][_i])