tommorris (owner)

Revisions

gist: 125381 Download_button fork
public
Description:
thingsproc - a simple script to grab mail out of a POP3 box and add it to Things.app
Public Clone URL: git://gist.github.com/125381.git
thingsproc.rb
1
2
3
4
5
6
7
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
36
37
38
39
40
require 'rubygems'
require 'rbosa'
require 'tmail'
require 'net/pop'
 
opts = {:username => '[ur pop box]', :password => '[ur pw!]', :server => '[ur server]'}
 
 
pop = Net::POP3.new(opts[:server])
pop.start(opts[:username], opts[:password])
things = OSA.app('Things')
inbox = things.lists.collect {|i| i if i.name.match /Inbox/ }.delete_if {|i| i.nil? }.first
 
def remove_sig (str)
  if str.match /--\n/
    str.split("-- ").first
  else
    str
  end
end
 
if pop.mails.empty?
  exit
else
  pop.each_mail do |mail|
    message = TMail::Mail.parse(mail.pop())
    message_body = remove_sig(message.body)
    todo = Hash.new
    if message.subject.size != 0
      todo[:name] = message.subject.strip
      if message_body.strip.size != 0
        todo[:note] = message_body.strip
      end
    elsif message_body.strip.size != 0
      todo[:name] = message_body.strip
    end
    things.make(OSA::Things::ToDo, inbox, todo)
    mail.delete
  end
end