wimap

Check-in [17e03cf724]
Login

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

Overview
Comment:Forward and back in message lists. Fix noop check of server status. Emphasis on date, don't use space for message index.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256:17e03cf724b023f405873a8ccbf309347c3784d797ebf7865aca6691ab1c5b8c
User & Date: ajv-899-334-8894@vsta.org 2016-11-27 01:17:19
Context
2016-11-27
16:05
Code up message reading check-in: 634e282a41 user: ajv-899-334-8894@vsta.org tags: master, trunk
01:17
Forward and back in message lists. Fix noop check of server status. Emphasis on date, don't use space for message index. check-in: 17e03cf724 user: ajv-899-334-8894@vsta.org tags: master, trunk
2016-11-26
23:23
First pass, iMap web interface check-in: 781ec6c7e9 user: ajv-899-334-8894@vsta.org tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to get.py.

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
...
159
160
161
162
163
164
165











166
167
168
169
170
171
172
173
        fn = urllib.unquote_plus(pp[0])
        if not self.valid_fname(fn):
            return False,None

        # Start at which index number?
        if self.vals and ("from" in self.vals):
            try:
                msgidx = int(self.vals["from"])
            except:
                return False,None
        else:
            msgidx = 1

        # Ask our library to pull them together
        srv = self.get_server()
        msgs = srv.messages(fn, msgidx, NMSG)
        if msgs is None:
            return False,None


        # Here's your messages
        buf = self.build_header("Messages %d-%d" %
            (msgidx, msgidx+len(msgs)-1))
        buf += '<table>\n'
        for msgidx,flags,fields in msgs:
            buf += ' <tr>\n'

            # Message #, emphasized if not marked as read
            if "Seen" not in flags:
                buf += '  <td><em>%d</em></td>\n' % (msgidx,)
            else:
                buf += '  <td>%d</td>\n' % (msgidx,)

            # Time if today
            # mm/dd if this year
            # mm/yy if previous years
            today = time.localtime()
            tm = srv.dt_parse(fields["date"])

            # This year
            if tm.tm_year == today.tm_year:
                # Today
                if (tm.tm_mon == today.tm_mon) and \
                        (tm.tm_mday == today.tm_mday):
                    buf += '  <td>%02d:%02d</td>\n' % \
                        (tm.tm_hour, tm.tm_min)
                else:
                    # Some month of this year
                    buf += '  <td>%d/%d</td>\n' % \
                        (tm.tm_mon, tm.tm_mday)
            else:
                # Some month of that year
                buf += '  <td>%d/%04d</td>\n' % \
                    (tm.tm_mon, tm.tm_year)








            # Who
            if "from" in fields:
                tup = parseaddr(fields["from"])
                s = tup[0].strip() or tup[1].strip() or "--"
                s = s[:20]
                buf += '  <td>%s</td>\n' % (cgi.escape(s),)
................................................................................
            # Subject
            buf += '  <td>%s</td>\n' % \
             (cgi.escape(fields.get("subject", "--")),)

            buf += ' </tr>\n'

        buf += '</table>\n'












        buf = self.build_tailer(buf)

        return True,self.send_result(buf, "text/html")

    # Message number under folder, render contents
    def read_msg(self):
        return None







|



|



|
|

>



|




<
<
<
<
<
<











<
|


<
|


<
|
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>








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
...
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
183
        fn = urllib.unquote_plus(pp[0])
        if not self.valid_fname(fn):
            return False,None

        # Start at which index number?
        if self.vals and ("from" in self.vals):
            try:
                startidx = int(self.vals["from"])
            except:
                return False,None
        else:
            startidx = 1

        # Ask our library to pull them together
        srv = self.get_server()
        tup = srv.messages(fn, startidx, NMSG)
        if tup is None:
            return False,None
        nmsg,msgs = tup

        # Here's your messages
        buf = self.build_header("Messages %d-%d" %
            (startidx, startidx+len(msgs)-1))
        buf += '<table>\n'
        for msgidx,flags,fields in msgs:
            buf += ' <tr>\n'







            # Time if today
            # mm/dd if this year
            # mm/yy if previous years
            today = time.localtime()
            tm = srv.dt_parse(fields["date"])

            # This year
            if tm.tm_year == today.tm_year:
                # Today
                if (tm.tm_mon == today.tm_mon) and \
                        (tm.tm_mday == today.tm_mday):

                    tms = "%02d:%02d" % (tm.tm_hour, tm.tm_min)
                else:
                    # Some month of this year

                    tms = "%d/%d" % (tm.tm_mon, tm.tm_mday)
            else:
                # Some month of that year

                tms = "%d/%04d" % (tm.tm_mon, tm.tm_year)

            # Emphasize time for unread
            if "Seen" not in flags:
                tms = "<em>%s</em>" % (tms,)

            # Add date
            buf += '  <td>%s</td>\n' % (tms,)

            # Who
            if "from" in fields:
                tup = parseaddr(fields["from"])
                s = tup[0].strip() or tup[1].strip() or "--"
                s = s[:20]
                buf += '  <td>%s</td>\n' % (cgi.escape(s),)
................................................................................
            # Subject
            buf += '  <td>%s</td>\n' % \
             (cgi.escape(fields.get("subject", "--")),)

            buf += ' </tr>\n'

        buf += '</table>\n'

        # Next and previous pages?
        ourpath = '/'.join(self.paths)
        if startidx > 1:
            buf += '<a href="/%s?from=%d">Older</a>\n' % (
                ourpath,
                (1 if (startidx <= NMSG) else (startidx-NMSG)) )
        if (startidx + NMSG) < nmsg:
            buf += '<a href="/%s?from=%d">Newer</a>\n' % (
                ourpath,
                startidx+NMSG )

        buf = self.build_tailer(buf)

        return True,self.send_result(buf, "text/html")

    # Message number under folder, render contents
    def read_msg(self):
        return None

Changes to imap.py.

96
97
98
99
100
101
102













103
104
105
106
107
108
109
...
129
130
131
132
133
134
135




136
137
138
139
140
141
142
...
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188

        # Burst flags, insert simple name in set
        res = set()
        for f in flags.split():
            res.add(f[1:])

        return res














    # Parse an email Date: field as a timeval
    def dt_parse(self, t):

        # Normalize whitespace
        tup = t.split()
        base = " ".join(tup[:5])
................................................................................
        except:
            tmf = time.time()

        return time.localtime(tmf)

    # Return list of metadata on messages starting at the
    #  given index for @nmsg




    def messages(self, fn, msgidx, maxmsg):
        srv = self.srv

        # Select folder, get message count
        tup = srv.select(fn, readonly=True)
        if tup[0] != "OK":
            return None
................................................................................

            # On to next
            msgidx += 1
            msgcount += 1
            if msgcount >= maxmsg:
                break

        return res

# Get or start an imap server connection
def get(user, uconfig, imaps):
    # Existing connection?
    srv = imaps.get(user)
    if srv is not None:
        # Make sure it's still alive
        import pdb
        pdb.set_trace()
        tup = srv.noop()
        if tup[0] == "OK":
            return srv
        srv.logout()
        del imaps[user]

    # New connection
    server = uconfig.get("server")
    passw = uconfig.get("pass")







>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>







 







|







<
<
|
<







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
...
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
...
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194


195

196
197
198
199
200
201
202

        # Burst flags, insert simple name in set
        res = set()
        for f in flags.split():
            res.add(f[1:])

        return res

    # Shim out to no-op test for health
    def noop(self):
        srv = self.srv
        tup = srv.noop()
        if tup[0] != "OK":
            return False
        return True

    # Shim to log off/disconnect
    def logout(self):
        srv = self.srv
        srv.logout()

    # Parse an email Date: field as a timeval
    def dt_parse(self, t):

        # Normalize whitespace
        tup = t.split()
        base = " ".join(tup[:5])
................................................................................
        except:
            tmf = time.time()

        return time.localtime(tmf)

    # Return list of metadata on messages starting at the
    #  given index for @nmsg
    # (#msgs-overall, [msgs...])
    # Each messages is:
    #   (idx#, set-flags, dict-header-fields)
    # Or return None on error.
    def messages(self, fn, msgidx, maxmsg):
        srv = self.srv

        # Select folder, get message count
        tup = srv.select(fn, readonly=True)
        if tup[0] != "OK":
            return None
................................................................................

            # On to next
            msgidx += 1
            msgcount += 1
            if msgcount >= maxmsg:
                break

        return nmsg,res

# Get or start an imap server connection
def get(user, uconfig, imaps):
    # Existing connection?
    srv = imaps.get(user)
    if srv is not None:
        # Make sure it's still alive


        if srv.noop():

            return srv
        srv.logout()
        del imaps[user]

    # New connection
    server = uconfig.get("server")
    passw = uconfig.get("pass")