This file is indexed.

/usr/lib/python2.7/dist-packages/gplugs/mail.py is in gozerbot 0.99.1-5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# plugs/mail.py
#
#

__copyright__ = 'this file is in the public domain'
__depend__ = ['log', ]
__gendocfirst__ = ['mail-set', ]

from gozerbot.persist.persiststate import UserState
from gozerbot.commands import cmnds
from gozerbot.examples import examples
from gozerbot.generic import waitforqueue, rlog, hourmin, strtotime
from gozerbot.users import users
from gozerbot.config import config
from gozerbot.plugins import plugins
from gozerbot.plughelp import plughelp
from gozerbot.aliases import aliasset
from gozerbot.tests import tests
from gplugs.log import logs
import smtplib, random, time, types

plughelp.add('mail', 'mail related commands')

rendezvous = {}

def getemail(username):
    try:
        state = UserState(username)
        if state:
            return state['email']
    except KeyError:
        return

class Mailservernotset(Exception):

    """ exception to raise if mail server is not set """

    def __str__(self):
        return "config['mailserver'] is not set"

def domail(mailto, txt, fromm=None, mailserver=None, subject=None):
    """ sent the mail """
    if not txt:
        rlog(10, 'mail', 'no text to send')
        return
    if fromm:
        fromaddr = fromm
    else:
        fromaddr = config['mailfrom']
        if not fromaddr:
            fromaddr = 'gozerbot@gozerbot.org'
    if not mailserver:
        mailserver = config['mailserver']
    if not mailserver:
        raise Mailservernotset
    if type(txt) != types.ListType:
        txt = [txt, ]
    msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % \
(fromaddr, mailto, subject))
    for i in txt:
        msg += "%s\r\n" % i 
    server = smtplib.SMTP(mailserver)
    server.sendmail(fromaddr, mailto, msg)

def handle_mail(bot, ievent):
    """ mail result from pipeline to the user giving the command """
    if not ievent.inqueue:
        ievent.reply('use mail in a pipeline')
        return
    ievent.reply('waiting for input to mail')
    result = waitforqueue(ievent.inqueue, 10)
    if not result:
        ievent.reply('no data to mail')
        return
    username = users.getname(ievent.userhost)
    email = getemail(username)
    if email:
        try:
            sub = "output of %s" % ievent.origtxt
            domail(email, result, subject=sub)
        except Exception, ex:
            ievent.reply("can't send email: %s" % str(ex))
            return
        ievent.reply('%s lines sent' % len(result))
    else:
        ievent.reply("can't get email of %s" % username)
 
cmnds.add('mail', handle_mail, ['MAIL', 'OPER'], threaded=True)
examples.add('mail', 'mail pipelined data to user giving the command', \
'todo | mail')
tests.add('exceptions | mail')

def handle_re(bot, ievent):
    """ mail log since last spoken """
    if not logs:
        ievent.reply('log plugin is not enabled')
        return
    if ievent.channel not in logs.loglist:
        ievent.reply('logging is not enabled in %s' % ievent.channel)
        return
    lastlist = logs.lastspokelist(ievent.channel, ievent.userhost, 100)
    lasttime = time.time()
    gotcha = None
    for i in lastlist[::-1]:
        delta = lasttime - i
        if delta > 600:
            gotcha = i
            break
        else:
            lasttime = i
    if gotcha:
        result = logs.fromtimewithbot(ievent.channel, gotcha)
        if result:
            username = users.getname(ievent.userhost)
            email = getemail(username)
            if email:
                try:
                    res = []
                    for i in result:
                        if i[2] == 'bot':
                            txt = i[4]
                        else:
                            nr = i[4].find(' ')
                            txt = i[4][nr:].strip()
                        res.append("[%s] <%s> %s" % \
(hourmin(float(i[1])), i[2], txt))
                    domail(email, res, subject="log of %s" % ievent.channel)
                except Exception, ex:
                    ievent.reply("can't send email: %s" % str(ex))
                    return
                ievent.reply('%s lines sent' % len(result))
                return
            else:
                ievent.reply("can't get email of %s" % username)
                return
    ievent.reply('no data found')
    
cmnds.add('re', handle_re, ['MAIL', 'OPER'])
examples.add('re', 'mail the log since last spoken word', 're')
tests.add('re', 'lines sent')

def handle_mailtime(bot, ievent):
    """ mail log since a given time """
    if not logs:
        ievent.reply('log plugin is not enabled')
        return
    if ievent.channel not in logs.loglist:
        ievent.reply('logging is not enabled in %s' % ievent.channel)
        return
    fromtime = strtotime(ievent.rest)
    if not fromtime:
        ievent.reply("can't detect time")
        return
    result = logs.fromtimewithbot(ievent.channel, fromtime)
    if result:
        username = users.getname(ievent.userhost)
        email = getemail(username)
        if email:
            try:
                res = []
                for i in result:
                    if i[2] == 'bot':
                        txt = i[4]
                    else:
                        nr = i[4].find(' ')
                        txt = i[4][nr:].strip()
                    res.append("[%s] <%s> %s" % (hourmin(float(i[1])), i[2], \
txt))
                domail(email, res, subject="log of %s" % ievent.channel)
            except Exception, ex:
                ievent.reply("can't send email: %s" % str(ex))
                return
            ievent.reply('%s lines sent' % len(result))
            return
        else:
            ievent.reply("can't get email of %s" % username)
            return
    ievent.reply('no data found')
    
cmnds.add('mail-time', handle_mailtime, ['MAIL', 'OPER'])
examples.add('mail-time', 'mail the log since given time', 'mail-time 12:00')
tests.add('mail-time 9:00')