Created
August 8, 2012 00:40
-
-
Save tekei/3290956 to your computer and use it in GitHub Desktop.
icloudに格納したメモ帳をテキストファイルとしてダウンロードする
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
# -*- coding: utf-8 -*- | |
# icloudに格納したメモ帳をテキストファイルとしてダウンロードする | |
# ファイル名は、[更新日付-タイトル.txt] | |
require 'mail' | |
require 'cgi' | |
account = '(ユーザ名)@me.com' | |
pass = '(パスワード)' | |
Mail.defaults do | |
retriever_method :imap, :address => "imap.mail.me.com", | |
:port => 993, | |
:user_name => account, | |
:password => pass, | |
:enable_ssl => true | |
end | |
c_before = "\\/:*?\"<>|" | |
c_after = "\/:*?"<>|" | |
Mail.find(:mailbox => 'Notes', :keys => 'undeleted', :count => 500) { |email| | |
file_name = "#{email.date.strftime("%Y%m%d")}-#{email.subject}.txt" | |
file_name.gsub!(/([#{c_before}])/) { c_after[c_before.index($1)] } | |
file_name.encode!("windows-31j", :undef => :replace, :replace => '#') | |
open(file_name, "w:utf-8") do |f| | |
body = email.body.decoded.encode("utf-8", email.charset) | |
body.gsub!('</div>', "\n") | |
body.gsub!(/<[^>]*>/, "") | |
f << CGI.unescapeHTML(body).gsub(" ", "") | |
end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
実行する際のメモ
もし、windows上で無い場合は、24行目を削除して実行してください。
「me.comのメールアドレス」はhttps://www.icloud.com/#mailから環境設定→アカウントで確認できます。
passは、appleIDのパスワードと同じです。