Gnus development mailing list
 help / color / mirror / Atom feed
* using templates to write articles (email)
@ 2011-06-10 18:03 lee
  2011-06-10 18:53 ` Eric Abrahamsen
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: lee @ 2011-06-10 18:03 UTC (permalink / raw)
  To: ding

Hi,

is there some sort of support built into gnus for writing articles
(email) from templates? Such templates would contain either headers or a
body, or a combination of both.

So far, I´ve created templates as plain text files, and when writing an
email from the template, I delete everything in the composing buffer and
do an insert-file to read the template into the buffer. This works fine,
and perhaps there´s some support for templates already built in, which
would make using templates more convenient?



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

* Re: using templates to write articles (email)
  2011-06-10 18:03 using templates to write articles (email) lee
@ 2011-06-10 18:53 ` Eric Abrahamsen
  2011-06-10 20:41   ` lee
  2011-06-10 19:32 ` Didier Verna
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Eric Abrahamsen @ 2011-06-10 18:53 UTC (permalink / raw)
  To: ding

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

> Hi,
>
> is there some sort of support built into gnus for writing articles
> (email) from templates? Such templates would contain either headers or a
> body, or a combination of both.
>
> So far, I´ve created templates as plain text files, and when writing an
> email from the template, I delete everything in the composing buffer and
> do an insert-file to read the template into the buffer. This works fine,
> and perhaps there´s some support for templates already built in, which
> would make using templates more convenient?

I don't know of anything built in, but I wrote the following function to
do something like a mail merge. It's very primitive, but could serve as
the basis for what you need.

--8<---------------cut here---------------start------------->8---
(defun my-mail-merge (names buffer subject from marker)
  "This is a bit of a mess, but it's something like a mail merge.

Variable containing names should be a list of two-element lists,
in the format (\"Name\" \"email address\")."
  (interactive "XVariable containing names: \nbBuffer to slurp: \nsSubject: \nsFrom: \nsMarker: ")
  (dolist (n names)
    (compose-mail (nth 1 n)		; to address
		  subject
		  `(("From" . ,from))  ; all other headers
		  nil nil nil nil)	; don't remember
    (insert-buffer-substring (get-buffer buffer))
    (message-goto-body)
    (perform-replace marker (nth 0 n) nil nil nil) ; insert name
    (message-send-and-exit)))
--8<---------------cut here---------------end--------------->8---

"marker" here is basically just something like XXXXX, that gets replaced
with the name. The logical next step would be to have it read data from
a file instead of a variable, and then have the top line of the file set
the markers for each field, like so:

{{name}},{{salutation}},{{email}}
John Doe,Dear,j.doe@gmail.com

Then use those markers in a template, and have the call to
perform-replace loop once for each marker.

Hope that provides food for thought,

Eric




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

* Re: using templates to write articles (email)
  2011-06-10 18:03 using templates to write articles (email) lee
  2011-06-10 18:53 ` Eric Abrahamsen
@ 2011-06-10 19:32 ` Didier Verna
  2011-06-10 20:46   ` lee
  2011-06-11 17:22 ` Dan Christensen
  2011-06-13  0:33 ` solved: " lee
  3 siblings, 1 reply; 7+ messages in thread
From: Didier Verna @ 2011-06-10 19:32 UTC (permalink / raw)
  To: ding

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

> is there some sort of support built into gnus for writing articles
> (email) from templates? Such templates would contain either headers or
> a body, or a combination of both.

  Personally, I do already a lot of templating based on a combination of
topic/group parameters and posting styles (e.g. headers, addresses,
signatures, even language for spell checking etc).

So I guess you could go down this road. You can add any variable to a
topic/group parameter, for example a skeleton text. Then, what you can
do is write a message-setup-hook function that looks in there and fill
your message with the appropriate contents.

All of this provided that group-based templating is what you have in
mind of course.

-- 
Resistance is futile. You will be jazzimilated.

Scientific site:   http://www.lrde.epita.fr/~didier
Music (Jazz) site: http://www.didierverna.com



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

* Re: using templates to write articles (email)
  2011-06-10 18:53 ` Eric Abrahamsen
@ 2011-06-10 20:41   ` lee
  0 siblings, 0 replies; 7+ messages in thread
From: lee @ 2011-06-10 20:41 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: ding

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> lee <lee@yun.yagibdah.de> writes:
>
>> So far, I´ve created templates as plain text files, and when writing an
>> email from the template, I delete everything in the composing buffer and
>> do an insert-file to read the template into the buffer. This works fine,
>> and perhaps there´s some support for templates already built in, which
>> would make using templates more convenient?
>
>
> (defun my-mail-merge (names buffer subject from marker)
>   "This is a bit of a mess, but it's something like a mail merge.
>
> Variable containing names should be a list of two-element lists,
> in the format (\"Name\" \"email address\")."
>   (interactive "XVariable containing names: \nbBuffer to slurp: \nsSubject: \nsFrom: \nsMarker: ")
>   (dolist (n names)
>     (compose-mail (nth 1 n)		; to address
> 		  subject
> 		  `(("From" . ,from))  ; all other headers
> 		  nil nil nil nil)	; don't remember
>     (insert-buffer-substring (get-buffer buffer))
>     (message-goto-body)
>     (perform-replace marker (nth 0 n) nil nil nil) ; insert name
>     (message-send-and-exit)))
>
> Hope that provides food for thought,

It does, thanks :) If I understand your code correctly --- and I don´t
know how to program in elisp (yet) --- your function would load text
from some buffer into the composing buffer and replace placeholders with
names and emailaddresses supplied as parameters to the function. That
way, you could mail an otherwise identical text to a number of
recipients with automatically customized salutations.

What I´m looking for is a little simpler in that I don´t need to use
placeholders. It´s ok to edit each message manually. I think it might be
possible, as Didier Verna suggested in his reply, to use posting styles
and to use a function that just replaces the whole default content of
the composing buffer with my template.

I´ll try to figure out how to get it set up that way; it´ll be a nice
excercise. I´ll let you guys know what I come up with --- or ask some
more questions about how to do it when I get stuck :)



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

* Re: using templates to write articles (email)
  2011-06-10 19:32 ` Didier Verna
@ 2011-06-10 20:46   ` lee
  0 siblings, 0 replies; 7+ messages in thread
From: lee @ 2011-06-10 20:46 UTC (permalink / raw)
  To: ding

Didier Verna <didier@xemacs.org> writes:

> lee <lee@yun.yagibdah.de> wrote:
>
>> is there some sort of support built into gnus for writing articles
>> (email) from templates? Such templates would contain either headers or
>> a body, or a combination of both.
>
> So I guess you could go down this road. You can add any variable to a
> topic/group parameter, for example a skeleton text. Then, what you can
> do is write a message-setup-hook function that looks in there and fill
> your message with the appropriate contents.
>
> All of this provided that group-based templating is what you have in
> mind of course.

Group-based templating should be fine. I would only need to specify the
filename of the template text in a variable and to write a function that
automatically replaces the default contents of the composing buffer with
the file and then allows me to edit it :)



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

* Re: using templates to write articles (email)
  2011-06-10 18:03 using templates to write articles (email) lee
  2011-06-10 18:53 ` Eric Abrahamsen
  2011-06-10 19:32 ` Didier Verna
@ 2011-06-11 17:22 ` Dan Christensen
  2011-06-13  0:33 ` solved: " lee
  3 siblings, 0 replies; 7+ messages in thread
From: Dan Christensen @ 2011-06-11 17:22 UTC (permalink / raw)
  To: ding

[-- Attachment #1: Type: text/plain, Size: 220 bytes --]

I use mozmail-compose-gnus in mozmail.el.  I wrap this with the attached
python script which reads an e-mail message from standard input and then
uses emacsclient to open a message buffer via mozmail-compose-gnus.

Dan


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: gnusemail --]
[-- Type: text/x-python, Size: 1181 bytes --]

#!/usr/bin/env python

# Reads an e-mail message from stdin, and sets up a gnus compose buffer
# with it ready to edit/send.  Only handles single-line To, Cc, Subject, etc.

import sys
import subprocess

readinghead = True
to = 'nil'
cc = 'nil'
bcc = 'nil'
subject = 'nil'
body = '"'
for line in sys.stdin:
    # Replace \ with \\
    line=line.replace('\\', r'\\')
    # Replace " with \"
    line=line.replace(r'"', r'\"')

    if readinghead:
	line = line.strip()
        if line:
            if line.startswith('To: '):
                to = '"' + line[4:] + '"'
            elif line.startswith('Cc: '):
                cc = '"' + line[4:] + '"'
            elif line.startswith('Bcc: '):
                bcc = '"' + line[5:] + '"'
            elif line.startswith('Subject: '):
                subject = '"' + line[9:] + '"'
            else:
                print 'Error: unknown line in head:'
                print line
                sys.exit(1)
        else:
            readinghead = False
    else:
        body += line
body += '"'

elisp = '(mozmail-compose-gnus %s %s %s %s %s)' % (to, subject, cc, bcc, body)
subprocess.call(['emacsclient', '-n', '--eval', elisp])

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

* solved: using templates to write articles (email)
  2011-06-10 18:03 using templates to write articles (email) lee
                   ` (2 preceding siblings ...)
  2011-06-11 17:22 ` Dan Christensen
@ 2011-06-13  0:33 ` lee
  3 siblings, 0 replies; 7+ messages in thread
From: lee @ 2011-06-13  0:33 UTC (permalink / raw)
  To: ding

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

> is there some sort of support built into gnus for writing articles
> (email) from templates? Such templates would contain either headers or a
> body, or a combination of both.

This tured out to be a problem I can solve with posting styles very
nicely:


,----
| 	 (posting-style
| 	  (name "foobar")
| 	  ("Return-Receipt-To" user-mail-address)
| 	  ("Disposition-Notification-To" user-mail-address)
| 	  ("X-yun.yagibdah.de-info" "ref ")
| 	  (body :file "~/some-filename.txt"))
`----


Thanks for all your help! I should have switched to gnus long ago
... The more I learn about it, the more I like it :)



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

end of thread, other threads:[~2011-06-13  0:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-10 18:03 using templates to write articles (email) lee
2011-06-10 18:53 ` Eric Abrahamsen
2011-06-10 20:41   ` lee
2011-06-10 19:32 ` Didier Verna
2011-06-10 20:46   ` lee
2011-06-11 17:22 ` Dan Christensen
2011-06-13  0:33 ` solved: " lee

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).