imh

Check-in [d1a5dd1a0c]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Gracefully handle failed SMTP send
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256:d1a5dd1a0c9ba3e682d9229c96cf6a5d0cfc8506d0ee2626f664fa98afc1f354
User & Date: ajv-899-334-8894@vsta.org 2016-11-13 00:50:49
Context
2016-11-13
01:27
Decode "q code" encoded email headers check-in: bc6ff21fd1 user: ajv-899-334-8894@vsta.org tags: master, trunk
00:50
Gracefully handle failed SMTP send check-in: d1a5dd1a0c user: ajv-899-334-8894@vsta.org tags: master, trunk
2016-11-11
17:00
Defend against timezone names check-in: 6da5b555b8 user: ajv-899-334-8894@vsta.org tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to whatnow.py.

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
..
59
60
61
62
63
64
65
66
67
68
69

70
71
72
73

74
75
76
77
78
79
80
...
119
120
121
122
123
124
125
126



127
128
129
130
131
132
133
		msg = msg[0:x] + msg[x+1:]
	else:
	    x += 1
    return msg

# deliver()
#	Drive our SMTP server to send mail to the named destination

def deliver(src, dests, msg):
    sys.stderr.write('sendmail From: ' + src + ', to: ' + str(dests) + '\n')

    smtp = smtplib.SMTP("localhost")



    smtp.sendmail(src, dests, msg)
    smtp.quit()


# addrlist()
#	Convert list from getaddrlist() to a straight list of addresses
def addrlist(l):
    result = [ ]
    for e in l:
	result.append(e[1])
    return result

# sendmail()
#	Process message in file, send it on its way

def sendmail(fp):
    global username

    # Extract to whom we are directing this message
    m = rfc822.Message(fp)
    to = addrlist(m.getaddrlist('To'))
    cc = addrlist(m.getaddrlist('Cc'))
................................................................................
    msg = fp.readlines()

    # Edit out the Bcc lines
    msg = fix_headers(msg)

    # Now off it goes to each destination
    msgbuf = string.join(msg, '')
    deliver(src, dests, msgbuf)

# process()
#	Process the named file

def process(name):
    fp = open(name, 'r')
    sendmail(fp)
    fp.close()


class Whatnow(imh.IMH_mixin):

    # Flags for this command
    #
    # -e: Start in edit mode
    def cmdargs(self):
................................................................................
            cmd = tup[0]
            if len(tup) > 1:
                arg = tup[1]
            else:
                arg = ""

            if cmd in ("s", "send"):
                process(fn)



                if self.to_folder(fn, "INBOX.Sent"):
                    os.unlink(fn)
                else:
                    sys.stderr.write("(Leaving in %s)\n" % (fn,))
                return

            if cmd in ("e", "edit"):







>


>
|
>
>
>


>











>







 







|



>


|

>







 







|
>
>
>







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
..
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
...
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
		msg = msg[0:x] + msg[x+1:]
	else:
	    x += 1
    return msg

# deliver()
#	Drive our SMTP server to send mail to the named destination
# Return True on success, else False
def deliver(src, dests, msg):
    sys.stderr.write('sendmail From: ' + src + ', to: ' + str(dests) + '\n')
    try:
        smtp = smtplib.SMTP("localhost")
    except:
        sys.stderr.write("Can't connect\n")
        return False
    smtp.sendmail(src, dests, msg)
    smtp.quit()
    return True

# addrlist()
#	Convert list from getaddrlist() to a straight list of addresses
def addrlist(l):
    result = [ ]
    for e in l:
	result.append(e[1])
    return result

# sendmail()
#	Process message in file, send it on its way
# Return True for success, else False
def sendmail(fp):
    global username

    # Extract to whom we are directing this message
    m = rfc822.Message(fp)
    to = addrlist(m.getaddrlist('To'))
    cc = addrlist(m.getaddrlist('Cc'))
................................................................................
    msg = fp.readlines()

    # Edit out the Bcc lines
    msg = fix_headers(msg)

    # Now off it goes to each destination
    msgbuf = string.join(msg, '')
    return deliver(src, dests, msgbuf)

# process()
#	Process the named file
# Return True for success, else False
def process(name):
    fp = open(name, 'r')
    res = sendmail(fp)
    fp.close()
    return res

class Whatnow(imh.IMH_mixin):

    # Flags for this command
    #
    # -e: Start in edit mode
    def cmdargs(self):
................................................................................
            cmd = tup[0]
            if len(tup) > 1:
                arg = tup[1]
            else:
                arg = ""

            if cmd in ("s", "send"):
                res = process(fn)
                if not res:
                    # Error, so let'em try and fix it
                    continue
                if self.to_folder(fn, "INBOX.Sent"):
                    os.unlink(fn)
                else:
                    sys.stderr.write("(Leaving in %s)\n" % (fn,))
                return

            if cmd in ("e", "edit"):