5 json_load("var/mail.json", mail_enable)
6 for (_user in mail_enable)
7 debug("watching " mail_enable[_user] " for " _user)
10 TO == NICK && /^sync/ {
11 json_load("var/mail.json", mail_enable)
12 for (_user in mail_enable)
13 debug("watching " mail_enable[_user] " for " _user)
18 mail_hist = 5*60 # If the users has not spoken withn mail_before before
19 mail_before = 5*60 # someone mentions their name and does not reply within
20 mail_after = 5*60 # mail_after seconds, email them hist seconds of the backlog
22 mail_from = NICK "<" NICK "@pileus.org>"
23 mail_err = "If you received this message in error,\n" \
24 "someone in #rhnoise is being a jerk"
27 function mail_send(addr, subj, body,
30 gsub(/[^a-zA-Z0-9_+@.-]/, "", addr)
31 sendmail = "/usr/sbin/sendmail " addr
32 print "To: " addr | sendmail
33 print "From: " mail_from | sendmail
34 print "Subject: " subj | sendmail
37 print mail_err | sendmail
41 function mail_prep(user, chan,
46 addr = mail_enable[user]
47 sn = asorti(mail_log[chan], ss)
49 for (si = 1; si <= sn; si++) {
51 mn = length(mail_log[chan][sec])
52 for (mi = 0; mi < mn; mi++) {
53 msg = mail_log[chan][sec][mi]
54 if (sec > mail_ready[user][chan] - mail_hist) {
63 say(chan, "notifying " user " at " addr)
64 mail_send(addr, "Message for " user " in " chan, body)
65 delete mail_ready[user][chan]
68 function mail_run( user, chan, ready, time)
70 for (user in mail_ready)
71 for (chan in mail_ready[user]) {
72 ready = mail_ready[user][chan]
73 delay = systime() - ready
74 if (ready && delay > mail_after)
79 function mail_save(file)
81 json_save(file, mail_enable)
86 say(".help mail -- manage email subscriptions")
90 say("Mail -- email users when they are mentioned")
91 say(".subscribe [addr] -- set your mailing address to [addr]")
92 say(".unsubscribe [addr] -- remove your subscription")
93 say(".addresses -- show your subscription address")
101 reply("notifying " $2 " for " $3)
103 mail_save("var/mail.json")
107 /^subscribe *[^ ]*$/ {
110 gsub(/[^a-zA-Z0-9_+@.-]/, "", _user)
111 gsub(/[^a-zA-Z0-9_+@.-]/, "", _addr)
112 reply("notifying " _addr " for " _user)
113 mail_enable[_user] = _addr
114 mail_save("var/mail.json")
120 reply("well fine then")
121 delete mail_enable[$2]
122 delete mail_ready[$2]
124 mail_save("var/mail.json")
129 reply("well fine then")
130 delete mail_enable[FROM]
131 delete mail_ready[FROM]
132 delete mail_seen[FROM]
133 mail_save("var/mail.json")
138 for (_user in mail_enable)
139 reply("\"" _user "\" <" mail_enable[_user] ">")
142 # Message logging and monitoring
144 for (_user in mail_enable) {
145 _idle = systime() - mail_seen[_user]
146 if ($0 ~ "\\<"_user"\\>" && _idle > mail_before) {
147 mail_ready[_user][DST] = systime()
148 debug("queueing messages to " DST " for " _user)
153 FROM in mail_enable {
154 delete mail_ready[FROM]
155 mail_seen[FROM] = systime()
156 debug("clearing message for " FROM)
161 _i = length(mail_log[DST][_t])
162 if (_i==0) delete mail_log[DST][_t]
163 mail_log[DST][_t][_i] = DST " " strftime("(%H:%M:%S) ") FROM ": " $0
164 #debug("log["DST"]["_t"]["_i"] = "mail_log[DST][_t][_i])