diff options
author | Francis Irving <francis@mysociety.org> | 2010-07-13 23:54:46 +0100 |
---|---|---|
committer | Francis Irving <francis@mysociety.org> | 2010-07-13 23:54:46 +0100 |
commit | 59395b3bdf19aed7bf5f77656afa6c31dad7e138 (patch) | |
tree | b6e4c9f9e5b4a9f792a550ce3af727ae32b1cba1 /lib | |
parent | 452ac41f05f655a9fd23c8df4796f26632c23050 (diff) | |
parent | da2c0aaf5f0d07baa3a355033a92d5dd295f2f13 (diff) |
Merge branch 'master' into francis-profile-photo
Conflicts:
app/views/user/show.rhtml
commonlib
spec/controllers/user_controller_spec.rb
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sendmail_return_path.rb | 2 | ||||
-rw-r--r-- | lib/tnef.rb | 40 |
2 files changed, 41 insertions, 1 deletions
diff --git a/lib/sendmail_return_path.rb b/lib/sendmail_return_path.rb index f9ddba5b4..d8922f78b 100644 --- a/lib/sendmail_return_path.rb +++ b/lib/sendmail_return_path.rb @@ -1,7 +1,7 @@ # Monkeypatch! # Grrr, semantics of smtp and sendmail send should be the same with regard to setting return path -# See test in spec/lib/sendmail_return_path.rb +# See test in spec/lib/sendmail_return_path_spec.rb module ActionMailer class Base diff --git a/lib/tnef.rb b/lib/tnef.rb new file mode 100644 index 000000000..ff88b0005 --- /dev/null +++ b/lib/tnef.rb @@ -0,0 +1,40 @@ +require 'tmpdir' + +class TNEF + + # Extracts all attachments from the given TNEF file as a TMail::Mail object + # The TNEF file also contains the message body, but in general this is the + # same as the message body in the message proper. + def self.as_tmail(content) + main = TMail::Mail.new + main.set_content_type 'multipart', 'mixed', { 'boundary' => TMail.new_boundary } + Dir.mktmpdir do |dir| + IO.popen("/usr/bin/tnef -K -C #{dir}", "w") do |f| + f.write(content) + f.close + if $?.signaled? + raise IOError, "tnef exited with signal #{$?.termsig}" + end + if $?.exited? && $?.exitstatus != 0 + raise IOError, "tnef exited with status #{$?.exitstatus}" + end + end + found = 0 + Dir.new(dir).sort.each do |file| # sort for deterministic behaviour + if file != "." && file != ".." + file_content = File.open("#{dir}/#{file}", "r").read + attachment = TMail::Mail.new + attachment['content-location'] = file + attachment.body = file_content + main.parts << attachment + found += 1 + end + end + if found == 0 + raise IOError, "tnef produced no attachments" + end + end + main + end + +end |