* how to write interactive hook @ 2014-09-14 18:07 Ruthard Baudach 2014-09-17 18:46 ` [sup] " Matthieu Rakotojaona ` (3 more replies) 0 siblings, 4 replies; 13+ messages in thread From: Ruthard Baudach @ 2014-09-14 18:07 UTC (permalink / raw) To: supmua [-- Attachment #1: Type: text/plain, Size: 563 bytes --] Dear list, I'd like to activate the signature hook. I have got two email addresses that I put for both private colloquial and privat formal use as well as occasional professional use. Therefor I have to base the signature of the mail currently composed on the content of the mail and not on the From: header. But how can I write an interactive hook? puts puts a string in the status line, but gets crashes the hook I'd like to have a prompt: Choose signature [1* 2 3 4] and to be able to enter the appropriate key to choose Yours, Ruthard [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 473 bytes --] ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [sup] how to write interactive hook 2014-09-14 18:07 how to write interactive hook Ruthard Baudach @ 2014-09-17 18:46 ` Matthieu Rakotojaona 2014-09-18 5:51 ` Gaute Hope 2014-09-18 17:46 ` Ruthard Baudach 2014-09-18 9:34 ` Eric Weikl ` (2 subsequent siblings) 3 siblings, 2 replies; 13+ messages in thread From: Matthieu Rakotojaona @ 2014-09-17 18:46 UTC (permalink / raw) To: supmua [-- Attachment #1: Type: text/plain, Size: 2317 bytes --] Excerpts from Ruthard Baudach's message of 2014-09-14 20:07:27 +0200: > Dear list, > > I'd like to activate the signature hook. I have got two email addresses > that I put for both private colloquial and privat formal use as well as occasional > professional use. > > Therefor I have to base the signature of the mail currently composed on > the content of the mail and not on the From: header. > > But how can I write an interactive hook? > > puts puts a string in the status line, but gets crashes the hook > > I'd like to have a prompt: > Choose signature [1* 2 3 4] > and to be able to enter the appropriate key to choose > > Yours, Ruthard Hello, I'm afraid you're not going to be able to do this with a hook; you're gonna have to change the core of sup. At a quick glance, the most straightforward thing for you to do is to play with the selectors in edit_message_mode; these are the choices you get at the top of the mode. See @account_selector and @crypto_selector in edit_message_mode.initialize. What you can do is add a @signature_selector, displaying all possible signatures associated to your account and allowing you to choose the one you want. You'll certainly have to then re-call edit_message_mode.sig_lines depending on the choice you make, and maybe other parts in edit_message_mode too. From a config point of view, here's what you'd have to change: - add a "signatures" setting, with a folder that has a list of files; each file would contain a different signature and the selector I mentioned earlier will offer a choice between file names: $ head ~/.config/sup/signatures/* ==> work <== Serious Business Inc. ==> family <== Matthieu Rakotojaona ==> friends <== rakoo This particular setting would give me a choice between "work", "family" and "friends" when editing a message - keep a possibilty to set a "signature" in the account for backwards compatibility (and people with only 1 signature) Good luck ! (Also random idea, slightly related to the subject: if neither signature nor signatures is specified in the account, put a default signature that contains the name of the user as specified in the account ? That default sounds reasonable enough to me) -- Matthieu Rakotojaona [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 949 bytes --] ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [sup] how to write interactive hook 2014-09-17 18:46 ` [sup] " Matthieu Rakotojaona @ 2014-09-18 5:51 ` Gaute Hope 2014-09-18 17:46 ` Ruthard Baudach 1 sibling, 0 replies; 13+ messages in thread From: Gaute Hope @ 2014-09-18 5:51 UTC (permalink / raw) To: supmua Excerpts from Matthieu Rakotojaona's message of September 17, 2014 20:46: > I'm afraid you're not going to be able to do this with a hook; you're > gonna have to change the core of sup. Doesn't the 'ask_yes_no' methods work from a hook? - gaute ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [sup] how to write interactive hook 2014-09-17 18:46 ` [sup] " Matthieu Rakotojaona 2014-09-18 5:51 ` Gaute Hope @ 2014-09-18 17:46 ` Ruthard Baudach 2014-09-18 18:58 ` Gaute Hope 1 sibling, 1 reply; 13+ messages in thread From: Ruthard Baudach @ 2014-09-18 17:46 UTC (permalink / raw) To: supmua [-- Attachment #1: Type: text/plain, Size: 225 bytes --] Thanks everybody! for the moment, I do not have the leisure to hack on sup, but look forward to digest the suggestions. By the way – how could I log in to the wiki if I wanted to contribute? Greetings Ruthard [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 473 bytes --] ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [sup] how to write interactive hook 2014-09-18 17:46 ` Ruthard Baudach @ 2014-09-18 18:58 ` Gaute Hope 0 siblings, 0 replies; 13+ messages in thread From: Gaute Hope @ 2014-09-18 18:58 UTC (permalink / raw) To: supmua, Ruthard Baudach Excerpts from Ruthard Baudach's message of September 18, 2014 19:46: > Thanks everybody! > > for the moment, I do not have the leisure to hack on sup, but look > forward to digest the suggestions. > > By the way – how could I log in to the wiki if I wanted to contribute? You should be able to edit it with a regular github account. If you don't want to make an account you can clone the wiki [0], and send a patch to this mailing list. - gaute [0] git@github.com:sup-heliotrope/sup.wiki.git ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [sup] how to write interactive hook 2014-09-14 18:07 how to write interactive hook Ruthard Baudach 2014-09-17 18:46 ` [sup] " Matthieu Rakotojaona @ 2014-09-18 9:34 ` Eric Weikl 2014-09-18 20:06 ` Ruthard Baudach 2014-09-18 20:15 ` Ruthard Baudach 3 siblings, 0 replies; 13+ messages in thread From: Eric Weikl @ 2014-09-18 9:34 UTC (permalink / raw) To: Ruthard Baudach; +Cc: supmua Hi Ruthard, On 09/14/2014 20:07:27, Ruthard Baudach wrote: > But how can I write an interactive hook? As Gaute pointed out, you can prompt the user for information using the BufferManager methods like ask_yes_no or ask_many_with_completions. I use this for a primitive follow-up hook. You can get the idea from this gist: https://gist.github.com/anonymous/b1c2beb9ccddd2787e12 It's not perfect and I'm happy if anyone has ideas for improvement, BTW :-) Cheers, Eric ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: how to write interactive hook 2014-09-14 18:07 how to write interactive hook Ruthard Baudach 2014-09-17 18:46 ` [sup] " Matthieu Rakotojaona 2014-09-18 9:34 ` Eric Weikl @ 2014-09-18 20:06 ` Ruthard Baudach 2014-09-18 20:15 ` Ruthard Baudach 3 siblings, 0 replies; 13+ messages in thread From: Ruthard Baudach @ 2014-09-18 20:06 UTC (permalink / raw) To: supmua [-- Attachment #1: Type: text/plain, Size: 592 bytes --] Dear list, I put together the following minimal signature.rb: --------->%-------------- # signature.rb -- generate signature signature = BufferManager.ask_many_with_completions :sign, "Choose signature: ", ["One","Two","Three"] 'Signature: ' + signature --------->%-------------- It works -- but the hook seems to be called 1) when entering compose mode 2) each time the external editor is called 3) and 4) two times after the external editor closed. So I have to choose my signature four times! Has anybody an idea what to do about this? Greetings, Ruthard [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 473 bytes --] ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: how to write interactive hook 2014-09-14 18:07 how to write interactive hook Ruthard Baudach ` (2 preceding siblings ...) 2014-09-18 20:06 ` Ruthard Baudach @ 2014-09-18 20:15 ` Ruthard Baudach 2014-09-18 21:10 ` [sup] " Gaute Hope 3 siblings, 1 reply; 13+ messages in thread From: Ruthard Baudach @ 2014-09-18 20:15 UTC (permalink / raw) To: supmua [-- Attachment #1: Type: text/plain, Size: 731 bytes --] Dear list, I put together the following minimal hook: ------------>%------------- # signature.rb -- generate signature signature = BufferManager.ask_many_with_completions :sign, "Choose signature: ", ["One","Two","Three"] 'Signature: ' + signature ------------>%------------- Works, but the hook seems to be called – or at least ask_many_with_completions asks when 1) sup enters compose mode 2) sup calls the external editor 3)4) two times when sup regains control – only the second answer is attached to compose-mode text 5) after initializing sendmail by hitting y So I have to choose the signature 5 times! Has anybody an idea about that? Greetings, Ruthard -- Signature: Two [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 473 bytes --] ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [sup] Re: how to write interactive hook 2014-09-18 20:15 ` Ruthard Baudach @ 2014-09-18 21:10 ` Gaute Hope 2014-09-19 18:41 ` Ruthard Baudach 0 siblings, 1 reply; 13+ messages in thread From: Gaute Hope @ 2014-09-18 21:10 UTC (permalink / raw) To: supmua, Ruthard Baudach Excerpts from Ruthard Baudach's message of September 18, 2014 22:15: > Works, but the hook seems to be called – or at least > ask_many_with_completions asks when > > 1) sup enters compose mode > 2) sup calls the external editor > 3)4) two times when sup regains control – only the second answer is > attached to compose-mode text > 5) after initializing sendmail by hitting y It is probably called every time the message needs to be generated. If you could figure out a way to save the state for the message then you could just return the previously selected one on the subsequent calls. - gaute ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [sup] Re: how to write interactive hook 2014-09-18 21:10 ` [sup] " Gaute Hope @ 2014-09-19 18:41 ` Ruthard Baudach 2014-09-21 17:20 ` Gaute Hope 0 siblings, 1 reply; 13+ messages in thread From: Ruthard Baudach @ 2014-09-19 18:41 UTC (permalink / raw) To: supmua [-- Attachment #1: Type: text/plain, Size: 1524 bytes --] >== Auszüge aus der Nachricht von Gaute Hope vom 2014-09-18 23:10: > Excerpts from Ruthard Baudach's message of September 18, 2014 22:15: > > Works, but the hook seems to be called – or at least > > ask_many_with_completions asks when > > > > 1) sup enters compose mode > > 2) sup calls the external editor > > 3)4) two times when sup regains control – only the second answer is > > attached to compose-mode text > > 5) after initializing sendmail by hitting y > > It is probably called every time the message needs to be generated. If > you could figure out a way to save the state for the message then you > could just return the previously selected one on the subsequent calls. For sure. At the moment my drafted solution is: ----------->%-------------------- # signature.rb -- generate signature unless $signature $signature = BufferManager.ask_many_with_completions :sign, "Choose signature: ", ["One","Two","Three"] end 'Signature: ' + $signature ----------->%-------------------- # sendemail.rb – send mail $signature = nil IO.popen(account.sendmail, "w:UTF-8") { |p| p.puts message } if $? return true else return false end ----------->%-------------------- Now I just needed a discard-message and a safe-draft hook to set the signature to nil in these cases, and everything was fine! I'm afraid I have to tackle sup core code to get this working. I'll report back if I get it to work, Happy supping, Ruthard -- Signature: One [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 473 bytes --] ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [sup] Re: how to write interactive hook 2014-09-19 18:41 ` Ruthard Baudach @ 2014-09-21 17:20 ` Gaute Hope 2014-10-01 20:46 ` Ruthard Baudach 0 siblings, 1 reply; 13+ messages in thread From: Gaute Hope @ 2014-09-21 17:20 UTC (permalink / raw) To: supmua Excerpts from Ruthard Baudach's message of September 19, 2014 20:41: >>== Auszüge aus der Nachricht von Gaute Hope vom 2014-09-18 23:10: >> Excerpts from Ruthard Baudach's message of September 18, 2014 22:15: >> > Works, but the hook seems to be called – or at least >> > ask_many_with_completions asks when >> > >> > 1) sup enters compose mode >> > 2) sup calls the external editor >> > 3)4) two times when sup regains control – only the second answer is >> > attached to compose-mode text >> > 5) after initializing sendmail by hitting y >> >> It is probably called every time the message needs to be generated. If >> you could figure out a way to save the state for the message then you >> could just return the previously selected one on the subsequent calls. > > For sure. > > At the moment my drafted solution is: > > ----------->%-------------------- > # signature.rb -- generate signature > > unless $signature > $signature = BufferManager.ask_many_with_completions :sign, "Choose signature: ", ["One","Two","Three"] > end > 'Signature: ' + $signature > ----------->%-------------------- > # sendemail.rb – send mail > > $signature = nil > > IO.popen(account.sendmail, "w:UTF-8") { |p| p.puts message } > if $? > return true > else > return false > end > ----------->%-------------------- > > Now I just needed a discard-message and a safe-draft hook to set the > signature to nil in these cases, and everything was fine! > > I'm afraid I have to tackle sup core code to get this working. I'll > report back if I get it to work, Setting up new hooks is not too complicated, have a look at some of the existing. Another option is to pass the message id (if it is persistent) to the signature hook, then when the message id changes you reset the hook state. I'm a bit reluctant to add new hooks for very seldomly used purposes, but the ones you describe above might be worth it. Cheers, Gaute ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [sup] Re: how to write interactive hook 2014-09-21 17:20 ` Gaute Hope @ 2014-10-01 20:46 ` Ruthard Baudach 2014-10-06 12:05 ` Gaute Hope 0 siblings, 1 reply; 13+ messages in thread From: Ruthard Baudach @ 2014-10-01 20:46 UTC (permalink / raw) To: supmua [-- Attachment #1.1: Type: text/plain, Size: 2397 bytes --] >== Auszüge aus der Nachricht von Gaute Hope vom 2014-09-21 19:20: > > Another option is to pass the message id (if it is persistent) to the > signature hook, then when the message id changes you reset the hook > state. Great idea! I managed to do so -- see attached patch. If you would decide to add this to main sup, I would publish my signature hook in the wiki. Best regards, Ruthard it works :-) vvv see down here vvv -- Dr. Ruthard Baudach Speckertsweg 36a 97209 Veitshöchheim ---- Emails sind Postkarten! Deshalb bitte Emails verschlüsseln und signieren. Mein öffentlicher Schlüssel: -----BEGIN PGP PUBLIC KEY BLOCK----- Version: GnuPG v2 mQENBFPcu+kBCADC5zwexQDbXfuv7fH4epJ6EJSqYPMzm867YHZZBiYO0EQPgXFp MBFEMRz0/HX8Roi3oeQNA01Bo4J6HzxcOqDXHLMQBfbiOsaQZFm73TotZUNDB9b6 kPTHFY33fnoJbTf9lcD8sOM4lZBcFKRumIKJP+IKhN2PFml0nTMBGoWgjmK/xP5F 7SvZO+Hy9uLvnzPMTTURrpUhJPba6mhPzX+IrDd6EfollXHk5aeYJ/b+XRFmWHPm B3HemLigYDMcvW2zzpK0cmGcxaBWE5pmguhYywibyP5AMsUQCgOfWLW/OCm8QWoL E3TMvWEc2luJT4FZ8jLbK5CWhdCvlqjwsbqhABEBAAG0KFJ1dGhhcmQgQmF1ZGFj aCA8cnV0aGFyZC5iYXVkYWNoQHdlYi5kZT6JAT8EEwECACkFAlPcu+kCGwMFCQPC ZwAHCwkIBwMCAQYVCAIJCgsEFgIDAQIeAQIXgAAKCRAPOdocrFrGwun0CACvTa7Q FFm8J7B+kbnkM96Yj+jtLofrU+JACOGstXfydINYIEjEzsgLAPII7qLjKhhIPTXJ L383WpKZn/xU4+zcTd88VeTUbyGsao2Xt2l+wbZBzmX73YDDU0FWLGfGwHZKs+EZ NxQbWXf0fDL83etm3Ti9YMOIUVJujMitKEzjt6R4l/cOvIp5oh/dZUTypzV6WKmP lrub6Jize504bOHgUH8G75YHkUoCdLhEnvAMuRB8cB1k6rxgSF2BmV+CRoh9kE6x 4z0HfPO6yfjWAhqx0vcoaS7TIZF6AbSHrvx3UsbmbiNZUGh4YzB9Y7ixMT4mrb/J tff0mrsDKmB7luJ3uQENBFPcu+kBCAC9uPwimGEkwmhs5zYpSQDrZfW0Oh7POTCB wv0KfaOCS9uIPe7KGT7yN40AL8W6v2MM3VK4tolcRv5tYqwV8Rz6LFMgZlAmrdsN wGuvs+pEb4xJ3AEN1gvos9fuI0Z/jzu/9LrzZIZbVK/8yNyRJ7rlUmaqErrxhNka T+I9XeLZZznp0r+1WE31sGToqYkph6UYgjV+qwRA4+D35T0J4txJrJeIOTYusCV+ uzTT3+Th6X12d6jLbpcNOeinOEB0CG+bITAIXy6tVC3H1Xqfp/T2f49BswEBhwyS +ZxWZLcxNnP69xG2ErnpQ39swUiHroQOjRggzJKFZQqFQWlk5P/FABEBAAGJASUE GAECAA8FAlPcu+kCGwwFCQPCZwAACgkQDznaHKxaxsIuzAgAhL0fNfBvU9Guaznj P27YWIwP1YYPBfGigeWNRssOipanHwc1r2epLsUByTnUagEnuz18RRIIAb4TOOSG uT7eXPTv6uh6Ok4Zk1WDG8mPHT4mqEbTvjzyfg+6dnOJ0BymgN4R410mULkbWOT1 hA50eG/yf0DvdtpJWNhXPo+fU1vb05kpi9OP56Ymz68rUQOc7k0qxOj6ic0Jju84 um6LZeHInFLUj6ZF+yeGNkBS+bD4gaQ4qp1z3kbVysO0ZEr1D/fb0GO0sDklhXJL nZrtuX6lfMsSdH1tbeeMGclaknL15iGdnv8b2Z+7cIO82qJmcfbdSYcfNC2KJHZn Nc2DAQ== =EfIc -----END PGP PUBLIC KEY BLOCK----- [-- Attachment #1.2: 0001-ge-ndert-lib-sup-modes-edit_message_mode.rb.patch --] [-- Type: application/octet-stream, Size: 1673 bytes --] From dc36797a150c8e94589fcaea9aa556feddfe8205 Mon Sep 17 00:00:00 2001 From: Ruthard Baudach <rthrd@web.de> Date: Wed, 1 Oct 2014 22:21:24 +0200 Subject: [PATCH] =?UTF-8?q?=09ge=C3=A4ndert:=20=20=20=20=20=20=20lib/sup/m?= =?UTF-8?q?odes/edit=5Fmessage=5Fmode.rb=20=09=09=09pass=20message=5Fid=20?= =?UTF-8?q?to=20signature=20hook?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/sup/modes/edit_message_mode.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/sup/modes/edit_message_mode.rb b/lib/sup/modes/edit_message_mode.rb index 2b8b590..57f75aa 100644 --- a/lib/sup/modes/edit_message_mode.rb +++ b/lib/sup/modes/edit_message_mode.rb @@ -19,7 +19,8 @@ Variables: header: an object that supports string-to-string hashtable-style access to the raw headers for the message. E.g., header["From"], header["To"], etc. - from_email: the email part of the From: line, or nil if empty + from_email: the email part of the From: line, or nil if empty + message_id: the unique message id of the message Return value: A string (multi-line ok) containing the text of the signature, or nil to use the default signature, or :none for no signature. @@ -688,7 +689,7 @@ private from_email = p && p.email ## first run the hook - hook_sig = HookManager.run "signature", :header => @header, :from_email => from_email + hook_sig = HookManager.run "signature", :header => @header, :from_email => from_email, :message_id => @message_id return [] if hook_sig == :none return ["", "-- "] + hook_sig.split("\n") if hook_sig -- 2.1.0 [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 473 bytes --] ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [sup] Re: how to write interactive hook 2014-10-01 20:46 ` Ruthard Baudach @ 2014-10-06 12:05 ` Gaute Hope 0 siblings, 0 replies; 13+ messages in thread From: Gaute Hope @ 2014-10-06 12:05 UTC (permalink / raw) To: supmua, Ruthard Baudach Excerpts from Ruthard Baudach's message of October 1, 2014 22:46: >>== Auszüge aus der Nachricht von Gaute Hope vom 2014-09-21 19:20: >> >> Another option is to pass the message id (if it is persistent) to the >> signature hook, then when the message id changes you reset the hook >> state. > > Great idea! I managed to do so -- see attached patch. > If you would decide to add this to main sup, I would publish my > signature hook in the wiki. Thanks, this patch has been applied. Cheers, Gaute ^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2014-10-06 12:04 UTC | newest] Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2014-09-14 18:07 how to write interactive hook Ruthard Baudach 2014-09-17 18:46 ` [sup] " Matthieu Rakotojaona 2014-09-18 5:51 ` Gaute Hope 2014-09-18 17:46 ` Ruthard Baudach 2014-09-18 18:58 ` Gaute Hope 2014-09-18 9:34 ` Eric Weikl 2014-09-18 20:06 ` Ruthard Baudach 2014-09-18 20:15 ` Ruthard Baudach 2014-09-18 21:10 ` [sup] " Gaute Hope 2014-09-19 18:41 ` Ruthard Baudach 2014-09-21 17:20 ` Gaute Hope 2014-10-01 20:46 ` Ruthard Baudach 2014-10-06 12:05 ` Gaute Hope
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox