[RUBY] [Rails 6 + Action Mailbox] Those who extracted the plain text of Gmail received by Action Mailbox

Task

How to extract plain text differs depending on whether Gmail received by ActionMailbox is a simplified version or not. Perhaps other mailers fall into either category. .. .. .. Should be.

Conclusion

How to extract each plain text. Gmail simplified version-> mail.body.decoded Gmail current version-> mail.text_part.body.decoded

plain_text extraction example


def plain_text
  mail.text_part.nil? ? mail.body.decoded : mail.text_part.body.decoded
end

At first I was impatient because I thought it was necessary for gem'sanitize'. Although it was a knowledge within the range of common sense, I stumbled unexpectedly.

Recommended Posts

[Rails 6 + Action Mailbox] Those who extracted the plain text of Gmail received by Action Mailbox
Rails6: Extract the image in Action Text
For those who want to use MySQL for the database in the environment construction of Rails6 ~.
Read the Rails Guide (Overview of Action Controller) again
Rails Action Text implementation
[Enum] Let's improve the readability of data by using rails enum
[Rails] Register by attribute of the same model using Devise