@@ -21,7 +21,7 @@ except ImportError:
21
21
import ConfigParser as configparser
22
22
import os .path
23
23
import re
24
- import time
24
+ import datetime as dt
25
25
import logging
26
26
27
27
From_RE = re .compile (b'^From ' , flags = re .MULTILINE )
@@ -98,10 +98,12 @@ class ImapUtil(object):
98
98
99
99
def do_capabilities (self , args ):
100
100
for c in self .client .capabilities ():
101
- print (c )
101
+ print (str ( c . decode ( 'ascii' )) )
102
102
103
103
def do_namespace (self , args ):
104
104
ns = self .client .namespace ()
105
+ # E.g. ((('', '.'),), None, None)
106
+ # personal, other, shared
105
107
print (ns )
106
108
107
109
@arg ('folder' , nargs = '?' )
@@ -110,14 +112,14 @@ class ImapUtil(object):
110
112
lst = self .client .list_folders (args .folder )
111
113
else :
112
114
lst = self .client .list_folders ()
113
- for f in lst :
114
- print (f )
115
+ for flags , delimiter , name in lst :
116
+ print (name )
115
117
116
118
@arg ('folder' )
117
119
def do_select (self , args ):
118
120
folder = args .folder
119
121
res = self .client .select_folder (folder )
120
- print ("%d message(s) in %s" % (res ['EXISTS' ], folder ))
122
+ print ("%d message(s) in %s" % (res [b 'EXISTS' ], folder ))
121
123
122
124
@arg ('--export' , type = str , help = 'Export messages' )
123
125
@arg ('--unread' , action = 'store_true' , help = 'Treat even if unread' )
@@ -167,16 +169,9 @@ class ImapUtil(object):
167
169
168
170
def get_older (self , folder , days , unread = False ):
169
171
self .client .select_folder (folder )
170
- date = time .localtime (time .time () - int (days ) * 86400 )
171
- # sdate = imaplib.Time2Internaldate(date)
172
- # print('sdate:',sdate)
173
- # lst = account.search('SEEN','UNDELETED',
174
- # 'BEFORE',sdate)
175
- sdate = time .strftime ('%e-%b-%Y' , date )
176
- terms = ('UNDELETED' , 'BEFORE' , sdate )
177
- if not unread :
178
- terms += ('SEEN' ,)
179
- lst = self .client .search (terms )
172
+ date = dt .date .today () - dt .timedelta (days = days )
173
+ lst = self .client .search (('SEEN' ,'UNDELETED' ,
174
+ 'BEFORE' , date ))
180
175
return lst
181
176
182
177
@arg ('--delete' , action = 'store_true' , help = 'Delete messages after export' )
0 commit comments