Archive of RubyForge sup-talk mailing list
 help / color / mirror / Atom feed
From: marcus-sup@bar-coded.net (Marcus Williams)
Subject: [sup-talk] Strange problem in before-edit hook
Date: Wed, 13 May 2009 16:28:06 +0100	[thread overview]
Message-ID: <1242228484-sup-2569@tomsk> (raw)

The automatic setting of the from address on a reply works really well
in sup, but I've been trying to get new emails do something similar
with the hook mechanism.

I've got the before-edit hook to do set my from address by picking up
the previously used from address from a search using the sent label.
Basically this means if I send a new email to someone using a specific
from address, it picks up my last used from address as the default the
next time I send them an email.  This saves having to write something
specific for every email/domain I send to.

It works really well but I get the odd crash in the hook because the
header['To'] sometimes is an array rather than the expected string.
I've got around this by doing a to_s on the header but I cant figure
out why I'd ever get an array. Anyone got any ideas?

Heres the hook:

### start of before-edit
fr = nil
emailto = ""

hdrto = header["To"].to_s

hdrto.split(' ').find() { |e| e.include?("@") }.each() do |ee| 
    if ee.include?("<")
        emailto = ee[1..-2] 
    else 
        emailto = ee 
    end 
end

Index.index.search_each("to:\"#{emailto}\" AND label:sent") { |id, score| m = Index.build_message(id); fr = m.from }

header["From"] = fr.full_address unless fr.nil?
header["Return-Path"] = header["From"]
### end of before-edit


                 reply	other threads:[~2009-05-13 15:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1242228484-sup-2569@tomsk \
    --to=marcus-sup@bar-coded.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox