Skip to content

Instantly share code, notes, and snippets.

@djgraham
Created September 11, 2009 11:59
Show Gist options
  • Save djgraham/185251 to your computer and use it in GitHub Desktop.
Save djgraham/185251 to your computer and use it in GitHub Desktop.
# WARNING! Far from incomplete, very experimental!
# Attempt to grab the body of the message.
# looks in "base" message and if its multipart, go one level deep..
# if not a multipart message return the body alone
#
def self.get_multipart_body(mail)
types = mail.parts.collect(&:content_type)
if types.include?("multipart/alternative")
m_part = mail.parts.find {
|m| m.content_type == "multipart/alternative"
}
sub_types = m_part.parts.collect(&:content_type)
if sub_types.include?("text/plain")
m_part2 = m_part.parts.find {
|m| m.content_type == "text/plain"
}
ret = m_part2.body
else
ret = m_part # get_text_html(m_part)
end
elsif types.include?("text/plain")
m_part = mail.parts.find {
|m| m.content_type == "text/plain"
}
ret = m_part.body # get_text_plain(m_part)
else
ret = mail.body
end
ret
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment