imh

Check-in [bf8c7c7d24]
Login

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

Overview
Comment:Let us point at an alternate SMTP server
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | master | trunk
Files: files | file ages | folders
SHA3-256: bf8c7c7d2480fe590c014ea40e9f3dd84b42a59e764bac228567c48e65c2c942
User & Date: vandys 2020-06-18 19:49:11
Context
2020-06-18
19:49
Let us point at an alternate SMTP server Leaf check-in: bf8c7c7d24 user: vandys tags: master, trunk
2020-02-10
00:56
Ignore junk check-in: 2d7b4d1a58 user: vandys tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to imh.py.

290
291
292
293
294
295
296

297
298
299
300
301
302
303
...
521
522
523
524
525
526
527







528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
    def add_config(self, cfg):
        cfg.onearg.add( ("server",) )
        cfg.onearg.add( ("user",) )
        cfg.onearg.add( ("password",) )
        cfg.args.add( ("mailboxes",) )
        cfg.onearg.add( ("address",) )
        cfg.onearg.add( ("name",) )


    # Run the function @op, which will get back (result, value)
    # Bomb if the result indicates failure.
    def cmd(self, op):
        tup = op()
        if tup[0] != "OK":
            raise Exception, "Op %s failed with %s" % (op, tup[0])
................................................................................
    def connect_server(self):
	cfg = self.cfg
	srv = self.server = imaplib.IMAP4_SSL(str(cfg["server"]))
	srv.login(cfg["user"], cfg["password"])

    # Start up
    def main(self):







        # Get config, or parse config on first run
        st = self.load_state()
        if st is None:
            # Parse config file
            c = chore.config.Config()
            IMH_mixin.add_config(self, c)
            fn = os.getenv("HOME") + "/.imh.config"
            os.chmod(fn, 0600)
            self.cfg = cfg = c.load_cfg(fn)
            self.state = st = {"config": cfg,
                "curbox": "INBOX",
                "curmsgs": {},
            }
            self.save_state()
        else:
            self.state = st
            self.cfg = cfg = st["config"]
        self.changed = False

        # Connect to our imap server
        if self.need_server():
	    self.connect_server()
        else:
            self.server = None







>







 







>
>
>
>
>
>
>



|
<
<
<
<
<
<




<
|
<







290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
...
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539






540
541
542
543

544

545
546
547
548
549
550
551
    def add_config(self, cfg):
        cfg.onearg.add( ("server",) )
        cfg.onearg.add( ("user",) )
        cfg.onearg.add( ("password",) )
        cfg.args.add( ("mailboxes",) )
        cfg.onearg.add( ("address",) )
        cfg.onearg.add( ("name",) )
        cfg.args.add( ("smtp",) )

    # Run the function @op, which will get back (result, value)
    # Bomb if the result indicates failure.
    def cmd(self, op):
        tup = op()
        if tup[0] != "OK":
            raise Exception, "Op %s failed with %s" % (op, tup[0])
................................................................................
    def connect_server(self):
	cfg = self.cfg
	srv = self.server = imaplib.IMAP4_SSL(str(cfg["server"]))
	srv.login(cfg["user"], cfg["password"])

    # Start up
    def main(self):
	# Get config
	c = chore.config.Config()
	IMH_mixin.add_config(self, c)
	fn = os.getenv("HOME") + "/.imh.config"
	os.chmod(fn, 0600)
	self.cfg = c.load_cfg(fn)

        # Get config, or parse config on first run
        st = self.load_state()
        if st is None:
            st = {






                "curbox": "INBOX",
                "curmsgs": {},
            }
            self.save_state()

	self.state = st

        self.changed = False

        # Connect to our imap server
        if self.need_server():
	    self.connect_server()
        else:
            self.server = None

Changes to whatnow.py.

1
2
3
4
5
6




7
8
9
10
11
12
13
..
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
...
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
...
173
174
175
176
177
178
179
180
181
182



#!/usr/local/bin/tauthon
# whatnow.py
#       Let the user hand-tailor their message
#
import sys, smtplib, rfc822, string, os, imaplib, time
import imh





# fix_headers()
#	Make necessary modifications to the mail's headers
#
# Trim lines holding Bcc addresses.
def fix_headers(msg):
    x = 0
................................................................................

# 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

................................................................................
        if tup[0] != "OK":
            sys.stderr.write(
             "Note: could not save message: %s\n" % (tup[1],))
            return False
        return True

    def run(self):


        # Work from this file
        if len(self.args) != 1:
            sys.stderr.write("No file argument\n")
            sys.exit(1)
        fn = self.args[0]

        # Start with an edit?
        if 'e' in self.flags:
            os.system("%s %s" % (os.getenv("EDITOR"), fn))







        # Now take commands
        while True:

            sys.stdout.write("What now? ")
            l = sys.stdin.readline().strip()
            tup = l.split()
            cmd = tup[0]
................................................................................
            # if l in ("?", "h", "help"):
            sys.stdout.write("[s]end - Send message out\n")
            sys.stdout.write("[e]dit - Edit the message\n")
            sys.stdout.write("refile +<folder> - Put message in folder\n")
            sys.stdout.write("[q]uit - Leave here, keep message\n")
            sys.stdout.write("? - This message\n")

if __name__ == "__main__":
    i = Whatnow()
    i.main()









>
>
>
>







 







|







 







>











>
>
>
>
>
>







 







|


>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
..
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
...
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
...
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/usr/local/bin/tauthon
# whatnow.py
#       Let the user hand-tailor their message
#
import sys, smtplib, rfc822, string, os, imaplib, time
import imh

# SMTP server (config can override)
SMTP_Server = "localhost"
SMTP_Port = 25

# fix_headers()
#	Make necessary modifications to the mail's headers
#
# Trim lines holding Bcc addresses.
def fix_headers(msg):
    x = 0
................................................................................

# 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(SMTP_Server, port=SMTP_Port)
    except:
        sys.stderr.write("Can't connect\n")
        return False
    smtp.sendmail(src, dests, msg)
    smtp.quit()
    return True

................................................................................
        if tup[0] != "OK":
            sys.stderr.write(
             "Note: could not save message: %s\n" % (tup[1],))
            return False
        return True

    def run(self):
	global SMTP_Server, SMTP_Port

        # Work from this file
        if len(self.args) != 1:
            sys.stderr.write("No file argument\n")
            sys.exit(1)
        fn = self.args[0]

        # Start with an edit?
        if 'e' in self.flags:
            os.system("%s %s" % (os.getenv("EDITOR"), fn))

	# SMTP config?
	if "smtp" in self.cfg:
	    tup = self.cfg["smtp"]
	    SMTP_Server = tup[0]
	    SMTP_Port = int(tup[1])

        # Now take commands
        while True:

            sys.stdout.write("What now? ")
            l = sys.stdin.readline().strip()
            tup = l.split()
            cmd = tup[0]
................................................................................
            # if l in ("?", "h", "help"):
            sys.stdout.write("[s]end - Send message out\n")
            sys.stdout.write("[e]dit - Edit the message\n")
            sys.stdout.write("refile +<folder> - Put message in folder\n")
            sys.stdout.write("[q]uit - Leave here, keep message\n")
            sys.stdout.write("? - This message\n")

def run():
    i = Whatnow()
    i.main()

if __name__ == "__main__":
    run()