Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

confirm send w/o attachment #395

Closed
pazz opened this issue Mar 6, 2012 · 11 comments
Closed

confirm send w/o attachment #395

pazz opened this issue Mar 6, 2012 · 11 comments

Comments

@pazz
Copy link
Owner

pazz commented Mar 6, 2012

if keyword "attach" matches the body text.
this should be configurable.

the best solution that comes to mind is to put this into envelope.SendCommand and use ui.choice like
globals.ExitCommand does.

@ghost
Copy link

ghost commented Mar 8, 2012

I think you should have this multilingual. So a word list in most common languages could address more users.

@pazz
Copy link
Owner Author

pazz commented Mar 8, 2012

eventually i would also like to use gettext or so to internationalize all strings used in the ui.
but that's really not a priority

@josch
Copy link
Contributor

josch commented Feb 15, 2013

+1 for this feature

sup saved me countless times from sending emails without attachments

is there a way to use hooks right now for a similar functionality?

@pazz
Copy link
Owner Author

pazz commented Feb 15, 2013

Quoting josch (2013-02-15 07:18:23)

+1 for this feature

sup saved me countless times from sending emails without attachments

is there a way to use hooks right now for a similar functionality?


Reply to this email directly or view it on GitHub.

Well, you can use the pre_envelope_send hook, inspect the envelope (ui.current_buffer.envelope)
and use ui.notify to complain and rise an exception. this will keep alot from executing the main
part of the Command, which would be sendout.

But consider sending a pull request if you have the code, so we can add it as default feature..
/p

@josch
Copy link
Contributor

josch commented Feb 15, 2013

I tried that using a ui.choice in the end which asks whether one really wants to send the email or not.

Unfortunately it seems that ui.choice works asynchronously and the envelope_send is executed in the background anyways? How to prevent this?

@pazz
Copy link
Owner Author

pazz commented Feb 15, 2013

Quoting josch (2013-02-15 11:39:58)

I tried that using a ui.choice in the end which asks whether one really wants
to send the email or not.

Unfortunately it seems that ui.choice works asynchronously and the
envelope_send is executed in the background anyways? How to prevent this?

ah yes: I'd have to investigate this further but it could be that
the hooks are assumed to be syncronous code.
If thats the case, you could hack around the problem by overwriting
the SendCommand and put your stuff in its .apply() method.
but a cleaner way of resolving this should be
to allow hooks to be Deferreds also.

The relevant code should be in ui.py, in UI.apply_command somewhere.
Sorry for the vague info here, I don't have much time to spend atm :/

pazz added a commit that referenced this issue Feb 20, 2013
also, with this a pre-command-hook can cancel the further
execution of the command by raising an Exception.

cf. issue #395
@pazz
Copy link
Owner Author

pazz commented Feb 20, 2013

the linked commit fixes the issue with asynchronous post/pre hooks.
its in branch 0.3.4-feature-hooks-563 and already pushed to testing.

with this you can implemented the "send w/o attachment?" feature as a hook e.g. like this:

from twisted.internet.defer import inlineCallbacks
import re

@inlineCallbacks
def pre_envelope_send(ui, dbm):
    e = ui.current_buffer.envelope
    if re.match('.*[Aa]ttach', e.body, re.DOTALL) and\
       not e.attachments:
        msg = 'no attachments. send anyway?'
        if not (yield ui.choice(msg, select='yes')) == 'yes':
            raise Exception()

@pazz pazz closed this as completed Feb 22, 2013
@josch
Copy link
Contributor

josch commented Feb 14, 2020

The code you suggest doesn't work anymore:

ERROR:ui:Traceback (most recent call last):
  File "/usr/share/alot/alot/ui.py", line 272, in apply_commandline
    await apply_this_command(c)
  File "/usr/share/alot/alot/ui.py", line 713, in apply_command
    await cmd.prehook(ui=self, dbm=self.dbman, cmd=cmd)
  File "/home/josch/.config/alot/hooks.py", line 17, in pre_envelope_send
    if re.match('.*[Aa]ttach', e.body, re.DOTALL) and\
AttributeError: 'Envelope' object has no attribute 'body'

@pazz
Copy link
Owner Author

pazz commented Feb 14, 2020 via email

@josch
Copy link
Contributor

josch commented Feb 14, 2020

Yes, body_txt and body_html. I assume one now has to check both parts for this kind of hook or is there a more convenient way?

@pazz
Copy link
Owner Author

pazz commented Feb 14, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants