imh

Check-in [0863d3a0d4]
Login

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

Overview
Comment:Deal with long idle intervals, try to handle with a server reconnection.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256: 0863d3a0d450a5c0145ac4bf3427ac7dbf010cc8f36cda6320360c8d96d16bbb
User & Date: vandys 2020-02-10 00:55:51
Context
2020-02-10
00:56
Ignore junk check-in: 2d7b4d1a58 user: vandys tags: master, trunk
00:55
Deal with long idle intervals, try to handle with a server reconnection. check-in: 0863d3a0d4 user: vandys tags: master, trunk
00:55
Defend against random character sets check-in: f7f1e1a0b0 user: vandys tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to imh.py.

513
514
515
516
517
518
519






520
521
522
523
524
525
526
...
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
    def nogetopt(self):
        return False

    # By default, connect to imap
    def need_server(self):
        return True







    # 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()
................................................................................
        else:
            self.state = st
            self.cfg = cfg = st["config"]
        self.changed = False

        # Connect to our imap server
        if self.need_server():
            srv = self.server = imaplib.IMAP4_SSL(str(cfg["server"]))
            srv.login(cfg["user"], cfg["password"])
        else:
            self.server = None

        # Parse command line
        self.flags = set()
        self.opts = {}
        if self.nogetopt():







>
>
>
>
>
>







 







|
<







513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
...
542
543
544
545
546
547
548
549

550
551
552
553
554
555
556
    def nogetopt(self):
        return False

    # By default, connect to imap
    def need_server(self):
        return True

    # Connect to our server
    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()
................................................................................
        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

        # Parse command line
        self.flags = set()
        self.opts = {}
        if self.nogetopt():

Changes to repl.py.

101
102
103
104
105
106
107

108





109
110
111
112
        fn = self.reply(m)

        # Hand it to whatnow, starting in edit mode
        os.system("whatnow -e %s" % (fn,))

        # Flag it as answered (technically, should only set this
        #  if whatnow handed off to SMTP, but close enough)

        tup = self.server.store(m, '+FLAGS', '\\Answered')






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







>
|
>
>
>
>
>




101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
        fn = self.reply(m)

        # Hand it to whatnow, starting in edit mode
        os.system("whatnow -e %s" % (fn,))

        # Flag it as answered (technically, should only set this
        #  if whatnow handed off to SMTP, but close enough)
	try:
	    tup = self.server.store(m, '+FLAGS', '\\Answered')
	except:
	    # Probably idled out while we were typing
	    sys.stderr.write("Server dropped, reconnecting...\n")
	    self.connect_server()
	    tup = self.server.store(m, '+FLAGS', '\\Answered')

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

Changes to whatnow.py.

95
96
97
98
99
100
101

102
103





104
105
106
107
108
109
110

        # Entire message contents
        f = open(fn, "r")
        buf = f.read()
        f.close()

        # Sent message saved in @folder

        tup = self.server.append(folder, "",
            imaplib.Time2Internaldate(time.time()), buf)





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

    def run(self):







>
|
|
>
>
>
>
>







95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

        # Entire message contents
        f = open(fn, "r")
        buf = f.read()
        f.close()

        # Sent message saved in @folder
	try:
	    tup = self.server.append(folder, "",
		imaplib.Time2Internaldate(time.time()), buf)
	except:
	    sys.stderr.write("(reconnect)\n")
	    self.connect_server()
	    tup = self.server.append(folder, "",
		imaplib.Time2Internaldate(time.time()), buf)
        if tup[0] != "OK":
            sys.stderr.write(
             "Note: could not save message: %s\n" % (tup[1],))
            return False
        return True

    def run(self):