diff options
author | Louise Crow <louise.crow@gmail.com> | 2012-11-20 16:14:22 +0000 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2012-11-20 16:14:22 +0000 |
commit | fcb6cdd6342d0272a8e7f05d20a4b0d87da70de9 (patch) | |
tree | 48ea4a5a796c4e95d26e4d4f36170ac09d368637 /lib/mail_handler/backends/mail_backend.rb | |
parent | b0d9551a83c4a101ac808f1c35f66dd138cbc0f1 (diff) | |
parent | 24c3ceb2315734ab6e43ae4f75673e251b98a96e (diff) |
Merge remote-tracking branch 'origin/feature/isolate-mail-handling' into develop
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 |