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 | |
} |
実行する際のメモ
- 最初に gem install mail してください
- windows上で実行する事を念頭にしています。
もし、windows上で無い場合は、24行目を削除して実行してください。 - accountには、appleIDではなくme.comのメールアドレスを入力してください。
「me.comのメールアドレス」はhttps://www.icloud.com/#mailから環境設定→アカウントで確認できます。
passは、appleIDのパスワードと同じです。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
上記2, 3行目うまく書けてないので、修正
・ 1行毎に<div>~</div>で囲まれている。空行は、 <div><br></div>
・ 行先頭の場合、半角スペース1個は" "と出力されている