I need to store email messages as soon as they are fetched from IMAP in the database for later processing. I extract the message using a FETCH
request and data is returned using BODY.PEEK[]
.
From my understanding, all IMAP messages are returned as US-ASCII
(the mail servers accept only that), but I could be wrong.
My options (in order of what I think it's right) are:
I was thinking about using US-ASCII but I'm afraid of having problems with encoding, I don't know if there are "faulty" IMAP servers not returning us-ascii mails. The alternative is Bytea, but I read you have to deal with encoding, so I'm not sure what's the advantage/disadvantage over US-ASCII. BLOB is raw, and I'm not sure about the problems it deliver in this case. I assume I have to deal with the bytes-to-string conversion.
What's the recommended data type?
For small objects such as emails, I think you're going to be better off with Bytea. The storage and handling is different and since your objects are going to be small, it seems like it would be handled better as Bytea. See here for a comparison of the two by Microolap. That's not a full answer to your question but might take one option off the list.