本文整理汇总了Python中alot.db.envelope.Envelope.attach方法的典型用法代码示例。如果您正苦于以下问题:Python Envelope.attach方法的具体用法?Python Envelope.attach怎么用?Python Envelope.attach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类alot.db.envelope.Envelope
的用法示例。
在下文中一共展示了Envelope.attach方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: apply
# 需要导入模块: from alot.db.envelope import Envelope [as 别名]
# 或者: from alot.db.envelope.Envelope import attach [as 别名]
def apply(self, ui):
# look if this makes sense: do we have any accounts set up?
my_accounts = settings.get_accounts()
if not my_accounts:
ui.notify('no accounts set', priority='error')
return
# get message to forward if not given in constructor
if not self.message:
self.message = ui.current_buffer.get_selected_message()
mail = self.message.get_email()
envelope = Envelope()
if self.inline: # inline mode
# set body text
name, address = self.message.get_author()
timestamp = self.message.get_date()
qf = settings.get_hook('forward_prefix')
if qf:
quote = qf(name, address, timestamp, ui=ui, dbm=ui.dbman)
else:
quote = 'Forwarded message from %s (%s):\n' % (
name or address, timestamp)
mailcontent = quote
quotehook = settings.get_hook('text_quote')
if quotehook:
mailcontent += quotehook(self.message.accumulate_body())
else:
quote_prefix = settings.get('quote_prefix')
for line in self.message.accumulate_body().splitlines():
mailcontent += quote_prefix + line + '\n'
envelope.body = mailcontent
else: # attach original mode
# attach original msg
mail.set_type('message/rfc822')
mail['Content-Disposition'] = 'attachment'
envelope.attach(Attachment(mail))
# copy subject
subject = decode_header(mail.get('Subject', ''))
subject = 'Fwd: ' + subject
forward_subject_hook = settings.get_hook('forward_subject')
if forward_subject_hook:
subject = forward_subject_hook(subject)
else:
fsp = settings.get('forward_subject_prefix')
if not subject.startswith(('Fwd:', fsp)):
subject = fsp + subject
envelope.add('Subject', subject)
# set From
realname, address = recipient_to_from(mail, my_accounts)
envelope.add('From', '%s <%s>' % (realname, address))
# continue to compose
ui.apply_command(ComposeCommand(envelope=envelope,
spawn=self.force_spawn))
示例2: apply
# 需要导入模块: from alot.db.envelope import Envelope [as 别名]
# 或者: from alot.db.envelope.Envelope import attach [as 别名]
def apply(self, ui):
if not self.message:
self.message = ui.current_buffer.get_selected_message()
mail = self.message.get_email()
# set body text
name, address = self.message.get_author()
mailcontent = self.message.accumulate_body()
envelope = Envelope(bodytext=mailcontent)
# copy selected headers
to_copy = ['Subject', 'From', 'To', 'Cc', 'Bcc', 'In-Reply-To',
'References']
for key in to_copy:
value = decode_header(mail.get(key, ''))
if value:
envelope.add(key, value)
# copy attachments
for b in self.message.get_attachments():
envelope.attach(b)
ui.apply_command(ComposeCommand(envelope=envelope,
spawn=self.force_spawn,
omit_signature=True))
示例3: ComposeCommand
# 需要导入模块: from alot.db.envelope import Envelope [as 别名]
# 或者: from alot.db.envelope.Envelope import attach [as 别名]
class ComposeCommand(Command):
"""compose a new email"""
def __init__(self, envelope=None, headers={}, template=None,
sender=u'', subject=u'', to=[], cc=[], bcc=[], attach=None,
omit_signature=False, spawn=None, **kwargs):
"""
:param envelope: use existing envelope
:type envelope: :class:`~alot.db.envelope.Envelope`
:param headers: forced header values
:type header: doct (str->str)
:param template: name of template to parse into the envelope after
creation. This should be the name of a file in your
template_dir
:type template: str
:param sender: From-header value
:type sender: str
:param subject: Subject-header value
:type subject: str
:param to: To-header value
:type to: str
:param cc: Cc-header value
:type cc: str
:param bcc: Bcc-header value
:type bcc: str
:param attach: Path to files to be attached (globable)
:type attach: str
:param omit_signature: do not attach/append signature
:type omit_signature: bool
:param spawn: force spawning of editor in a new terminal
:type spawn: bool
"""
Command.__init__(self, **kwargs)
self.envelope = envelope
self.template = template
self.headers = headers
self.sender = sender
self.subject = subject
self.to = to
self.cc = cc
self.bcc = bcc
self.attach = attach
self.omit_signature = omit_signature
self.force_spawn = spawn
@inlineCallbacks
def apply(self, ui):
if self.envelope is None:
self.envelope = Envelope()
if self.template is not None:
# get location of tempsdir, containing msg templates
tempdir = settings.get('template_dir')
tempdir = os.path.expanduser(tempdir)
if not tempdir:
xdgdir = os.environ.get('XDG_CONFIG_HOME',
os.path.expanduser('~/.config'))
tempdir = os.path.join(xdgdir, 'alot', 'templates')
path = os.path.expanduser(self.template)
if not os.path.dirname(path): # use tempsdir
if not os.path.isdir(tempdir):
ui.notify('no templates directory: %s' % tempdir,
priority='error')
return
path = os.path.join(tempdir, path)
if not os.path.isfile(path):
ui.notify('could not find template: %s' % path,
priority='error')
return
try:
self.envelope.parse_template(open(path).read())
except Exception as e:
ui.notify(str(e), priority='error')
return
# set forced headers
for key, value in self.headers.items():
self.envelope.add(key, value)
# set forced headers for separate parameters
if self.sender:
self.envelope.add('From', self.sender)
if self.subject:
self.envelope.add('Subject', self.subject)
if self.to:
self.envelope.add('To', ','.join(self.to))
if self.cc:
self.envelope.add('Cc', ','.join(self.cc))
if self.bcc:
self.envelope.add('Bcc', ','.join(self.bcc))
# get missing From header
if not 'From' in self.envelope.headers:
accounts = settings.get_accounts()
if len(accounts) == 1:
a = accounts[0]
fromstring = "%s <%s>" % (a.realname, a.address)
#.........这里部分代码省略.........
示例4: apply
# 需要导入模块: from alot.db.envelope import Envelope [as 别名]
# 或者: from alot.db.envelope.Envelope import attach [as 别名]
def apply(self, ui):
# get message to forward if not given in constructor
if not self.message:
self.message = ui.current_buffer.get_selected_message()
mail = self.message.get_email()
envelope = Envelope()
if self.inline: # inline mode
# set body text
name, address = self.message.get_author()
timestamp = self.message.get_date()
qf = settings.get_hook('forward_prefix')
if qf:
quote = qf(name, address, timestamp, ui=ui, dbm=ui.dbman)
else:
quote = 'Forwarded message from %s (%s):\n' % (
name or address, timestamp)
mailcontent = quote
quotehook = settings.get_hook('text_quote')
if quotehook:
mailcontent += quotehook(self.message.accumulate_body())
else:
quote_prefix = settings.get('quote_prefix')
for line in self.message.accumulate_body().splitlines():
mailcontent += quote_prefix + line + '\n'
envelope.body = mailcontent
for a in self.message.get_attachments():
envelope.attach(a)
else: # attach original mode
# attach original msg
original_mail = Message()
original_mail.set_type('message/rfc822')
original_mail['Content-Disposition'] = 'attachment'
original_mail.set_payload(email_as_string(mail))
envelope.attach(Attachment(original_mail))
# copy subject
subject = decode_header(mail.get('Subject', ''))
subject = 'Fwd: ' + subject
forward_subject_hook = settings.get_hook('forward_subject')
if forward_subject_hook:
subject = forward_subject_hook(subject)
else:
fsp = settings.get('forward_subject_prefix')
if not subject.startswith(('Fwd:', fsp)):
subject = fsp + subject
envelope.add('Subject', subject)
# set From-header and sending account
try:
from_header, account = determine_sender(mail, 'reply')
except AssertionError as e:
ui.notify(e.message, priority='error')
return
envelope.add('From', from_header)
# continue to compose
ui.apply_command(ComposeCommand(envelope=envelope,
spawn=self.force_spawn))
示例5: ComposeCommand
# 需要导入模块: from alot.db.envelope import Envelope [as 别名]
# 或者: from alot.db.envelope.Envelope import attach [as 别名]
class ComposeCommand(Command):
"""compose a new email"""
def __init__(
self,
envelope=None,
headers={},
template=None,
sender=u"",
subject=u"",
to=[],
cc=[],
bcc=[],
attach=None,
omit_signature=False,
spawn=None,
rest=[],
**kwargs
):
"""
:param envelope: use existing envelope
:type envelope: :class:`~alot.db.envelope.Envelope`
:param headers: forced header values
:type headers: dict (str->str)
:param template: name of template to parse into the envelope after
creation. This should be the name of a file in your
template_dir
:type template: str
:param sender: From-header value
:type sender: str
:param subject: Subject-header value
:type subject: str
:param to: To-header value
:type to: str
:param cc: Cc-header value
:type cc: str
:param bcc: Bcc-header value
:type bcc: str
:param attach: Path to files to be attached (globable)
:type attach: str
:param omit_signature: do not attach/append signature
:type omit_signature: bool
:param spawn: force spawning of editor in a new terminal
:type spawn: bool
:param rest: remaining parameters. These can start with
'mailto' in which case it is interpreted as mailto string.
Otherwise it will be interpreted as recipients (to) header
:type rest: list(str)
"""
Command.__init__(self, **kwargs)
self.envelope = envelope
self.template = template
self.headers = headers
self.sender = sender
self.subject = subject
self.to = to
self.cc = cc
self.bcc = bcc
self.attach = attach
self.omit_signature = omit_signature
self.force_spawn = spawn
self.rest = " ".join(rest)
@inlineCallbacks
def apply(self, ui):
if self.envelope is None:
if self.rest:
if self.rest.startswith("mailto"):
self.envelope = mailto_to_envelope(self.rest)
else:
self.envelope = Envelope()
self.envelope.add("To", self.rest)
else:
self.envelope = Envelope()
if self.template is not None:
# get location of tempsdir, containing msg templates
tempdir = settings.get("template_dir")
tempdir = os.path.expanduser(tempdir)
if not tempdir:
xdgdir = os.environ.get("XDG_CONFIG_HOME", os.path.expanduser("~/.config"))
tempdir = os.path.join(xdgdir, "alot", "templates")
path = os.path.expanduser(self.template)
if not os.path.dirname(path): # use tempsdir
if not os.path.isdir(tempdir):
ui.notify("no templates directory: %s" % tempdir, priority="error")
return
path = os.path.join(tempdir, path)
if not os.path.isfile(path):
ui.notify("could not find template: %s" % path, priority="error")
return
try:
self.envelope.parse_template(open(path).read())
except Exception as e:
ui.notify(str(e), priority="error")
return
#.........这里部分代码省略.........