# IMAP\_Authenticatable Problem

**URL:** <https://www.ruby-forum.com/t/imap-authenticatable-problem/156102>\
**Category:** Rails\
**Created:** [December 20, 2008, 5:31pm UTC](https://www.ruby-forum.com/t/imap-authenticatable-problem/156102 "2008-12-20T17:31:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pete\_Bekisz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8edcca/32.png) [@Pete\_Bekisz](https://www.ruby-forum.com/u/Pete_Bekisz)\
**Post date:** [December 20, 2008, 5:31pm UTC](https://www.ruby-forum.com/t/imap-authenticatable-problem/156102/1 "2008-12-20T17:31:13Z")

</div>

Good morning all,  
I’ve been using the imap\_authenticatable plugin for about a year now  
without  
incident. All of a sudden, I tried logging in this morning and this  
error is  
showing up in the logs. Does anyone have any idea what could be causing  
this  
or how to fix it?

Thanks,  
Pete

NoMethodError (undefined method `disconnect' for nil:NilClass): /vendor/plugins/imap_authenticatable/lib/imap_authenticatable.rb:52:in`authenticate’  
/app/controllers/login\_controller.rb:13:in `login’

/usr/lib/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/base.rb:1095:in  
`send’

/usr/lib/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/base.rb:1095:in  
`perform\_action\_without\_filters’

/usr/lib/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:632:in  
`call\_filter’

/usr/lib/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:634:in  
`call\_filter’

/usr/lib/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:619:in  
`perform\_action\_without\_benchmark’

/usr/lib/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/benchmarking.rb:66:in  
`perform_action_without_rescue' /usr/lib/ruby/1.8/benchmark.rb:293:in`measure’

/usr/lib/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/benchmarking.rb:66:in  
`perform\_action\_without\_rescue’

/usr/lib/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/rescue.rb:83:in  
`perform\_action’

/usr/lib/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/base.rb:430:in  
`send’

/usr/lib/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/base.rb:430:in  
`process\_without\_filters’

/usr/lib/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/filters.rb:624:in  
`process\_without\_session\_management\_support’

/usr/lib/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/session\_management.rb:114:in  
`process’

/usr/lib/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/base.rb:330:in  
`process' /usr/lib/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in`dispatch’  
/usr/lib/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:78:in  
`process' /usr/lib/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in`synchronize’  
/usr/lib/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in  
`process' /usr/lib/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:618:in`process\_client’  
/usr/lib/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in `each' /usr/lib/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in`process\_client’  
/usr/lib/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run' /usr/lib/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in`initialize’  
/usr/lib/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `new' /usr/lib/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in`run’  
/usr/lib/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in  
`initialize' /usr/lib/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in`new’  
/usr/lib/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `run' /usr/lib/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:271:in`run’  
/usr/lib/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in  
`each' /usr/lib/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in`run’  
/usr/lib/gems/1.8/gems/mongrel-1.0.1/bin/mongrel\_rails:127:in `run' /usr/lib/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:211:in`run’  
/usr/lib/gems/1.8/gems/mongrel-1.0.1/bin/mongrel\_rails:243  
/usr/bin/mongrel\_rails:16:in `load’  
/usr/bin/mongrel\_rails:16

---

<div class="post-metadata">

**Author:** ![Pete\_Bekisz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8edcca/32.png) [@Pete\_Bekisz](https://www.ruby-forum.com/u/Pete_Bekisz)\
**Post date:** [December 22, 2008, 2:53pm UTC](https://www.ruby-forum.com/t/imap-authenticatable-problem/156102/2 "2008-12-22T14:53:08Z")

</div>

On Dec 20, 2008, at 11:30 AM, Pete Bekisz wrote:

> NoMethodError (undefined method `disconnect' for nil:NilClass): /vendor/plugins/imap_authenticatable/lib/imap_authenticatable.rb: 52:in `authenticate’

Well, I have no experience with imap\_authenticate, but you need to  
look at this line 52 in the plugin’s code to see what is the ‘nil’ and  
then find where that gets set. Chances are there’s a condition that’s  
not being properly checked for and the connection is never made; then  
when some later error happens, the cleanup to disconnect is getting  
called on the never-successfully opened instance.

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Pete\_Bekisz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8edcca/32.png) [@Pete\_Bekisz](https://www.ruby-forum.com/u/Pete_Bekisz)\
**Post date:** [December 22, 2008, 3:29pm UTC](https://www.ruby-forum.com/t/imap-authenticatable-problem/156102/3 "2008-12-22T15:29:00Z")

</div>

Hi Rob,  
Thanks for your answers. I switched the server from our authentication  
server over to our mail server and it seems to be running fine, so I’m  
assuming it’s an issue with the way the auth server handles IMAP/POP  
authentication. Here’s the code from the plugin:

```
    def authenticate(username, password)
      imap = Net::IMAP.new imap_authenicatable_options[:host],

```

imap\_authenicatable\_options[:port], imap\_authenicatable\_options[:ssl]  
username = clean\_username(username)  
imap.authenticate(‘LOGIN’, username, password)

```
      if imap_authenicatable_options[:allow_new_users]
        find_or_create_by_username(username)
      else
        find_by_username(username)
      end
    rescue
      false
    ensure
      imap.disconnect
    end

```

Does it sound like it’s an issue with the auth server to anyone else?

On Mon, Dec 22, 2008 at 8:52 AM, Rob B.

---

<div class="post-metadata">

**Author:** ![Pete\_Bekisz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8edcca/32.png) [@Pete\_Bekisz](https://www.ruby-forum.com/u/Pete_Bekisz)\
**Post date:** [December 22, 2008, 4:05pm UTC](https://www.ruby-forum.com/t/imap-authenticatable-problem/156102/4 "2008-12-22T16:05:22Z")

</div>

I’d say that a guard was needed on the disconnect call.

On Dec 22, 2008, at 9:28 AM, Pete Bekisz wrote:

> imap\_authenicatable\_options[:port], imap\_authenicatable\_options[:ssl]  
> ensure  
> imap.disconnect

imap.disconnect unless imap.nil?

> ```
> end
> 
> ```
> 
> Does it sound like it’s an issue with the auth server to anyone else?

With that naked rescue, it’s hard to say what the real problem is, but  
I suspect a connection problem over an authentication problem.

-Rob

> > any idea what could be causing this or how to fix it?  
> > and then find where that gets set. Chances are there’s a condition  
> > /usr/lib/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/  
> > benchmarking.rb:66:in `perform_action_without_rescue' filters.rb:624:in `process\_without\_session\_management\_support’  
> > /usr/lib/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in  
> > /usr/lib/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run' /usr/lib/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:127:in `run’  
> > /usr/lib/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:  
> > 211:in `run' /usr/lib/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:243 /usr/bin/mongrel_rails:16:in `load’  
> > /usr/bin/mongrel\_rails:16

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid
