# IMAP\_Authenticatable Problem

**URL:** <https://discuss.rubyonrails.org/t/imap-authenticatable-problem/37571>\
**Category:** rubyonrails-talk\
**Created:** [December 20, 2008, 4:30pm UTC](https://discuss.rubyonrails.org/t/imap-authenticatable-problem/37571 "2008-12-20T16:30:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pete7](https://avatars.discourse-cdn.com/v4/letter/p/9fc348/32.png) [@Pete7](https://discuss.rubyonrails.org/u/Pete7)\
**Post date:** [December 20, 2008, 4:30pm UTC](https://discuss.rubyonrails.org/t/imap-authenticatable-problem/37571/1 "2008-12-20T16:30:21Z")

</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:** ![rab](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/rab/32/710_2.png) [@rab](https://discuss.rubyonrails.org/u/rab)\
**Post date:** [December 22, 2008, 1:52pm UTC](https://discuss.rubyonrails.org/t/imap-authenticatable-problem/37571/2 "2008-12-22T13:52:21Z")

</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’

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 Biedenharn [http://agileconsultingllc.com](http://agileconsultingllc.com)

[Rob@AgileConsultingLLC.com](mailto:Rob@AgileConsultingLLC.com)

---

<div class="post-metadata">

**Author:** ![Pete7](https://avatars.discourse-cdn.com/v4/letter/p/9fc348/32.png) [@Pete7](https://discuss.rubyonrails.org/u/Pete7)\
**Post date:** [December 22, 2008, 2:28pm UTC](https://discuss.rubyonrails.org/t/imap-authenticatable-problem/37571/3 "2008-12-22T14:28:16Z")

</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?

---

<div class="post-metadata">

**Author:** ![rab](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/rab/32/710_2.png) [@rab](https://discuss.rubyonrails.org/u/rab)\
**Post date:** [December 22, 2008, 3:04pm UTC](https://discuss.rubyonrails.org/t/imap-authenticatable-problem/37571/4 "2008-12-22T15:04:37Z")

</div>

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

> 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

```
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

> 

> > > 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’

> >

> > 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 Biedenharn [http://agileconsultingllc.com](http://agileconsultingllc.com)

> > [Rob@AgileConsultingLLC.com](mailto:Rob@AgileConsultingLLC.com)

> >

> > > /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

Rob Biedenharn [http://agileconsultingllc.com](http://agileconsultingllc.com)

[Rob@AgileConsultingLLC.com](mailto:Rob@AgileConsultingLLC.com)
