branch : pmacs2
This commit is contained in:
moculus 2009-02-23 04:12:58 +00:00
parent 22e873833f
commit f89d94867f
1 changed files with 51 additions and 10 deletions

View File

@ -7,6 +7,8 @@ from buffer import Buffer
from method import Method, Argument, arg
import util
cont_re = re.compile(r' *\n *| +')
class LineGrammar(Grammar):
rules = [PatternRule(name=r'data', pattern=r'^.*\n$')]
@ -48,14 +50,19 @@ class MboxMsgBuffer(Buffer):
else:
return []
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 = [
'Delivered-To: ' + self.msg.get('delivered-to'),
'To: ' + self.msg.get('to'),
'From: ' + self.msg.get('from'),
'Subject: ' + self.msg.get('subject'),
'Date: ' + self.msg.get('date'),
'Delivered-To: ' + d['delivered-to'],
'To: ' + d['to'],
'From: ' + d['from'],
'Subject: ' + d['subject'],
'Date: ' + d['date'],
'',
]
lines.extend(self._get_msg_lines(self.msg))
return lines
def open(self):
@ -67,7 +74,8 @@ class MboxMsgBuffer(Buffer):
class MboxListBuffer(Buffer):
btype = 'mboxlist'
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_re2 = re.compile(r'^ *([^" ].*?) *< *(.+) *> *$')
@ -102,12 +110,14 @@ class MboxListBuffer(Buffer):
if m: return m.group(1), m.group(1)
m = self.from_re4.match(msg['from'])
if m: return m.group(2), m.group(1)
#return msg['from'], msg['from']
return 'unknown', 'unknown'
def _parse_date(self, msg):
fields = ['', '', '', '', '', '', '', '']
m = self.date_re1.match(msg['date'])
if m: return m.groups()
return ('', '', '', '', '', '', '', '')
if m:
fields = list(m.groups())
fields[1] = '%02d' % int(fields[1])
return fields
def _create_msg_dict(self, pos, msg):
d = {}
@ -129,6 +139,7 @@ class MboxListBuffer(Buffer):
for key in d:
if type(d[key]) == type(''):
d[key] = d[key].replace('\t', ' ')
d[key] = cont_re.sub(' ', d[key])
return d
def _get_lines(self):
@ -148,7 +159,7 @@ class MboxListBuffer(Buffer):
for msg in msgs:
d = self._create_msg_dict(pos, msg)
s = self.format % d
lines.append(s)
lines.append(s.rstrip())
pos += 1
return lines
@ -180,6 +191,25 @@ class MboxOpenPath(Method):
w.application.add_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):
modename = 'MboxMsg'
colors = {
@ -202,7 +232,18 @@ class MboxMsg(mode.Fundamental):
class Mbox(mode.Fundamental):
modename = 'Mbox'
grammar = MailListGrammar
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):
mode.Fundamental.__init__(self, w)
self.add_bindings('mbox-refresh', ('C-c r',))