Gnus development mailing list
 help / color / mirror / Atom feed
* sending messages from script/command line
@ 2013-06-28 15:40 lee
  2013-07-01 12:40 ` Ted Zlatanov
  0 siblings, 1 reply; 9+ messages in thread
From: lee @ 2013-06-28 15:40 UTC (permalink / raw)
  To: ding

Hi,

is there a way to send messages from a script using the posting style of
a particular group?  Like

  emacsclient -e "(gnus-group-mail 1)"

works fine, only it doesn't let me specify which group to use and emacs
asks me.

Hmm ...

For what it's worth, I copied the defun and modified it:


(defun my-gnus-group-mail (arg)
  "Start composing a mail.
Use the group given in ARG to find a posting style."
  (interactive "P")
  ;; We can't `let' gnus-newsgroup-name here, since that leads
  ;; to local variables leaking.
  (let ((group gnus-newsgroup-name)
	;; make sure last viewed article doesn't affect posting styles:
	(gnus-article-copy)
	(buffer (current-buffer)))
    (unwind-protect
	(progn
	  (setq gnus-newsgroup-name arg)
	  ;; #### see comment in gnus-setup-message -- drv
	  (gnus-setup-message 'message (message-mail)))
      (with-current-buffer buffer
	(setq gnus-newsgroup-name group)))))


This might not be as it should be, but it seems to work:

  emacsclient -e '(my-gnus-group-mail "particular.group.name")'

Maybe there's a better (already built-in) way to do this?


Since I am at this:  This only works when gnus has already been started.
What would I do to make sure that it's started if it isn't?  Is there a
way to check whether gnus is running from the command line/script, or
could/should I write a wrapper around 'my-gnus-group-mail that starts
gnus in case it's not started already?

Maybe I should add that I'm not actually "composing" a mail with this:
Headers and body are read from files and I just need to take a look at
the mail and sometimes make a little change to it before actually
sending it.

Hmmm ... Can posting styles be specified on the command line?  Having
/one fixed/ posting style for a group isn't ideal in my case; I could
use something like being asked "Which of the posting styles for this
group would you like to use?" in some cases --- and/or be able to
specify them on the command line.

Perhaps I need to write a wrapper function that resets the posting-style
from what's in ~/.gnus to what I need?  Could I just add something like

(setq posting-style (signature "something else"))

to 'my-gnus-group-mail?  (This is probably wrong; I'm really not good
with elisp ...)


-- 
"Object-oriented programming languages aren't completely convinced that
you should be allowed to do anything with functions."
http://www.joelonsoftware.com/items/2006/08/01.html



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: sending messages from script/command line
  2013-06-28 15:40 sending messages from script/command line lee
@ 2013-07-01 12:40 ` Ted Zlatanov
  2013-07-02  9:48   ` lee
  0 siblings, 1 reply; 9+ messages in thread
From: Ted Zlatanov @ 2013-07-01 12:40 UTC (permalink / raw)
  To: ding

On Fri, 28 Jun 2013 17:40:25 +0200 lee <lee@yun.yagibdah.de> wrote: 

l> is there a way to send messages from a script using the posting style of
l> a particular group?  Like

l>   emacsclient -e "(gnus-group-mail 1)"

l> works fine, only it doesn't let me specify which group to use and emacs
l> asks me.
...
l> This might not be as it should be, but it seems to work:

l>   emacsclient -e '(my-gnus-group-mail "particular.group.name")'

l> Maybe there's a better (already built-in) way to do this?

There's no built-in way to do what you describe, so your function is
probably the best solution.

l> Since I am at this:  This only works when gnus has already been started.
l> What would I do to make sure that it's started if it isn't?  Is there a
l> way to check whether gnus is running from the command line/script, or
l> could/should I write a wrapper around 'my-gnus-group-mail that starts
l> gnus in case it's not started already?

Since Gnus is not a daemon, it's hard to do what you describe.  Gnus is
more like a set of functions that agree upon the same buffer formats :)

So the simplest way, probably, is to give some advice to the `gnus'
function and to the `q' keybinding in the Group buffer.  You can also
look at the `gnus-slave' stuff but that's opportunistic and not stateful.

Ted




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: sending messages from script/command line
  2013-07-01 12:40 ` Ted Zlatanov
@ 2013-07-02  9:48   ` lee
  2013-07-02 15:35     ` Ted Zlatanov
  0 siblings, 1 reply; 9+ messages in thread
From: lee @ 2013-07-02  9:48 UTC (permalink / raw)
  To: ding

Ted Zlatanov <tzz@lifelogs.com> writes:

> On Fri, 28 Jun 2013 17:40:25 +0200 lee <lee@yun.yagibdah.de> wrote: 
>
> l> is there a way to send messages from a script using the posting style of
> l> a particular group?  Like
>
> l>   emacsclient -e "(gnus-group-mail 1)"
>
> l> works fine, only it doesn't let me specify which group to use and emacs
> l> asks me.
> ...
> l> This might not be as it should be, but it seems to work:
>
> l>   emacsclient -e '(my-gnus-group-mail "particular.group.name")'
>
> l> Maybe there's a better (already built-in) way to do this?
>
> There's no built-in way to do what you describe, so your function is
> probably the best solution.

Anyone else who might need it, feel free to use it :)

> l> Since I am at this:  This only works when gnus has already been started.
> l> What would I do to make sure that it's started if it isn't?  Is there a
> l> way to check whether gnus is running from the command line/script, or
> l> could/should I write a wrapper around 'my-gnus-group-mail that starts
> l> gnus in case it's not started already?
>
> Since Gnus is not a daemon, it's hard to do what you describe.  Gnus is
> more like a set of functions that agree upon the same buffer formats :)

Maybe I can make a wrapper function that checks the buffer list for a
buffer named "*Gnus*" and starts gnus when there's no such buffer ...


-- 
"Object-oriented programming languages aren't completely convinced that
you should be allowed to do anything with functions."
http://www.joelonsoftware.com/items/2006/08/01.html



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: sending messages from script/command line
  2013-07-02  9:48   ` lee
@ 2013-07-02 15:35     ` Ted Zlatanov
  2013-07-05 22:00       ` lee
  0 siblings, 1 reply; 9+ messages in thread
From: Ted Zlatanov @ 2013-07-02 15:35 UTC (permalink / raw)
  To: ding

On Tue, 02 Jul 2013 11:48:58 +0200 lee <lee@yun.yagibdah.de> wrote: 

l> Ted Zlatanov <tzz@lifelogs.com> writes:
>> 
>> There's no built-in way to do what you describe, so your function is
>> probably the best solution.

l> Anyone else who might need it, feel free to use it :)

I would be OK with putting it under contrib/ at least, if you want to
make it a patch submission.

l> Since I am at this:  This only works when gnus has already been started.
l> What would I do to make sure that it's started if it isn't?  Is there a
l> way to check whether gnus is running from the command line/script, or
l> could/should I write a wrapper around 'my-gnus-group-mail that starts
l> gnus in case it's not started already?
>> 
>> Since Gnus is not a daemon, it's hard to do what you describe.  Gnus is
>> more like a set of functions that agree upon the same buffer formats :)

l> Maybe I can make a wrapper function that checks the buffer list for a
l> buffer named "*Gnus*" and starts gnus when there's no such buffer ...

That may work.  It's probably more robust if Gnus does something on
startup to indicate that it's been started, and something else when it
quits.  But I'll leave it to Lars, I don't have a strong opinion.

Ted




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: sending messages from script/command line
  2013-07-02 15:35     ` Ted Zlatanov
@ 2013-07-05 22:00       ` lee
  2013-07-06  3:22         ` Eric Abrahamsen
  2013-07-08 12:32         ` Ted Zlatanov
  0 siblings, 2 replies; 9+ messages in thread
From: lee @ 2013-07-05 22:00 UTC (permalink / raw)
  To: ding

Ted Zlatanov <tzz@lifelogs.com> writes:

> On Tue, 02 Jul 2013 11:48:58 +0200 lee <lee@yun.yagibdah.de> wrote: 
>
> l> Ted Zlatanov <tzz@lifelogs.com> writes:
>>> 
>>> There's no built-in way to do what you describe, so your function is
>>> probably the best solution.
>
> l> Anyone else who might need it, feel free to use it :)
>
> I would be OK with putting it under contrib/ at least, if you want to
> make it a patch submission.

Sure, why not --- I don't know how to do that, though.  And I would
really like to come up with something better: "better" meaning something
that optionally includes posting styles.  I'd like to be able to specify
headers and the body and give it a flag telling gnus whether I want to
edit the mail before sending it or not.

A tool like mailx would do, and I could send a Bcc to myself and use
some splitting rules to put the messages into the right groups ... but
isn't that something that gnus should be able to do?

> l> Since I am at this:  This only works when gnus has already been started.
> l> What would I do to make sure that it's started if it isn't?  Is there a
> l> way to check whether gnus is running from the command line/script, or
> l> could/should I write a wrapper around 'my-gnus-group-mail that starts
> l> gnus in case it's not started already?
>>> 
>>> Since Gnus is not a daemon, it's hard to do what you describe.  Gnus is
>>> more like a set of functions that agree upon the same buffer formats :)
>
> l> Maybe I can make a wrapper function that checks the buffer list for a
> l> buffer named "*Gnus*" and starts gnus when there's no such buffer ...
>
> That may work.  It's probably more robust if Gnus does something on
> startup to indicate that it's been started, and something else when it
> quits.  But I'll leave it to Lars, I don't have a strong opinion.

Let's see what he says --- perhaps this is even easy to do.  Before I
could come up with something better, I'd have to try to figure out how
gnus works.  Maybe it's not possible to change the posting style on the
fly ... and if it's changed, it would have to be restored ...


-- 
"Object-oriented programming languages aren't completely convinced that
you should be allowed to do anything with functions."
http://www.joelonsoftware.com/items/2006/08/01.html



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: sending messages from script/command line
  2013-07-05 22:00       ` lee
@ 2013-07-06  3:22         ` Eric Abrahamsen
  2013-07-08 12:23           ` Ted Zlatanov
  2013-07-08 12:32         ` Ted Zlatanov
  1 sibling, 1 reply; 9+ messages in thread
From: Eric Abrahamsen @ 2013-07-06  3:22 UTC (permalink / raw)
  To: ding

lee <lee@yun.yagibdah.de> writes:

> Ted Zlatanov <tzz@lifelogs.com> writes:
>
>> On Tue, 02 Jul 2013 11:48:58 +0200 lee <lee@yun.yagibdah.de> wrote: 
>>
>> l> Ted Zlatanov <tzz@lifelogs.com> writes:
>>>> 
>>>> There's no built-in way to do what you describe, so your function is
>>>> probably the best solution.
>>
>> l> Anyone else who might need it, feel free to use it :)
>>
>> I would be OK with putting it under contrib/ at least, if you want to
>> make it a patch submission.
>
> Sure, why not --- I don't know how to do that, though.  And I would
> really like to come up with something better: "better" meaning something
> that optionally includes posting styles.  I'd like to be able to specify
> headers and the body and give it a flag telling gnus whether I want to
> edit the mail before sending it or not.
>
> A tool like mailx would do, and I could send a Bcc to myself and use
> some splitting rules to put the messages into the right groups ... but
> isn't that something that gnus should be able to do?
>
>> l> Since I am at this:  This only works when gnus has already been started.
>> l> What would I do to make sure that it's started if it isn't?  Is there a
>> l> way to check whether gnus is running from the command line/script, or
>> l> could/should I write a wrapper around 'my-gnus-group-mail that starts
>> l> gnus in case it's not started already?
>>>> 
>>>> Since Gnus is not a daemon, it's hard to do what you describe.  Gnus is
>>>> more like a set of functions that agree upon the same buffer formats :)
>>
>> l> Maybe I can make a wrapper function that checks the buffer list for a
>> l> buffer named "*Gnus*" and starts gnus when there's no such buffer ...
>>
>> That may work.  It's probably more robust if Gnus does something on
>> startup to indicate that it's been started, and something else when it
>> quits.  But I'll leave it to Lars, I don't have a strong opinion.
>
> Let's see what he says --- perhaps this is even easy to do.  Before I
> could come up with something better, I'd have to try to figure out how
> gnus works.  Maybe it's not possible to change the posting style on the
> fly ... and if it's changed, it would have to be restored ...

There's the function `gnus-alive-p' that does a bit of checking to see
if gnus is running, you could probably use that in your wrapper
function...

E




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: sending messages from script/command line
  2013-07-06  3:22         ` Eric Abrahamsen
@ 2013-07-08 12:23           ` Ted Zlatanov
  2013-07-08 14:08             ` Eric Abrahamsen
  0 siblings, 1 reply; 9+ messages in thread
From: Ted Zlatanov @ 2013-07-08 12:23 UTC (permalink / raw)
  To: ding

On Sat, 06 Jul 2013 11:22:50 +0800 Eric Abrahamsen <eric@ericabrahamsen.net> wrote: 

EA> There's the function `gnus-alive-p' that does a bit of checking to see
EA> if gnus is running, you could probably use that in your wrapper
EA> function...

Nice, I didn't know about it.  Looks like it's based on the group
buffer's existence.

Ted




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: sending messages from script/command line
  2013-07-05 22:00       ` lee
  2013-07-06  3:22         ` Eric Abrahamsen
@ 2013-07-08 12:32         ` Ted Zlatanov
  1 sibling, 0 replies; 9+ messages in thread
From: Ted Zlatanov @ 2013-07-08 12:32 UTC (permalink / raw)
  To: ding

On Sat, 06 Jul 2013 00:00:57 +0200 lee <lee@yun.yagibdah.de> wrote: 

l> Ted Zlatanov <tzz@lifelogs.com> writes:
>> On Tue, 02 Jul 2013 11:48:58 +0200 lee <lee@yun.yagibdah.de> wrote: 
>> 
l> Ted Zlatanov <tzz@lifelogs.com> writes:
>>>> 
>>>> There's no built-in way to do what you describe, so your function is
>>>> probably the best solution.
>> 
l> Anyone else who might need it, feel free to use it :)
>> 
>> I would be OK with putting it under contrib/ at least, if you want to
>> make it a patch submission.

l> Sure, why not --- I don't know how to do that, though.  And I would
l> really like to come up with something better: "better" meaning something
l> that optionally includes posting styles.  I'd like to be able to specify
l> headers and the body and give it a flag telling gnus whether I want to
l> edit the mail before sending it or not.

For headers and body, you could just feed the message through a file or
STDIN instead of making options for everything.

I don't know about calling mailx...

l> Let's see what he says --- perhaps this is even easy to do.  Before I
l> could come up with something better, I'd have to try to figure out how
l> gnus works.  Maybe it's not possible to change the posting style on the
l> fly ... and if it's changed, it would have to be restored ...

`gnus-alive-p' is your friend as Eric said :)

Ted




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: sending messages from script/command line
  2013-07-08 12:23           ` Ted Zlatanov
@ 2013-07-08 14:08             ` Eric Abrahamsen
  0 siblings, 0 replies; 9+ messages in thread
From: Eric Abrahamsen @ 2013-07-08 14:08 UTC (permalink / raw)
  To: ding

Ted Zlatanov <tzz@lifelogs.com> writes:

> On Sat, 06 Jul 2013 11:22:50 +0800 Eric Abrahamsen <eric@ericabrahamsen.net> wrote: 
>
> EA> There's the function `gnus-alive-p' that does a bit of checking to see
> EA> if gnus is running, you could probably use that in your wrapper
> EA> function...
>
> Nice, I didn't know about it.  Looks like it's based on the group
> buffer's existence.
>
> Ted

Yeah, it's nothing particularly magic, but it saves some boilerplate...




^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-07-08 14:08 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-28 15:40 sending messages from script/command line lee
2013-07-01 12:40 ` Ted Zlatanov
2013-07-02  9:48   ` lee
2013-07-02 15:35     ` Ted Zlatanov
2013-07-05 22:00       ` lee
2013-07-06  3:22         ` Eric Abrahamsen
2013-07-08 12:23           ` Ted Zlatanov
2013-07-08 14:08             ` Eric Abrahamsen
2013-07-08 12:32         ` Ted Zlatanov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).