# Username mapping for imap/pop

**URL:** <https://www.ruby-forum.com/t/username-mapping-for-imap-pop/238472>\
**Category:** NGINX\
**Created:** [January 12, 2014, 11:27pm UTC](https://www.ruby-forum.com/t/username-mapping-for-imap-pop/238472 "2014-01-12T23:27:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [January 12, 2014, 11:27pm UTC](https://www.ruby-forum.com/t/username-mapping-for-imap-pop/238472/1 "2014-01-12T23:27:37Z")

</div>

I need to map from username to login name where I wish to map from just  
username to removed\_email\_address@domain.invalid for gmail and windomain\username for an  
exchange server. Is there a way for me to build in hooks to change the  
username before connecting. I can to that in my mailauth.pm module but  
don’t know how to return the updated username.

Posted at Nginx Forum:

> **[username mapping for imap/pop](https://forum.nginx.org/read.php?2,246296,246296#msg-246296)**
>
> I need to map from username to login name where I wish to map from just username to username@domain.org for gmail and windomain\\username for an exchange server. Is there a way for me to build in hooks to change the username before connecting. I can...

---

<div class="post-metadata">

**Author:** ![bidwell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bidwell](https://www.ruby-forum.com/u/bidwell)\
**Post date:** [January 13, 2014, 8:58am UTC](https://www.ruby-forum.com/t/username-mapping-for-imap-pop/238472/2 "2014-01-13T08:58:59Z")

</div>

On Jan 13, 2014, at 2:27 , bidwell wrote:

> I need to map from username to login name where I wish to map from just  
> username to removed\_email\_address@domain.invalid for gmail and windomain\username for an  
> exchange server. Is there a way for me to build in hooks to change the  
> username before connecting. I can to that in my mailauth.pm module but  
> don’t know how to return the updated username.

You can return it via header:  
Auth-User: removed\_email\_address@domain.invalid

–  
Igor S.

> **[Advanced Load Balancer, Web Server, & Reverse Proxy - NGINX](https://www.nginx.com/)**
>
> NGINX accelerates content and application delivery, improves security, and facilitates availability and scalability for the busiest websites on the Internet.

---

<div class="post-metadata">

**Author:** ![bidwell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bidwell](https://www.ruby-forum.com/u/bidwell)\
**Post date:** [January 13, 2014, 6:52pm UTC](https://www.ruby-forum.com/t/username-mapping-for-imap-pop/238472/3 "2014-01-13T18:52:41Z")

</div>

Thank you. That is what I thought and have implimented. Tracing the  
problem further, my imap connection successfully authenticates and then  
gets  
a “connection closed by foreign host” going through nginx. The pop  
connection works just fine, but imap fails.

I have nginx configured to enter on port 143 and go out to 127.0.0.1:143  
where it goes through stunnel to go to [imap.gmail.com:993](http://imap.gmail.com:993). If I talk  
directly to 127.0.0.1:143 (to stunnel) it works. If I talk to nginx, it  
authenticates, logs correct username, target IP and port, gets the  
Capability list and registers a successful login to the remote (gmail)  
imap  
server and then closes the connection immediately. The following is a  
transcript of the telnet session:

telnet nginx:143

- OK IMAP4 ready  
a1 LOGIN removed\_email\_address@domain.invalid password
- CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN  
X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE ENABLE MOVE CONDSTORE ESEARCH  
a1 OK removed\_email\_address@domain.invalid first\_name Last\_name authenticated (Success)  
Connection closed by foreign host.

Any suggestions as to what to try next to diagnose this? (Thanks in  
advance)

Posted at Nginx Forum:

> **[Re: username mapping for imap/pop](https://forum.nginx.org/read.php?2,246296,246341#msg-246341)**
>
> I need to map from username to login name where I wish to map from just username to username@domain.org for gmail and windomain\\username for an exchange server. Is there a way for me to build in hooks to change the username before connecting. I can...

---

<div class="post-metadata">

**Author:** ![bidwell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bidwell](https://www.ruby-forum.com/u/bidwell)\
**Post date:** [January 14, 2014, 10:56pm UTC](https://www.ruby-forum.com/t/username-mapping-for-imap-pop/238472/4 "2014-01-14T22:56:04Z")

</div>

My nginx error.log shows the following:  
_5 upstream sent invalid response: "_ CAPABILITY IMAP4rev1 UNSELECT IDLE  
NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE  
ENABLE  
MOVE CONDSTORE ESEARCH  
a1 OK removed\_email\_address@domain.invalid Test User authenticated (Success)" while reading  
response from upstream,…

It appears to not like google’s CAPABILITY line. Is it too long? Any  
suggestions?

Posted at Nginx Forum:

> **[Re: username mapping for imap/pop](https://forum.nginx.org/read.php?2,246296,246442#msg-246442)**
>
> I need to map from username to login name where I wish to map from just username to username@domain.org for gmail and windomain\\username for an exchange server. Is there a way for me to build in hooks to change the username before connecting. I can...
