Skip to content

Commit

Permalink
Merge branch '0.3.6-feature-list-replies-793'
Browse files Browse the repository at this point in the history
  • Loading branch information
pazz committed Dec 16, 2015
2 parents 13295e3 + ef47ffb commit 0e92e66
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
35 changes: 34 additions & 1 deletion alot/commands/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,29 @@ def determine_sender(mail, action='reply'):

@registerCommand(MODE, 'reply', arguments=[
(['--all'], {'action': 'store_true', 'help': 'reply to all'}),
(['--list'], {'action': BooleanAction, 'default': None,
'dest': 'listreply', 'help': 'reply to list'}),
(['--spawn'], {'action': BooleanAction, 'default': None,
'help': 'open editor in new window'})])
class ReplyCommand(Command):

"""reply to message"""
repeatable = True

def __init__(self, message=None, all=False, spawn=None, **kwargs):
def __init__(self, message=None, all=False, listreply=None, spawn=None, **kwargs):
"""
:param message: message to reply to (defaults to selected message)
:type message: `alot.db.message.Message`
:param all: group reply; copies recipients from Bcc/Cc/To to the reply
:type all: bool
:param listreply: reply to list; autodetect if unset and enabled in config
:type listreply: bool
:param spawn: force spawning of editor in a new terminal
:type spawn: bool
"""
self.message = message
self.groupreply = all
self.listreply = listreply
self.force_spawn = spawn
Command.__init__(self, **kwargs)

Expand Down Expand Up @@ -162,6 +167,17 @@ def apply(self, ui):
subject = rsp + subject
envelope.add('Subject', subject)

# Auto-detect ML
auto_replyto_mailinglist = settings.get('auto_replyto_mailinglist')
if mail['List-Id'] and self.listreply == None:
# mail['List-Id'] is need to enable reply-to-list
self.listreply = auto_replyto_mailinglist
elif mail['List-Id'] and self.listreply == True:
self.listreply = True
elif self.listreply == False:
# In this case we only need the sender
self.listreply = False

# set From-header and sending account
try:
from_header, account = determine_sender(mail, 'reply')
Expand Down Expand Up @@ -212,6 +228,23 @@ def apply(self, ui):

to = ', '.join(recipients)
logging.debug('reply to: %s' % to)

if self.listreply:
# To choose the target of the reply --list
# Reply-To is standart reply target RFC 2822:, RFC 1036: 2.2.1
# X-BeenThere is needed by sourceforge ML also winehq
# X-Mailing-List is also standart and is used by git-send-mail
to = mail['Reply-To'] or mail['X-BeenThere'] or mail['X-Mailing-List']
# Some mail server (gmail) will not resend you own mail, so you have
# to deal with the one in sent
if to is None:
to = mail['To']
logging.debug('mail list reply to: %s' % to)
# Cleaning the 'To' in this case
if envelope.get('To') is not None:
envelope.__delitem__('To')

# Finally setup the 'To' header
envelope.add('To', decode_header(to))

# if any of the recipients is a mailinglist that we are subscribed to,
Expand Down
3 changes: 3 additions & 0 deletions alot/defaults/alot.rc.spec
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ followup_to = boolean(default=False)
# The list of addresses associated to the mailinglists you are subscribed to
mailinglists = force_list(default=list())

# Automatically switch to list reply mode if appropriate
auto_replyto_mailinglist = boolean(default=False)

# prefer plaintext alternatives over html content in multipart/alternative
prefer_plaintext = boolean(default=False)

Expand Down
10 changes: 10 additions & 0 deletions docs/source/configuration/alotrc_table
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@
:default: True


.. _auto_replyto_mailinglist:

.. describe:: auto_replyto_mailinglist

Automatically switch to list reply mode if appropriate

:type: boolean
:default: False


.. _bufferclose-focus-offset:

.. describe:: bufferclose_focus_offset
Expand Down
1 change: 1 addition & 0 deletions docs/source/usage/modes/thread.rst
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ The following commands are available in thread mode

optional arguments
:---all: reply to all.
:---list: reply to list.
:---spawn: open editor in new window.

.. _cmd.thread.save:
Expand Down

0 comments on commit 0e92e66

Please sign in to comment.