How imap_auth version 6.x-1.x-dev worked with drupal-6.8

bijit - January 6, 2009 - 12:58

Hi All,

I would like to share something with you all on imap_auth module of Drupal.

We had drupal-6.8 installed on a RHEL 3 box. As per requirement we needed to have this Drupal version authenticate against our own IMAP server, thus we dowloaded imap_auth version 6.x-1.x-dev, knowing that this version of imap_auth might not work properly with the Drupal version that we have. Also, frankly speaking we did not have much choice! As the other imap_auth that we found in the Drupal site was imap_auth-4.7.x-1.0 and it was recommended for drupal-4.7.11.

A. Thus the scenario is:
we have drupal-6.8 and a imap_auth version 6.x-1.x-dev (Development snapshot).

B. Integration and configuration:

Integration of imap_auth version 6.x-1.x-dev with drupal-6.8 did not raise any issues.
Necessary inputs for our imap server were made under administer->Site Configuration->IMAP Auth

C. Time for Actual Testing:
http://www.someserver.com/drupal
In the login page, we provided the full email ID and password as someone@somedomain.com
[Kindly note, we have courier-imap and it requires full Email ID as user name]
Now we hit the login button.

D. Results:

Oops!!! Drupal could not log me in. It says, "Sorry. Unrecognized username or password."
I retyped the password in the same page (which was showing me error) and Yes, It logged me in !!!

So, what could be the reasons!!!!

Now, I tried to authenticate the IMAP server that we have using telnet from the command prompt. Following are the outcome,
**********************************************************************************************************
[root@www root]# telnet www.somedomain.com 143
Trying xxx.xxx.xxx.xxx...
Connected to www.somedomain.com.
Escape character is '^]'.
* OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE]Courier-IMAP
ready. Copyright 1998-2005 Double Precision, Inc. See COPYING for distribution information.
@ login someone@somedomain.com xxxxxxxx
@ OK LOGIN Ok.
. logout
* BYE Courier-IMAP server shutting down
. OK LOGOUT completed
Connection closed by foreign host.
**********************************************************************************************************

Thus, we felt there is no issues with the IMAP server of ours. Something is wrong in the core module itself.

E. Solution:

We open the file imap_auth.module to investigate the issues, following are our findings;

* The line 72 is supposed replace the local auth with imap_auth but because of typo it added an additional auth
Solution: Line 72: change 'key' to $key

* The line 154 is supposed to decide when to use imap_auth. The orginal code fails for local auth- the userid without @ are also qualified for
imap_auth
Solution: Line 154: change || to &&

* The line 118 makes wrong assumptions for our IMAP server. As said before, we have courier-imap which requires full email id as username. So
swap line 118 with 130;

line 118: $mbox = @imap_open($mailbox, $username, $password);
swap with
line 130: $mbox = @imap_open($mailbox, $username . '@' . $server, $password);

F. Test again:
We did the same thing as described in C. and Guess what, We are DONE !!!
No login issues anymore... :-)

The whole credit goes to S.P. Mandal, who has taken the pain to find the above solution.

Do let us know if that helped you in any way or you have some alternative solutions to this one.
Feel free to post your comments...

Regards,
- A novice drupal user.

Thanks a lot!!!

ani7a - June 25, 2009 - 17:48

Thanks, all worked just fine with this changes.

My only comment is that, at the first test, after the first attemp, the user was already logged in (but drupal displays an error like the one when user is wrong), no need for re enter the pass just go to /user again to see that the user was in fact logged in.

Thanks again.

Ana

 
 

Drupal is a registered trademark of Dries Buytaert.