lib/waddup/sources/apple_mail.rb in waddup-0.0.2 vs lib/waddup/sources/apple_mail.rb in waddup-0.1.0
- old
+ new
@@ -1,56 +1,32 @@
module Waddup
class Source::AppleMail < Waddup::Source
include Waddup::Extension::AppleScript
extend Waddup::Extension::AppleScript
+ extend Waddup::Extension::FileSystem
ALIAS = 'mail'
ICON = "\xE2\x9C\x89\xEF\xB8\x8F "
- # Until OSX Mavericks handles Gmail's sent-mailbox correctly, resort to
- # iterating through all mailboxes and identify sent messages by sender
- #
- # See: http://tidbits.com/article/14219
- SENT_MAIL_SCRIPT = %Q{
- on run argv
- set window_from to date (item 1 of argv)
- set window_to to date (item 2 of argv)
+ SENT_MAIL_SCRIPT = folder_of(__FILE__) + 'apple_mail/sent_mail.applescript'
- tell application "Mail"
- set results to {}
-
- repeat with acct in every account
- set username to user name of acct
- set mboxes to (messages whose sender contains username and date sent >= window_from and date sent <= window_to) in every mailbox in acct
- repeat with mbox in mboxes
- repeat with msg in mbox
- set the end of results to {subject:subject of msg, datetime:date sent of msg as string}
- end
- end repeat
- end repeat
-
- results
- end tell
- end run
- }
-
# Aggregates sent mail events
#
# Arguments:
#
# :from (datetime)
# :to (datetime)
#
def events(from, to)
results = applescript SENT_MAIL_SCRIPT,
- :as_ruby => true,
- :args => [from.strftime('%d/%m/%Y %H:%M'), to.strftime('%d/%m/%Y %H:%M')]
+ as_ruby: true,
+ args: [from.strftime('%d/%m/%Y %H:%M'), to.strftime('%d/%m/%Y %H:%M')]
results.map do |result|
Waddup::Event.new do |e|
e.label = result[:subject]
- e.at = DateTime.parse(result[:datetime])
+ e.at = Time.parse(result[:datetime])
e.source = self
end
end
end