5065 comments
2219 subscribers
4798 on Twitter
Subscribe! Feed reader E-mail

semi-form letters: hooray for open source!

I needed to write 31 thank-you-for-attending-my-send-off-party e-mail
messages. Instead of having a generic letter that I’d send to lots of
people all listed in To: or Bcc:, I decided to personalize it a bit by
including their nicknames, two-year goals, and a personal message I’d
add to each letter in different places.

Fortunately, my mail client was up to the task. One of the benefits of
having both your contact information and your mail client in an
easily-programmable environment is that you can hack together a quick
program to do exactly what you want.

I had typed everyone’s two-year-plans into my contact information
manager’s Notes field following a special format. It was the work of a
few minutes to record and run a macro that extracted the data and
created a signature for each person who attended my send-off party.

I then wrote a couple of short functions that looped over the
currently displayed contact records and drafted messages for each of
them following a template.

This resulted in 31 drafts I could edit and send without hassles. Much
fun!

For future reference (and for the handful of Emacs geeks or learners
in the audience), here’s the code I used to make it all happen:

(defun sacha/bbdb-send-form-mail (bbdb-record &optional subject template)
  "Compose a form message to the people indicated by the current BBDB record(s)."
  (interactive (list (if (bbdb-do-all-records-p)
                         (mapcar 'car bbdb-records)
                       (bbdb-current-record))
                     (read-string "Subject: ")
                     (read-string "Template (): ")))
  (if (consp bbdb-record)
      (let ((records bbdb-record))
        (while records
          (sacha/bbdb-send-form-mail-1 (car records) subject template)
          (setq records (cdr records))))
    (sacha/bbdb-send-form-mail-1 bbdb-record subject template)))

(defun sacha/bbdb-send-form-mail-1  (bbdb-record &optional subject template)
  "Compose a form message for one person."
    (if bbdb-inside-electric-display
      (bbdb-electric-throw-to-execute
       (list 'sacha/bbdb-send-form-mail bbdb-record subject)))
  ;; else...
  (cond ((null bbdb-record) (error "record unexists"))
        ((null (bbdb-record-net bbdb-record))
         (message "%s record unhas a network addresses." (or (bbdb-record-name bbdb-record) "Unknown")))
        (t (bbdb-send-mail-internal (bbdb-dwim-net-address bbdb-record)
                                    subject (list bbdb-record))
           (goto-char (point-min))
           (when (re-search-forward "--text follows this line--" nil t)
             (forward-line 1)
             (insert template)
             (goto-char (point-min))
             (while (search-forward "" nil t)
               (replace-match (or (bbdb-record-getprop bbdb-record 'nick)
                                  (bbdb-record-name bbdb-record))
                              t t))
             (when (bbdb-record-getprop bbdb-record 'signature)
               (goto-char (point-max))
               (insert "\n")
               (let ((p (point)))
                 (insert (bbdb-record-getprop bbdb-record 'signature))
                 (fill-region-as-paragraph p (point))))
             (goto-char (point-min))
             (if (re-search-forward "^Subject: $" nil t) (end-of-line))))))

I used M-x local-set-key to bind sacha/bbdb-send-form-mail to M. * M
then applies the function to all displayed records.
../emacs/miniedit.el makes it easy to edit long strings in the
minibuffer, and that made the template much easier to write.

Emacs totally rocks. Nothing else has ever given me this much power.

自動車製造は人間の労働者に代わって、コンピューターが組み込まれたロボットによって行われている。 Car manufacturing is carried out by computer-programmed robots in place of human workers.

On Technorati: ,

Short URL: http://sachachua.com/blog/p/2820

Comment, share a thought, ask a question...

Please comment as you, not your organization.





 

On This Day...

  • 2011: Weekly review: Two weeks ending July 9, 2011 — Ah, holiday weekends. Forgot to do my review last week. =) From the other week’s plans Work [X] Visit [...]
  • 2010: Sooner or later? Expertise and the new — I will learn how to sell, sooner or later. The question is: sooner, or later? Years of experience can help a [...]
  • 2008: Ruby code to quickly convert titles to ISBNs — I love the Toronto Public Library system. I can’t say that enough. I particularly love how I can go on [...]
  • 2008: To dream the impersonal dream — I’ve been trying to find words to explain what it’s like wanting to make things happen, how it’s not about [...]
  • 2007: Geek… — Darn. It looks like Statistics is one of those subjects that creeps up on you and clamps onto your brain when [...]
  • 2006: CookOrDie: Vegetarian virtues — After quite a hiatus from CookOrDie blogging because I’d either been eating out or cooking simple things, I decided to experiment [...]
  • 2006: Short-term plans: happy with research, thinking about internship? — Mark Chignell, Gordon Lee, Julie Waterhouse and I discussed my research plan this morning. I’m really lucky to have such wonderful, wonderful [...]
  • 2006: Visited a friend — I found myself in the neighborhood of a good friend I hadn’t talked to in a while, so I decided to [...]
  • 2006: Finally on a phone plan — I’ve switched to a plan that gives me free incoming calls and (practically) unlimited text messages. My new number is +1416TADANOW. Or [...]
  • 2005: Things you can do with RSS — Check out Things You Can Do with RSS for lots of interesting uses for RSS aggregators like Bloglines. =) Great [...]
  • 2005: Also from Trim Path: Javascript MVC framework — Junction brings the power of the Ruby on Rails web MVC framework to JavaScript. It makes it much easier to develop web-based [...]
  • 2003: Hmmm, not so many updates this time — I should come up with a matrix to show the students that I’m keeping track of where they are and what [...]
  • 2003: http://whisper.surrey.sfu.ca/what.html — “Wearable body architectures” – seems to be a performance-art/tele-biofeedback thing? Link from Jonathan Hatol.
  • 2003: Cool student programs — I’ll be highlighting some cool programs in my journal. =) I’ll write up the ones that are in my mindmap (XML, [...]
  • 2003: Javascript + XUL ideas — I tend to download a lot of links; it would be nice to have a list of downloadable links and select [...]
  • 2003: Window manager decisions — I will stay in ion and use Xnest for apps that have weird dialog boxes, like Openoffice.
  • 2003: Oooh, teaching story! — My students are brilliant _and_ having fun! =) I’ve gotten e-mail from students along the lines of “I was thinking in the [...]
  • 2003: Openoffice exports to Flash — Nifty! OpenOffice presentations can be exported to Flash. =) Hmm. WebCast?
  • 2003: Clipart wanted for document: — manager developer sweatdrop (for Use Cases) stacks of paper person sleeping