前回は、PDF以外にも対応するため関連部分のコードを一つずつ見ていき、設定部分と動作部分を整理することができました。
今回も引き続き、PDF以外にも対応するための関連部分のコードを一つずつ見ていきます。 [asin:B07ZWCDYZG:detail] evernote.com trello.com
PDF以外にも対応する(その2)
それでは前回に引き続き一つずつ見ていって、統合作業を進めていくことにしましょう。
kindle_convert
pdfドキュメントを送り込む時のみに作用するようにしておきます。したがって、コードは次のようになります。
# docsend_run (一部抜粋) set "docsend_default_custom" "kindle_run"; include "docsend_default_custom_bool"; if string :matches "${docsend_default_custom_bool}" "true" { if allof ( string :matches "${docsend_running}" "pdf", string :matches "${kindle_convert}" "true" ) { set "kindle_convert" "true"; } else { set "kindle_convert" "false"; } include "send-kindle"; }
# send-kindle require ["include", "copy", "editheader", "variables"]; global ["subject"]; global ["kindle_convert"]; if string :matches "${kindle_convert}" "true" { deleteheader "Subject"; addheader :last "Subject" "convert"; } else { deleteheader "Subject"; addheader :last "Subject" "${subject}"; } redirect :copy "example_to_kindle@kindle.com";
evernote_notebook
これは素直にpdf用とtext用の2回書いておくことにします。pdfをtextを同じノートブックに保存する場合は設定が重複することになります。(念のため補足しておくと、設定しない場合はevernote側のデフォルトのノートブックに保存されることになります。)
また、裏技として、evernote_notebookに直接設定できるようにしてあります。
# docsend_check_from (一部抜粋) if header :contains "From" "example1.co.jp" { set "docsend_check_from_default" "true"; set "kindle_convert" "true"; set "evernote_notebook_text" "テスト1"; set "evernote_notebook_pdf" "テスト1";
# docsend_run (一部抜粋) set "docsend_default_custom" "evernote_run"; include "docsend_default_custom_bool"; if string :matches "${docsend_default_custom_bool}" "true" { if allof ( string :matches "${docsend_running}" "text", not string :matches "${evernote_notebook_text}" "" ) { set "evernote_notebook" "evernote_notebook_text"; } if allof ( string :matches "${docsend_running}" "pdf", not string :matches "${evernote_notebook_pdf}" "" ) { set "evernote_notebook" "evernote_notebook_pdf"; } include "send-evernote"; }
trello_assgin
こちらもevernoteと同様の仕様にしておきます。
# docsend_check_from (一部抜粋) set "evernote_notebook_text" "テスト1"; set "evernote_notebook_pdf" "テスト2"; set "evernote_notebook" "テスト2"; set "docsend_default_custom" "trello_run"; include "docsend_default_custom_bool"; if string :matches "${docsend_default_custom_bool}" "true" { if allof ( string :matches "${docsend_running}" "text", not string :matches "${trello_assgin_text}" "" ) { set "trello_assign" "trello_assgin_text"; } if allof ( string :matches "${docsend_running}" "pdf", not string :matches "${trello_assign_pdf}" "" ) { set "trello_assign" "trello_assign_pdf"; } include "send-trello"; }
各サービスの送信先emailアドレス等を docsned_configに書くようにする
send-* に直書きされている、各サービスへの送信先のemailアドレスを "docsend_check_from" に集約しておき、名前を "docsend_config" に変更します。
#test6-1 (一部抜粋) require ["include", "variables", "mime", "foreverypart"]; global "subject"; global "docsend_default_custom_bool"; global "docsend_default_custom"; global "docsend_running"; # 元メールのSubject:を保存 if header :matches "Subject" "*" { set "subject" "${1}"; } include "docsend_config"; set "docsend_running" "text"; set "docsend_default_custom" "check_from"; include "docsend_default_custom_bool"; if string :matches "${docsend_default_custom_bool}" "true" { include "docsend_run"; include "trash"; } set "docsend_running" "pdf"; set "docsend_default_custom" "check_from"; include "docsend_default_custom_bool"; if string :matches "${docsend_default_custom_bool}" "true" { foreverypart { if header :mime :subtype "Content-Type" "pdf" { include "docsend_run"; break; } } include "trash"; } discard;
# docsend_config require ["include", "variables"]; # 以下の変数の値を設定(true/false)することができます global "docsend_check_from_default"; global "docsend_check_from_text"; global "docsend_check_from_pdf"; global "docsend_kindle_run_default"; global "docsend_kindle_run_text"; global "docsend_kindle_run_pdf"; global "docsend_evernote_run_default"; global "docsend_evernote_run_text"; global "docsend_evernote_run_pdf"; global "docsend_trello_run_default"; global "docsend_trello_run_text"; global "docsend_trello_run_pdf"; global "kindle_convert"; global "evernote_notebook"; global "evernote_notebook_text"; global "evernote_notebook_pdf"; global "trello_assign"; global "trello_assign_text"; global "trello_assign_pdf"; global "send_kindle_address"; global "send_evernote_address"; global "send_trello_address"; # 各サービスの送信先emailアドレス set "send_kindle_address" "example_to_kindle@kindle.com"; set "send_evernote_address" "example_to_evernote@m.evernote.com"; set "send_trello_address" "example_to_trello@boards.trello.com"; # default動作の設定 set "docsend_check_from_default" "false"; set "docsend_kindle_run_default" "true"; set "docsend_evernote_run_default" "true"; set "docsend_trello_run_default" "true"; # 送信元別の設定 if header :contains "From" "example1.co.jp" { set "docsend_check_from_default" "true"; set "kindle_convert" "true"; set "evernote_notebook_text" "テスト1"; set "evernote_notebook_pdf" "テスト2"; set "trello_assign_text" "exampleuser1"; set "trello_assign_pdf" "exampleuser2"; } elsif header :contains "From" "example2.co.jp" { set "docsend_check_from_default" "true"; set "evernote_notebook" "テスト1"; set "trello_assign" "exampleuser2"; } include "docsend_check_from_init";
# send-kindle require ["include", "copy", "editheader", "variables"]; global "send_kindle_address"; global ["subject"]; global ["kindle_convert"]; if string :matches "${kindle_convert}" "true" { deleteheader "Subject"; addheader :last "Subject" "convert"; } else { deleteheader "Subject"; addheader :last "Subject" "${subject}"; } redirect :copy "${send_kindle_address}";
# send-evernote require ["include", "copy", "editheader", "variables"]; global "send_evernote_address"; global ["subject"]; global ["evernote_notebook"]; deleteheader "Subject"; addheader :last "Subject" "${subject} @${evernote_notebook}"; redirect "${send_evernote_address}";
# send-trello require ["include", "copy", "editheader", "variables"]; global "send_trello_address"; global "send_trello_address"; global ["subject"]; deleteheader "Subject"; addheader :last "Subject" "【Kindle】 ${subject} @${trello_assign}"; redirect :copy "${send_trello_address}";
docsend_init に名称を変更
前回作成した docsend_check_from_init の名前を docsend_init に変更し、docsend_init からdocsend_config を呼び出すように呼び出し順を調整しておきます。これで大まかな処理の流れが docsend_init → docsend_config → docsend_run の順番に呼び出されることになり、何をやっているか分かりやすくなります。
また、メインから docsend処理を抜き出して別ファイルにしておきます。
#test6-2 require ["include", "variables"]; global "subject"; # 元メールのSubject:を保存 if header :matches "Subject" "*" { set "subject" "${1}"; } include "docsend"; discard;
# docsend require ["include", "variables", "mime", "foreverypart"]; global "docsend_default_custom_bool"; global "docsend_default_custom"; global "docsend_running"; include "docsend_init"; set "docsend_running" "text"; set "docsend_default_custom" "check_from"; include "docsend_default_custom_bool"; if string :matches "${docsend_default_custom_bool}" "true" { include "docsend_run"; include "trash"; } set "docsend_running" "pdf"; set "docsend_default_custom" "check_from"; include "docsend_default_custom_bool"; if string :matches "${docsend_default_custom_bool}" "true" { foreverypart { if header :mime :subtype "Content-Type" "pdf" { include "docsend_run"; break; } } include "trash"; }
# docsend_init require ["include", "variables"]; global "docsend_check_from_text_bool"; global "docsend_check_from_pdf_bool"; global "docsend_kindle_run_text_bool"; global "docsend_kindle_run_pdf_bool"; global "docsend_evernote_run_text_bool"; global "docsend_evernote_run_pdf_bool"; global "docsend_trello_run_text_bool"; global "docsend_trello_run_pdf_bool"; global "docsend_check_from_default"; global "docsend_check_from_text"; global "docsend_check_from_pdf"; global "docsend_kindle_run_default"; global "docsend_kindle_run_text"; global "docsend_kindle_run_pdf"; global "docsend_evernote_run_default"; global "docsend_evernote_run_text"; global "docsend_evernote_run_pdf"; global "docsend_trello_run_default"; global "docsend_trello_run_text"; global "docsend_trello_run_pdf"; # default動作 set "docsend_check_from_default" "false"; set "docsend_kindle_run_default" "true"; set "docsend_evernote_run_default" "true"; set "docsend_trello_run_default" "true"; include "docsend_config"; set "docsend_check_from_text_bool" "${docsend_check_from_default}"; if not string :matches "${docsend_check_from_text}" "" { set "docsend_check_from_text_bool" "${docsend_check_from_text}"; } set "docsend_check_from_pdf_bool" "${docsend_check_from_default}"; if not string :matches "${docsend_check_from_pdf}" "" { set "docsend_check_from_pdf_bool" "${docsend_check_from_pdf}"; } set "docsend_kindle_run_text_bool" "${docsend_kindle_run_default}"; if not string :matches "${docsend_kindle_run_text}" "" { set "docsend_kindle_run_text_bool" "${docsend_kindle_run_text}"; } set "docsend_kindle_run_pdf_bool" "${docsend_kindle_run_default}"; if not string :matches "${docsend_kindle_run_pdf}" "" { set "docsend_kindle_run_pdf_bool" "${docsend_kindle_run_pdf}"; } set "docsend_evernote_run_text_bool" "${docsend_evernote_run_default}"; if not string :matches "${docsend_evernote_run_text}" "" { set "docsend_evernote_run_text_bool" "${docsend_evernote_run_text}"; } set "docsend_evernote_run_pdf_bool" "${docsend_evernote_run_default}"; if not string :matches "${docsend_evernote_run_pdf}" "" { set "docsend_evernote_run_pdf_bool" "${docsend_evernote_run_pdf}"; } set "docsend_trello_run_text_bool" "${docsend_trello_run_default}"; if not string :matches "${docsend_trekki_run_text}" "" { set "docsend_trello_run_text_bool" "${docsend_trello_run_text}"; } set "docsend_trello_run_pdf_bool" "${docsend_trello_run_default}"; if not string :matches "${docsend_trello_run_pdf}" "" { set "docsend_trello_run_pdf_bool" "${docsend_trello_run_pdf}"; }
# docsend_config require ["include", "variables"]; # 以下の変数の値を設定(true/false)することができます global "docsend_check_from_default"; global "docsend_check_from_text"; global "docsend_check_from_pdf"; global "docsend_kindle_run_default"; global "docsend_kindle_run_text"; global "docsend_kindle_run_pdf"; global "docsend_evernote_run_default"; global "docsend_evernote_run_text"; global "docsend_evernote_run_pdf"; global "docsend_trello_run_default"; global "docsend_trello_run_text"; global "docsend_trello_run_pdf"; global "kindle_convert"; global "evernote_notebook"; global "evernote_notebook_text"; global "evernote_notebook_pdf"; global "trello_assign"; global "trello_assign_text"; global "trello_assign_pdf"; global "send_kindle_address"; global "send_evernote_address"; global "send_trello_address"; # 各サービスの送信先emailアドレス set "send_kindle_address" "example_to_kindle@kindle.com"; set "send_evernote_address" "example_to_evernote@m.evernote.com"; set "send_trello_address" "example_to_trello@boards.trello.com"; # 送信元別の設定 if header :contains "From" "example1.co.jp" { set "docsend_check_from_default" "true"; set "kindle_convert" "true"; set "evernote_notebook_text" "テスト1"; set "evernote_notebook_pdf" "テスト2"; set "trello_assign_text" "exampleuser1"; set "trello_assign_pdf" "exampleuser2"; } elsif header :contains "From" "example2.co.jp" { set "docsend_check_from_default" "true"; set "kindle_convert" "true"; set "evernote_notebook" "テスト1"; set "trello_assign" "exampleuser2"; }
随分メイン処理がスッキリしましたね。
これで、ひとまずPDFとTEXTを送り込む処理の統合作業は完成です。お疲れさまでした。
まとめ
今回は、PDFとTEXTを送り込むための統合作業を行いました。
次回は、もう少し使い勝手が良くなるように改造していきます。お楽しみに。
[asin:B07ZWCDYZG:detail]
evernote.com
trello.com
前回までの記事はこちらです。 tsh.hatenablog.jp tsh.hatenablog.jp tsh.hatenablog.jp tsh.hatenablog.jp tsh.hatenablog.jp tsh.hatenablog.jp tsh.hatenablog.jp