imh

Check-in [9b6c22a915]
Login

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

Overview
Comment:Handle refile failure gracefully
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256:9b6c22a91568619a54d086e06ab192cc37635be5630628a37386a3e2648f8f79
User & Date: ajv-899-334-8894@vsta.org 2016-11-11 03:39:32
Context
2016-11-11
03:39
If no messages, just quietly exit, don't Exception out check-in: 5761a5db23 user: ajv-899-334-8894@vsta.org tags: master, trunk
03:39
Handle refile failure gracefully check-in: 9b6c22a915 user: ajv-899-334-8894@vsta.org tags: master, trunk
03:38
Helpfully decline to go beyond last message check-in: 245fcd8b74 user: ajv-899-334-8894@vsta.org tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to refile.py.

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
            self.args = []
        else:
            destf = None

        # See what we should move (and, possibly, in what folder)
        msgs = self.arg_msgs()

        # No current message if we move it
        st = self.state
        fn = st["curbox"]
        if st["curmsgs"].get(fn, 999999) in msgs:
            del st["curmsgs"][fn]
            self.changed = True

        # Last arg should be destination folder
        if destf is None:
            if (len(self.args) != 1) or \
                    (not self.args[0].startswith('+')):
                raise Exception, "Last argument should be dest +folder"
            destf = self.args[0][1:]
        elif self.args:
            raise Exception, "Unexpected extra arguments"

        # Move each message, and mark for deletion
        srv = self.server

        for m in msgs:
            tup = srv.copy(m, destf)
            if tup[0] != "OK":
                sys.stderr.write(
                 "Can't move %d to %s: %s\n" % (m, destf, tup[1]))

            else:
                tup = srv.store(m, '+FLAGS', '\\Deleted')
                if tup[0] != "OK":
                    sys.stderr.write(
                     "Can't mark %d deleted: %s\n" % (m, tup[1]))










        # Dump the messages at their old location
        srv.expunge()

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







<
<
<
<
<
<
<











>





>





>

>
>
>
>
>
>
>
>
|
|




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
            self.args = []
        else:
            destf = None

        # See what we should move (and, possibly, in what folder)
        msgs = self.arg_msgs()








        # Last arg should be destination folder
        if destf is None:
            if (len(self.args) != 1) or \
                    (not self.args[0].startswith('+')):
                raise Exception, "Last argument should be dest +folder"
            destf = self.args[0][1:]
        elif self.args:
            raise Exception, "Unexpected extra arguments"

        # Move each message, and mark for deletion
        srv = self.server
        success = True
        for m in msgs:
            tup = srv.copy(m, destf)
            if tup[0] != "OK":
                sys.stderr.write(
                 "Can't move %d to %s: %s\n" % (m, destf, tup[1]))
                success = False
            else:
                tup = srv.store(m, '+FLAGS', '\\Deleted')
                if tup[0] != "OK":
                    sys.stderr.write(
                     "Can't mark %d deleted: %s\n" % (m, tup[1]))
                    success = False

        if success:
            # No current message if we moved it
            st = self.state
            fn = st["curbox"]
            if st["curmsgs"].get(fn, 999999) in msgs:
                del st["curmsgs"][fn]
                self.changed = True

            # Dump the messages at their old location
            srv.expunge()

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