configuration.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # encoding: utf-8
  2. #
  3. # Thanks to Nicolas Fouché for this wrapper
  4. #
  5. require 'singleton'
  6. module Mail
  7. # The Configuration class is a Singleton used to hold the default
  8. # configuration for all Mail objects.
  9. #
  10. # Each new mail object gets a copy of these values at initialization
  11. # which can be overwritten on a per mail object basis.
  12. class Configuration
  13. include Singleton
  14. def initialize
  15. @delivery_method = nil
  16. @retriever_method = nil
  17. super
  18. end
  19. def delivery_method(method = nil, settings = {})
  20. return @delivery_method if @delivery_method && method.nil?
  21. @delivery_method = lookup_delivery_method(method).new(settings)
  22. end
  23. def lookup_delivery_method(method)
  24. case method
  25. when nil
  26. Mail::SMTP
  27. when :smtp
  28. Mail::SMTP
  29. when :sendmail
  30. Mail::Sendmail
  31. when :exim
  32. Mail::Exim
  33. when :file
  34. Mail::FileDelivery
  35. when :smtp_connection
  36. Mail::SMTPConnection
  37. when :test
  38. Mail::TestMailer
  39. else
  40. method
  41. end
  42. end
  43. def retriever_method(method = nil, settings = {})
  44. return @retriever_method if @retriever_method && method.nil?
  45. @retriever_method = lookup_retriever_method(method).new(settings)
  46. end
  47. def lookup_retriever_method(method)
  48. case method
  49. when nil
  50. Mail::POP3
  51. when :pop3
  52. Mail::POP3
  53. when :imap
  54. Mail::IMAP
  55. when :test
  56. Mail::TestRetriever
  57. else
  58. method
  59. end
  60. end
  61. def param_encode_language(value = nil)
  62. value ? @encode_language = value : @encode_language ||= 'en'
  63. end
  64. end
  65. end