replyr 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c6c41bcadd8c68ea3ea35081427e8c5a8efe6a86
4
- data.tar.gz: 3d92a5ba1279b30887d2e9c1aebc90b1be5b127b
3
+ metadata.gz: f87aae31a3317413213744f8bd2f0696d919298b
4
+ data.tar.gz: f87f27905023ca6456df8517cc220587ebf0044a
5
5
  SHA512:
6
- metadata.gz: 8c1bff8dbcdadcd1795f10cda3ef8443af24c25a1a9c76eb53d09941cc6319be2f2f86e83c71050e44ff041ce295f3a3a61768d08cfb2c2359b3d90b03c7556e
7
- data.tar.gz: c6c4c8a0bbc73da85bf3a6569083c580878992571833bf4916fffdf729792a492ac74087e3a63c2ccfc166b90646774cb9aa5b3939e1479647b7f2ddc5b2f1ea
6
+ metadata.gz: 64322ae65ccf1db378b2aa814a7e47ca5d68ca03f7c260595a0e1c19871ad314aaad0558dd816f435af5254fb8dd718aed130cb632657dc7e498d0d2a2550e21
7
+ data.tar.gz: 1de09c12bb51d5003b1cad581a75c37bc9faa884bd31a230da7929c69ed84a56d87dd023a1ee928fd26eec14bf8c788fd6ef9fa92d81da6becacecb2922b09d2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## v0.0.4
2
+
3
+ - Monkeypatch mailman, because of invalid dependency (listen gem)
4
+ - Fix bug concerning decoding body of a message
5
+
1
6
  ## v0.0.3
2
7
 
3
8
  Fix outdated mailman dependency (gem listen, "< 2.0.0")
@@ -0,0 +1,152 @@
1
+ require 'rbconfig'
2
+
3
+ module Mailman
4
+ IS_WINDOWS = (RbConfig::CONFIG['target_os'] =~ /mswin|mingw|cygwin/i)
5
+
6
+ # The main application class. Pass a block to {#new} to create a new app.
7
+ class Application
8
+
9
+ def self.run(config=nil, &block)
10
+ if config
11
+ app = new(config, &block)
12
+ else
13
+ app = new(&block)
14
+ end
15
+ app.run
16
+ app
17
+ end
18
+
19
+ # @return [Router] the app's router
20
+ attr_reader :router
21
+
22
+ # @return [MessageProcessor] the app's message processor
23
+ attr_reader :processor
24
+
25
+ # @return [Config] the apps's configuration
26
+ attr_reader :config
27
+
28
+ # Creates a new router, and sets up any routes passed in the block.
29
+ # @param [Hash] options the application options
30
+ # @option options [true,false] :graceful_death catch interrupt signal and don't die until end of poll
31
+ # @param [Proc] block a block with routes
32
+
33
+ def initialize(config=:default, &block)
34
+ @router = Mailman::Router.new
35
+ @config = select_config(config)
36
+ @processor = MessageProcessor.new(:router => @router, :config => @config)
37
+
38
+ if self.config.maildir
39
+ require 'maildir'
40
+ @maildir = Maildir.new(self.config.maildir)
41
+ end
42
+
43
+ instance_eval(&block) if block_given?
44
+ end
45
+
46
+ def polling?
47
+ config.poll_interval > 0 && !@polling_interrupt
48
+ end
49
+
50
+ # Sets the block to run if no routes match a message.
51
+ def default(&block)
52
+ @router.default_block = block
53
+ end
54
+
55
+ # Runs the application.
56
+ def run
57
+ Mailman.logger.info "Mailman v#{Mailman::VERSION} started"
58
+
59
+ if config.rails_root
60
+ rails_env = File.join(config.rails_root, 'config', 'environment.rb')
61
+ if File.exist?(rails_env) && !(defined?(Rails) && Rails.env)
62
+ Mailman.logger.info "Rails root found in #{config.rails_root}, requiring environment..."
63
+ require rails_env
64
+ end
65
+ end
66
+
67
+ if config.graceful_death
68
+ # When user presses CTRL-C, finish processing current message before exiting
69
+ Signal.trap("INT") { @polling_interrupt = true }
70
+ end
71
+
72
+ # STDIN
73
+ if !IS_WINDOWS && !config.ignore_stdin && $stdin.fcntl(Fcntl::F_GETFL, 0) == 0
74
+ Mailman.logger.debug "Processing message from STDIN."
75
+ @processor.process($stdin.read)
76
+
77
+ # IMAP
78
+ elsif config.imap
79
+ options = {:processor => @processor}.merge(config.imap)
80
+ Mailman.logger.info "IMAP receiver enabled (#{options[:username]}@#{options[:server]})."
81
+ polling_loop Receiver::IMAP.new(options)
82
+
83
+ # POP3
84
+ elsif config.pop3
85
+ options = {:processor => @processor}.merge(config.pop3)
86
+ Mailman.logger.info "POP3 receiver enabled (#{options[:username]}@#{options[:server]})."
87
+ polling_loop Receiver::POP3.new(options)
88
+
89
+ # Maildir
90
+ elsif config.maildir
91
+
92
+ Mailman.logger.info "Maildir receiver enabled (#{config.maildir})."
93
+
94
+ Mailman.logger.debug "Processing new message queue..."
95
+ @maildir.list(:new).each do |message|
96
+ @processor.process_maildir_message(message)
97
+ end
98
+
99
+ if config.watch_maildir
100
+ require 'listen'
101
+ Mailman.logger.debug "Monitoring the Maildir for new messages..."
102
+ base = Pathname.new(@maildir.path)
103
+
104
+ callback = Proc.new do |modified, added, removed|
105
+ added.each do |new_file|
106
+ message = Maildir::Message.new(@maildir, Pathname.new(new_file).relative_path_from(base).to_s)
107
+ @processor.process_maildir_message(message)
108
+ end
109
+ end
110
+
111
+ @listener = Listen::Listener.new(File.join(@maildir.path, 'new'), &callback)
112
+ @listener.start
113
+ sleep
114
+ end
115
+ end
116
+ end
117
+
118
+ private
119
+
120
+ def select_config(new_config)
121
+ return Mailman.config if new_config == :default
122
+ return new_config if new_config.is_a?(Configuration)
123
+ return Configuration.from_hash(new_config) if new_config.is_a?(Hash)
124
+ return Configuration.new
125
+ end
126
+
127
+ # Run the polling loop for the email inbox connection
128
+ def polling_loop(connection)
129
+ if polling?
130
+ polling_msg = "Polling enabled. Checking every #{config.poll_interval} seconds."
131
+ else
132
+ polling_msg = "Polling disabled. Checking for messages once."
133
+ end
134
+ Mailman.logger.info(polling_msg)
135
+
136
+ loop do
137
+ begin
138
+ connection.connect
139
+ connection.get_messages
140
+ rescue SystemCallError => e
141
+ Mailman.logger.error e.message
142
+ ensure
143
+ connection.disconnect
144
+ end
145
+
146
+ break unless polling?
147
+ sleep config.poll_interval
148
+ end
149
+ end
150
+
151
+ end
152
+ end
@@ -6,7 +6,7 @@ module Replyr
6
6
  self.to = mail.to.first
7
7
  self.from = mail.from.first
8
8
  self.subject = mail.subject
9
- self.body = mail.decoded # Returns the decoded text from the mail in UTF-8 format
9
+ self.body = mail.multipart? ? mail.text_part.decoded : mail.decoded
10
10
 
11
11
  # Extract Attachments and store as StringIO in attached_files
12
12
  # can later be processed by e.g. carrierwave
@@ -1,3 +1,3 @@
1
1
  module Replyr
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/replyr.rb CHANGED
@@ -6,6 +6,9 @@ require "replyr/reply_address"
6
6
  require "replyr/handle_reply"
7
7
  require 'replyr/engine'
8
8
 
9
+ # Monkey Patch broken listen dependency in mailman v0.7.0
10
+ require 'mailman_monkey_patch' if Mailman::VERSION == "0.7.0"
11
+
9
12
  module Replyr
10
13
  class << self
11
14
  attr_accessor :config, :logger
Binary file