Created
June 22, 2012 16:14
-
-
Save sulrich/2973772 to your computer and use it in GitHub Desktop.
script to push mail message into omnifocus from mutt
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/local/bin/ruby | |
require 'rubygems' | |
require 'mail' | |
require 'appscript'; include Appscript | |
require 'iconv' | |
message = STDIN.read | |
mail = Mail.new(message) | |
notes = "" | |
if mail.multipart? then | |
mail.parts.map do |p| | |
if p.content_type =~ /text\/plain/ | |
notes << p.body.decoded << "\n" | |
notes << "------------------------\n" | |
elsif p.content_type =~ /multipart\/alternative/ | |
nest = Mail.new(p) | |
nest.parts.map do |n| | |
if n.content_type =~ /text\/plain/ | |
notes << n.body.decoded << "\n" | |
else | |
notes << "[non-text attachment]\n" | |
end | |
end | |
# end of processing multipart/alternative | |
else | |
notes << "[non-text attachment]\n" | |
end | |
end | |
else | |
notes << mail.body.decoded | |
end | |
notes.force_encoding('UTF-8') | |
# this forces the transliteration of a number of characters. if i were | |
# really thinking here, i'd iterate through the from charsets more | |
# flexibly. | |
unote = Iconv.conv("UTF-8//IGNORE//TRANSLIT", "CP1252", notes) | |
of = app('OmniFocus') | |
tasks = of.default_document | |
tasks.make( :new => :inbox_task, | |
:with_properties => {:name => mail.subject, :note => unote} ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment