# Imap and character enconding

**URL:** <https://www.ruby-forum.com/t/imap-and-character-enconding/88685>\
**Category:** Rails\
**Created:** [March 13, 2007, 3:29pm UTC](https://www.ruby-forum.com/t/imap-and-character-enconding/88685 "2007-03-13T15:29:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fcruxen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ecae2f/32.png) [@fcruxen](https://www.ruby-forum.com/u/fcruxen)\
**Post date:** [March 13, 2007, 3:29pm UTC](https://www.ruby-forum.com/t/imap-and-character-enconding/88685/1 "2007-03-13T15:29:26Z")

</div>

Hi, hi, hi little droogies

First of all, sorry for the lame english and the dumb question. After a  
quick search on google I found iconv, and some other toys, but the point  
is:

I’m making a small webmail app for my company, still taking the first  
steps. For instance, if I want to read my INBOX folder and list the  
messages:

* * *

CONTROLLER =\>  
def list\_inbox  
imap = Net::IMAP.new(‘xxx.xxx.xxx.xxx’)  
imap.authenticate(‘LOGIN’, ‘removed\_email\_address@domain.invalid’, ‘password’)  
imap.select(‘INBOX’)  
@emails = []  
imap.search([“ALL”]).each do |i|  
@emails \<\< imap.fetch(i, “ENVELOPE”)[0].attr[“ENVELOPE”]  
end  
imap.disconnect  
end

VIEW =\>

## 

# Webmail#list\_inbox
  
\<% @emails.each do |i| %\>  
\<%= i.from[0].name %\> / \<%= i.subject %\>  
  
\<% end %\>

The enconding seems messed up, when the message comes in iso-8859-1  
format, it’s preceeded with “=?iso-8859-1?Q?”, same for utf-8  
“=?UTF-8?Q?”. And the accents come encoded too (=E9 =\> Ã©).How can I  
solve this?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![fcruxen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ecae2f/32.png) [@fcruxen](https://www.ruby-forum.com/u/fcruxen)\
**Post date:** [March 15, 2007, 6:39am UTC](https://www.ruby-forum.com/t/imap-and-character-enconding/88685/2 "2007-03-15T06:39:13Z")

</div>

On 14/03/2007, at 1:29 AM, Felipe C. wrote:

> The enconding seems messed up, when the message comes in iso-8859-1  
> format, it’s preceeded with “=?iso-8859-1?Q?”, same for utf-8  
> “=?UTF-8?Q?”. And the accents come encoded too (=E9 =\> é).How can I  
> solve this?

That’s the way non-ASCII headers are supposed to be encoded. You need  
to read:

[http://www.ietf.org/rfc/rfc2047.txt](http://www.ietf.org/rfc/rfc2047.txt)

Cheers,

Pete Y.

> **[Pete Yandell — Principal Engineer / Architect](https://notahat.com/)**
>
> Pete Yandell is an experienced Principal Software Engineer and Architect based in Melbourne, Australia.
