branch : pmacs2
This commit is contained in:
moculus 2008-11-11 00:55:13 +00:00
parent 27dc2bb89f
commit 6f64fedd7f
1 changed files with 56 additions and 11 deletions

View File

@ -1,10 +1,26 @@
import commands, dirutil, grp, mailbox, method, mode, os.path, pwd, re
import buffer, default, window
from mode.mutt import MuttGrammar
from lex import Grammar, PatternRule, RegionRule, PatternGroupRule
from point import Point
from buffer import Buffer
from method import Method, Argument, arg
class LineGrammar(Grammar):
rules = [PatternRule(name=r'data', pattern=r'^.*\n$')]
class MailMsgGrammar(Grammar):
rules = [
PatternRule(name=r'mail_pgp', pattern=r'^-----BEGIN PGP SIGNED MESSAGE-----\n$'),
RegionRule(r'mail_signature', r'^-----BEGIN PGP SIGNATURE-----\n$', LineGrammar, r'^-----END PGP SIGNATURE-----\n$'),
PatternRule(name=r'mail_header', pattern=r'^(?:From|To|Cc|Bcc|Subject|Reply-To|In-Reply-To|Delivered-To|Date):'),
PatternRule(name=r'mail_quoteb', pattern=r'^ *(?:(?: *>){3})*(?: *>){2}.*$'),
PatternRule(name=r'mail_quotea', pattern=r'^ *(?:(?: *>){3})*(?: *>){1}.*$'),
PatternRule(name=r'mail_quotec', pattern=r'^ *(?:(?: *>){3})*(?: *>){3}.*$'),
PatternRule(name=r'mail_email', pattern=r'(?:^|(?<=[ :]))<?[^<>@\n ]+@(?:[^<>@\.\n ]+\.)*[^<>@\.\n ]+>?'),
PatternRule(name=r'mail_url', pattern=r'(?:^|(?<= ))(?:http|https|ftp|sftp|file|smtp|smtps|torrent|news|jabber|irc|telnet)://(?:[^\.\n ]+\.)*[^\.\n ]+'),
]
class MboxMsgBuffer(Buffer):
btype = 'mboxmsg'
def __init__(self, path, lineno, msg):
@ -21,7 +37,16 @@ class MboxMsgBuffer(Buffer):
def save_as(self, path): raise Exception, "can't save an mbox message"
def name(self): return 'mbox:%s:%s' % (self.base, self.lineno)
def _get_lines(self):
return ['to', 'from', 'headers', 'subject', 'body']
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'),
'',
]
lines.extend(self.msg.get_payload().split('\n'))
return lines
def open(self):
self.lines = self._get_lines()
def reload(self):
@ -78,7 +103,13 @@ class MboxRefresh(Method):
w.buffer.reload()
class MboxOpenMsg(Method):
def _execute(self, w, **vargs):
w.set_error('your implementation here')
b = w.buffer
b = MboxMsgBuffer(b.path, w.cursor.y, b.mbox[w.cursor.y])
b.open()
window.Window(b, w.application, height=0, width=0, mode_name='mboxmsg')
w.application.add_buffer(b)
w.application.switch_buffer(b)
class MboxOpenPath(Method):
args = [arg('mbox', dt="path", p="Open Mbox: ", dv=default.path_dirname,
ld=True, h="mbox to open")]
@ -89,20 +120,34 @@ class MboxOpenPath(Method):
w.application.add_buffer(b)
w.application.switch_buffer(b)
class MboxMsg(mode.Fundamental):
modename = 'MboxMsg'
colors = {
'mail_pgp': ('red', 'default', 'bold'),
'mail_signature.start': ('red', 'default', 'bold'),
'mail_signature.data': ('red', 'default', 'bold'),
'mail_signature.null': ('red', 'default', 'bold'),
'mail_signature.end': ('red', 'default', 'bold'),
'mail_header': ('green', 'default', 'bold'),
'mail_email': ('cyan', 'default', 'bold'),
'mail_url': ('cyan', 'default', 'bold'),
'mail_quotea': ('yellow', 'default', 'bold'),
'mail_quoteb': ('cyan', 'default', 'bold'),
'mail_quotec': ('magenta', 'default', 'bold'),
}
actions = []
grammar = MailMsgGrammar
def __init__(self, w):
mode.Fundamental.__init__(self, w)
class Mbox(mode.Fundamental):
modename = 'Mbox'
colors = {}
actions = [MboxRefresh, MboxOpenPath, MboxOpenMsg]
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('mbox-refresh', ('C-c r',))
self.add_bindings('mbox-open-msg', ('RETURN',))
#self.add_bindings('open-path', ('RETURN',))
#self.add_bindings('dir-grep', ('C-c G',))
#self.add_bindings('chmod', ('C-c m',))
#self.add_bindings('chown', ('C-c o',))
#self.add_bindings('chgrp', ('C-c g',))
#self.add_bindings('touch-path', ('C-c t',))
#self.add_bindings('remove-path', ('DELETE', 'BACKSPACE', 'C-d'))
install = Mbox.install
def install(*args):
Mbox.install(*args)
MboxMsg.install(*args)