replyr 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/mailman_monkey_patch.rb +152 -0
- data/lib/replyr/reply_email.rb +1 -1
- data/lib/replyr/version.rb +1 -1
- data/lib/replyr.rb +3 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +1404 -0
- data/test/replyr/reply_email_test.rb +1 -1
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f87aae31a3317413213744f8bd2f0696d919298b
|
4
|
+
data.tar.gz: f87f27905023ca6456df8517cc220587ebf0044a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64322ae65ccf1db378b2aa814a7e47ca5d68ca03f7c260595a0e1c19871ad314aaad0558dd816f435af5254fb8dd718aed130cb632657dc7e498d0d2a2550e21
|
7
|
+
data.tar.gz: 1de09c12bb51d5003b1cad581a75c37bc9faa884bd31a230da7929c69ed84a56d87dd023a1ee928fd26eec14bf8c788fd6ef9fa92d81da6becacecb2922b09d2
|
data/CHANGELOG.md
CHANGED
@@ -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
|
data/lib/replyr/reply_email.rb
CHANGED
@@ -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.
|
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
|
data/lib/replyr/version.rb
CHANGED
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
|
data/test/dummy/db/test.sqlite3
CHANGED
Binary file
|