Last active
May 4, 2017 11:39
-
-
Save Kameshwaran/13aa2dca20d3bd9785f65f89445527b5 to your computer and use it in GitHub Desktop.
Command line tool to read emails through Mailman
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# This file defines the configuration for mail reading through pop3 protocol | |
# using 'Mailman' library. Place this file inside `config/initializers` if you are on Rails. | |
# Poll interval must be specified seconds, it defaults to 10 seconds | |
Mailman.config.poll_interval = (ENV['MAILBOX_POLL_INTERVAL'] || 10).to_i | |
# POP3 settings | |
Mailman.config.pop3 = { | |
server: ENV['POP3_SERVER'], | |
port: (ENV['POP3_PORT'] || 995).to_i, | |
ssl: (ENV['SSL_ENABLED_IN_POP3_SERVER'] == 'true'), | |
username: ENV['POP3_USERNAME'], | |
password: ENV['POP3_PASSWORD'] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# This file must be placed under `bin` folder of project's root directory. | |
# frozen_string_literal: true | |
require File.expand_path('../config/environment', __dir__) | |
print_help_and_exit = false | |
daemonizable = false | |
logfile = nil | |
ARGV.each_with_index do |arg, index| | |
case arg | |
when '-h', '--help' then print_help_and_exit = true | |
when '-l', '--logfile' then logfile = ARGV[index + 1] | |
when '-d', '--daemonize' then daemonizable = true | |
end | |
end | |
if print_help_and_exit | |
puts 'readmail [...OPTIONS]' | |
puts '-d or --daemonize Daemonize the process' | |
puts '-l or --logfile [FILE] Path to logfile' | |
puts '-h or --help Prints this message' | |
else | |
logger = ::Logger.new(logfile || ::Logger::STDOUT) | |
::Process.daemon(true, true) if daemonizable | |
Mailman::Application.run do | |
default do | |
begin | |
logger.info message.from.first | |
logger.info message.to.first | |
logger.info message.subject | |
rescue StandardError => er | |
Mailman.logger.fatal er.message | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment