* [sup-talk] Strange problem in before-edit hook
@ 2009-05-13 15:28 Marcus Williams
0 siblings, 0 replies; only message in thread
From: Marcus Williams @ 2009-05-13 15:28 UTC (permalink / 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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2009-05-13 15:28 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-13 15:28 [sup-talk] Strange problem in before-edit hook Marcus Williams
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox