module Redwood
class Account < Person
- attr_accessor :sendmail, :sig_file
+ attr_accessor :sendmail, :signature
def initialize email, h
super h[:name], email, 0, true
@sendmail = h[:sendmail]
- @sig_file = h[:signature]
+ @signature = h[:signature]
end
end
@accounts = {}
@default_account = nil
- accounts.each { |k, v| add_account v, k == :default }
+ add_account accounts[:default], true
+ accounts.each { |k, v| add_account v unless k == :default }
self.class.i_am_the_instance self
end
def user_accounts; @accounts.keys; end
def user_emails; @email_map.keys.select { |e| String === e }; end
+ ## must be called first with the default account. fills in missing
+ ## values from the default account.
def add_account hash, default=false
- main_email = hash[:email]
+ raise ArgumentError, "no email specified for account" unless hash[:email]
+ unless default
+ [:name, :sendmail, :signature].each { |k| hash[k] ||= @default_account.send(k) }
+ end
+ hash[:alternates] ||= []
- ([hash[:email]] + (hash[:alternates] || [])).each do |email|
+ main_email = hash[:email]
+ ([hash[:email]] + hash[:alternates]).each do |email|
next if @email_map.member? email
a = Account.new main_email, hash
PersonManager.register a
@header["Bcc"] = opts[:bcc].map { |p| p.full_address }.join(", ") if opts[:bcc]
@header["Subject"] = opts[:subj] if opts[:subj]
- @body = (opts[:body] || []) + sig_lines
+ @body = opts[:body] || []
regen_text
end
- def lines; @text.length; end
- def [] i; @text[i]; end
-
protected
def handle_new_text new_header, new_body
@header = new_header
@body = new_body
end
-
- def regen_text
- @text = header_lines(@header - EditMessageMode::NON_EDITABLE_HEADERS) + [""] + @body
- end
end
end
@edited = false
end
+ def lines; @text.length; end
+ def [] i; @text[i]; end
+
def edit
@file = Tempfile.new "sup.#{self.class.name.gsub(/.*::/, '').camel_to_hyphy}"
@file.puts header_lines(header - NON_EDITABLE_HEADERS)
buffer.mark_dirty
end
+ def regen_text
+ @text = header_lines(header - NON_EDITABLE_HEADERS) + [""] + body + sig_lines
+ end
+
def parse_file fn
File.open(fn) do |f|
header = MBox::read_header f
BufferManager.flash "Saved for later editing."
end
- def sig_lines
- sigfn = (AccountManager.account_for(header["From"]) ||
- AccountManager.default_account).sig_file
-
- if sigfn && File.exists?(sigfn)
- ["", "-- "] + File.readlines(sigfn).map { |l| l.chomp }
- else
- []
- end
- end
-
def write_message f, full_header=true, date=Time.now
raise ArgumentError, "no pre-defined date: header allowed" if header["Date"]
f.puts header_lines(header)
end
f.puts
- f.puts @body.map { |l| l =~ /^From / ? ">#{l}" : l }
+ f.puts body.map { |l| l =~ /^From / ? ">#{l}" : l }
+ f.puts sig_lines
end
+
+private
+
+
+ def sig_lines
+ p = PersonManager.person_for header["From"]
+ sigfn = (AccountManager.account_for(p.email) ||
+ AccountManager.default_account).signature
+
+ if sigfn && File.exists?(sigfn)
+ ["", "-- "] + File.readlines(sigfn).map { |l| l.chomp }
+ else
+ []
+ end
+ end
end
end
"Subject" => "Fwd: #{m.subj}",
"Message-Id" => gen_message_id,
}
- @body = forward_body_lines(m) + sig_lines
+ @body = forward_body_lines m
regen_text
end
- def lines; @text.length; end
- def [] i; @text[i]; end
-
protected
def forward_body_lines m
@header = new_header
@body = new_body
end
-
- def regen_text
- @text = header_lines(@header - NON_EDITABLE_HEADERS) + [""] + @body
- end
end
end
## it's important to put this early because it forces a read of
## the full headers (most importantly the list-post header, if
## any)
- @body = reply_body_lines(message)
+ @body = reply_body_lines message
from =
if @m.recipient_email
:recipient
end
- @body += sig_lines
regen_text
end
end
end
- def regen_text
- @text = header_lines(header - NON_EDITABLE_HEADERS) + [""] + body
- end
-
def gen_references
(@m.refs + [@m.id]).map { |x| "<#{x}>" }.join(" ")
end