Class: Mail2FrontMatter::Watcher

Inherits:
Object
  • Object
show all
Defined in:
lib/mail2frontmatter/watcher.rb

Class Method Summary collapse

Class Method Details

.runObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/mail2frontmatter/watcher.rb', line 8

def self.run
  mail_protocol = Mail2FrontMatter.config[:protocol] || :imap
  poll_interval = Mail2FrontMatter.config[:interval] || 60

  @receiver = Mail2FrontMatter.config[:receiver]
  @senders  = Mail2FrontMatter.config[:senders]

  Mailman.config.poll_interval = poll_interval
  Mailman.config.ignore_stdin = true

  Mailman.config.send("#{mail_protocol}=", Mail2FrontMatter.config[:mailman])
  Mailman.config.logger = Mail2FrontMatter.logger

  Mailman::Application.run do
    from(@senders).to(@receiver) do
      logger = Mailman.config.logger

      logger.info('parsing message...')
      parser = Mail2FrontMatter::Parser.new(message)

      logger.info('processing body and attachments...')
      , body = Mail2FrontMatter::PreProcessor.process(parser., parser.body)

      logger.info('saving processed post...')
      Mail2FrontMatter::Writer.write(, body)
    end
  end
end