diff options
author | Louise Crow <louise.crow@gmail.com> | 2012-11-22 09:49:24 +0000 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2012-11-22 09:49:24 +0000 |
commit | 09ffe8277417a1e486ae60db3254d511b4c64d33 (patch) | |
tree | 245f90f83681210ceec19a35f29fbf0e06c10252 /lib/mail_handler/backends/mail_backend.rb | |
parent | 766da660994dbe7c86f556d9cf863411814622fe (diff) | |
parent | 640aa149fd321658a33466df7b53947b78bccd81 (diff) |
Merge branch 'develop' into wdtk
Diffstat (limited to 'lib/mail_handler/backends/mail_backend.rb')
-rw-r--r-- | lib/mail_handler/backends/mail_backend.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/mail_handler/backends/mail_backend.rb b/lib/mail_handler/backends/mail_backend.rb new file mode 100644 index 000000000..0e198adf0 --- /dev/null +++ b/lib/mail_handler/backends/mail_backend.rb @@ -0,0 +1,51 @@ +require 'mail' + +module MailHandler + module Backends + module MailBackend + + def backend() + 'Mail' + end + + # Note that the decode flag is not yet used + def mail_from_raw_email(data, decode=true) + Mail.new(data) + end + + # Extracts all attachments from the given TNEF file as a Mail object + def mail_from_tnef(content) + main = Mail.new + tnef_attachments(content).each do |attachment| + main.add_file(attachment) + end + main.ready_to_send! + main + end + + # Return a copy of the file name for the mail part + def get_part_file_name(mail_part) + part_file_name = mail_part.filename + part_file_name.nil? ? nil : part_file_name.dup + end + + # Format + def address_from_name_and_email(name, email) + if !MySociety::Validate.is_valid_email(email) + raise "invalid email " + email + " passed to address_from_name_and_email" + end + if name.nil? + return Mail::Address.new(email) + end + address = Mail::Address.new + address.display_name = name + address.address = email + address.to_s + end + + def address_from_string(string) + Mail::Address.new(string).address + end + end + end +end
\ No newline at end of file |