tpitale / mail_room

Forward mail from gmail IMAP to a callback URL or job worker, simply.
MIT License
195 stars 51 forks source link

Faraday API change, connection.basic_auth removed #155

Closed erwin closed 1 year ago

erwin commented 1 year ago

Before this patch, I was getting the following error each time mail_room received a message and tried to use the postbackto ActionMailbox.

(NoMethodError) connection.basic_auth( ``` #, @formatter=nil, @logdev=nil>> # terminated with exception (report_on_exception is true): /home/app/webapp/gems/ruby/3.1.0/gems/mail_room-0.10.0/lib/mail_room/delivery/postback.rb:52:in `deliver': undefined method `basic_auth' for #"Faraday v2.7.4"}, @params={}, @options=#, @ssl=#, @default_parallel_manager=nil, @manual_proxy=false, @builder=#, @url_prefix=#, @proxy=nil> (NoMethodError) connection.basic_auth( ^^^^^^^^^^^ from /home/app/webapp/gems/ruby/3.1.0/gems/mail_room-0.10.0/lib/mail_room/mailbox.rb:109:in `deliver' from /home/app/webapp/gems/ruby/3.1.0/gems/mail_room-0.10.0/lib/mail_room/mailbox_watcher.rb:30:in `block in run' from /home/app/webapp/gems/ruby/3.1.0/gems/mail_room-0.10.0/lib/mail_room/connection.rb:141:in `map' from /home/app/webapp/gems/ruby/3.1.0/gems/mail_room-0.10.0/lib/mail_room/connection.rb:141:in `process_mailbox' from /home/app/webapp/gems/ruby/3.1.0/gems/mail_room-0.10.0/lib/mail_room/connection.rb:51:in `wait' from /home/app/webapp/gems/ruby/3.1.0/gems/mail_room-0.10.0/lib/mail_room/mailbox_watcher.rb:35:in `block in run' bundler: failed to load command: mail_room (/home/app/webapp/gems/ruby/3.1.0/bin/mail_room) /home/app/webapp/gems/ruby/3.1.0/gems/mail_room-0.10.0/lib/mail_room/delivery/postback.rb:52:in `deliver': undefined method `basic_auth' for #"Faraday v2.7.4"}, @params={}, @options=#, @ssl=#, @default_parallel_manager=nil, @manual_proxy=false, @builder=#, @url_prefix=#, @proxy=nil> (NoMethodError) connection.basic_auth( ^^^^^^^^^^^ from /home/app/webapp/gems/ruby/3.1.0/gems/mail_room-0.10.0/lib/mail_room/mailbox.rb:109:in `deliver' from /home/app/webapp/gems/ruby/3.1.0/gems/mail_room-0.10.0/lib/mail_room/mailbox_watcher.rb:30:in `block in run' from /home/app/webapp/gems/ruby/3.1.0/gems/mail_room-0.10.0/lib/mail_room/connection.rb:141:in `map' from /home/app/webapp/gems/ruby/3.1.0/gems/mail_room-0.10.0/lib/mail_room/connection.rb:141:in `process_mailbox' from /home/app/webapp/gems/ruby/3.1.0/gems/mail_room-0.10.0/lib/mail_room/connection.rb:51:in `wait' from /home/app/webapp/gems/ruby/3.1.0/gems/mail_room-0.10.0/lib/mail_room/mailbox_watcher.rb:35:in `block in run' ```

According to: https://lostisland.github.io/faraday/middleware/authentication

Faraday 2.x+ no longer support the: connection.basic_auth function.

This patch just tests if connection.basic_auth is defined (1.x) and if so calls it, otherwise must be the 2.x version of the API.

Basic Authentication

The middleware will automatically Base64 encode your Basic username and password:

Faraday.new(...) do |conn|
 conn.request :authorization, :basic, 'username', 'password'
end
tpitale commented 1 year ago

Looks good. I'll review more and merge when I can get on my laptop.