parent
22e873833f
commit
f89d94867f
61
mode/mbox.py
61
mode/mbox.py
|
@ -7,6 +7,8 @@ from buffer import Buffer
|
||||||
from method import Method, Argument, arg
|
from method import Method, Argument, arg
|
||||||
import util
|
import util
|
||||||
|
|
||||||
|
cont_re = re.compile(r' *\n *| +')
|
||||||
|
|
||||||
class LineGrammar(Grammar):
|
class LineGrammar(Grammar):
|
||||||
rules = [PatternRule(name=r'data', pattern=r'^.*\n$')]
|
rules = [PatternRule(name=r'data', pattern=r'^.*\n$')]
|
||||||
|
|
||||||
|
@ -48,14 +50,19 @@ class MboxMsgBuffer(Buffer):
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
def _get_lines(self):
|
def _get_lines(self):
|
||||||
|
d = {}
|
||||||
|
for name in ('delivered-to', 'to', 'from', 'subject', 'date'):
|
||||||
|
s = self.msg.get(name)
|
||||||
|
d[name] = cont_re.sub(' ', s.replace('\t', ' '))
|
||||||
lines = [
|
lines = [
|
||||||
'Delivered-To: ' + self.msg.get('delivered-to'),
|
'Delivered-To: ' + d['delivered-to'],
|
||||||
'To: ' + self.msg.get('to'),
|
'To: ' + d['to'],
|
||||||
'From: ' + self.msg.get('from'),
|
'From: ' + d['from'],
|
||||||
'Subject: ' + self.msg.get('subject'),
|
'Subject: ' + d['subject'],
|
||||||
'Date: ' + self.msg.get('date'),
|
'Date: ' + d['date'],
|
||||||
'',
|
'',
|
||||||
]
|
]
|
||||||
|
|
||||||
lines.extend(self._get_msg_lines(self.msg))
|
lines.extend(self._get_msg_lines(self.msg))
|
||||||
return lines
|
return lines
|
||||||
def open(self):
|
def open(self):
|
||||||
|
@ -67,7 +74,8 @@ class MboxMsgBuffer(Buffer):
|
||||||
class MboxListBuffer(Buffer):
|
class MboxListBuffer(Buffer):
|
||||||
btype = 'mboxlist'
|
btype = 'mboxlist'
|
||||||
reverse = True
|
reverse = True
|
||||||
format = '%(pos)4d %(replied)1.1s %(dow)3.3s %(day)2.2s %(fromname)-15.15s %(size)6.6s %(subject)-43.43s'
|
#format = '%(pos)4d %(replied)1.1s %(month)3.3s %(day)2.2s %(fromname)-15.15s %(size)6.6s %(subject)-43.43s'
|
||||||
|
format = '%(pos)4d %(replied)1.1s %(month)3.3s %(day)2.2s %(fromname)-15.15s %(size)6.6s %(subject)s'
|
||||||
|
|
||||||
from_re1 = re.compile(r'^ *" *([^"]+) *" *< *(.+) *> *$')
|
from_re1 = re.compile(r'^ *" *([^"]+) *" *< *(.+) *> *$')
|
||||||
from_re2 = re.compile(r'^ *([^" ].*?) *< *(.+) *> *$')
|
from_re2 = re.compile(r'^ *([^" ].*?) *< *(.+) *> *$')
|
||||||
|
@ -102,12 +110,14 @@ class MboxListBuffer(Buffer):
|
||||||
if m: return m.group(1), m.group(1)
|
if m: return m.group(1), m.group(1)
|
||||||
m = self.from_re4.match(msg['from'])
|
m = self.from_re4.match(msg['from'])
|
||||||
if m: return m.group(2), m.group(1)
|
if m: return m.group(2), m.group(1)
|
||||||
#return msg['from'], msg['from']
|
|
||||||
return 'unknown', 'unknown'
|
return 'unknown', 'unknown'
|
||||||
def _parse_date(self, msg):
|
def _parse_date(self, msg):
|
||||||
|
fields = ['', '', '', '', '', '', '', '']
|
||||||
m = self.date_re1.match(msg['date'])
|
m = self.date_re1.match(msg['date'])
|
||||||
if m: return m.groups()
|
if m:
|
||||||
return ('', '', '', '', '', '', '', '')
|
fields = list(m.groups())
|
||||||
|
fields[1] = '%02d' % int(fields[1])
|
||||||
|
return fields
|
||||||
|
|
||||||
def _create_msg_dict(self, pos, msg):
|
def _create_msg_dict(self, pos, msg):
|
||||||
d = {}
|
d = {}
|
||||||
|
@ -129,6 +139,7 @@ class MboxListBuffer(Buffer):
|
||||||
for key in d:
|
for key in d:
|
||||||
if type(d[key]) == type(''):
|
if type(d[key]) == type(''):
|
||||||
d[key] = d[key].replace('\t', ' ')
|
d[key] = d[key].replace('\t', ' ')
|
||||||
|
d[key] = cont_re.sub(' ', d[key])
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def _get_lines(self):
|
def _get_lines(self):
|
||||||
|
@ -148,7 +159,7 @@ class MboxListBuffer(Buffer):
|
||||||
for msg in msgs:
|
for msg in msgs:
|
||||||
d = self._create_msg_dict(pos, msg)
|
d = self._create_msg_dict(pos, msg)
|
||||||
s = self.format % d
|
s = self.format % d
|
||||||
lines.append(s)
|
lines.append(s.rstrip())
|
||||||
pos += 1
|
pos += 1
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
|
@ -180,6 +191,25 @@ class MboxOpenPath(Method):
|
||||||
w.application.add_buffer(b)
|
w.application.add_buffer(b)
|
||||||
w.application.switch_buffer(b)
|
w.application.switch_buffer(b)
|
||||||
|
|
||||||
|
class MailListGrammar(Grammar):
|
||||||
|
rules = [
|
||||||
|
PatternGroupRule(r'xyz',
|
||||||
|
r'index', r'^ *[0-9]+',
|
||||||
|
r'spaces', r' ',
|
||||||
|
r'flag', r'.',
|
||||||
|
r'spaces', r' ',
|
||||||
|
r'month', r'Jan|Fed|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec',
|
||||||
|
#r'dow', r'Mon|Tue|Wed|Thu|Fri|Sat|Sun',
|
||||||
|
r'spaces', r' +',
|
||||||
|
r'day', r'[0-9]+',
|
||||||
|
r'spaces', r' +',
|
||||||
|
r'sender', r'.{16}',
|
||||||
|
r'spaces', r' +',
|
||||||
|
r'size', r'[0-9]+',
|
||||||
|
r'spaces', ' +',
|
||||||
|
r'subject', r'.+$'),
|
||||||
|
]
|
||||||
|
|
||||||
class MboxMsg(mode.Fundamental):
|
class MboxMsg(mode.Fundamental):
|
||||||
modename = 'MboxMsg'
|
modename = 'MboxMsg'
|
||||||
colors = {
|
colors = {
|
||||||
|
@ -202,7 +232,18 @@ class MboxMsg(mode.Fundamental):
|
||||||
|
|
||||||
class Mbox(mode.Fundamental):
|
class Mbox(mode.Fundamental):
|
||||||
modename = 'Mbox'
|
modename = 'Mbox'
|
||||||
|
grammar = MailListGrammar
|
||||||
actions = [MboxRefresh, MboxOpenPath, MboxReadMsg]
|
actions = [MboxRefresh, MboxOpenPath, MboxReadMsg]
|
||||||
|
colors = {
|
||||||
|
'index': ('default', 'default', 'bold'),
|
||||||
|
'flag': ('yellow', 'default', 'bold'),
|
||||||
|
'month': ('green', 'default', 'bold'),
|
||||||
|
'dow': ('green', 'default', 'bold'),
|
||||||
|
'day': ('green', 'default', 'bold'),
|
||||||
|
'sender': ('default', 'default', 'bold'),
|
||||||
|
'size': ('cyan', 'default', 'bold'),
|
||||||
|
'subject': ('default', 'default', 'bold'),
|
||||||
|
}
|
||||||
def __init__(self, w):
|
def __init__(self, w):
|
||||||
mode.Fundamental.__init__(self, w)
|
mode.Fundamental.__init__(self, w)
|
||||||
self.add_bindings('mbox-refresh', ('C-c r',))
|
self.add_bindings('mbox-refresh', ('C-c r',))
|
||||||
|
|
Loading…
Reference in New Issue