Class: Command::Mail
Instance Method Summary
collapse
Methods inherited from CommandBase
execute!, #load_local_settings
Constructor Details
#initialize ⇒ Mail
Returns a new instance of Mail.
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/command/mail.rb', line 15
def initialize
super("[<target1> <target2> ...]")
@opt.separator "\n \u30FB\u4E3B\u306BSend to Kindle\u3092\u4F7F\u3046\u305F\u3081\u306E\u30B3\u30DE\u30F3\u30C9\u3067\u3059\u3002\n \u30FB<target>\u3067\u6307\u5B9A\u3057\u305F\u5C0F\u8AAC\u306E\u96FB\u5B50\u66F8\u7C4D\u30C7\u30FC\u30BF\u30E1\u30FC\u30EB\u3067\u9001\u4FE1\u3057\u307E\u3059\u3002\n \u30FB<target>\u3092\u7701\u7565\u3057\u305F\u5834\u5408\u3001\u65B0\u7740\u304C\u3042\u3063\u305F\u5C0F\u8AAC\u3092\u5168\u3066\u9001\u4FE1\u3057\u307E\u3059\u3002\n \u30FB\u30E1\u30FC\u30EB\u306E\u9001\u4FE1\u8A2D\u5B9A\u306F\u3001\#{Mailer::SETTING_FILE}\u30D5\u30A1\u30A4\u30EB\u3092\u7DE8\u96C6\u3057\u307E\u3059\u3002\n(\u521D\u3081\u3066\u30B3\u30DE\u30F3\u30C9\u3092\u4F7F\u3046\u3068\u304D\u306B\u81EA\u52D5\u3067\u4F5C\u6210\u3055\u308C\u307E\u3059)\n\n Example:\nnarou mail 6 # \u65B0\u7740\u95A2\u4FC2\u306A\u304F\u30E1\u30FC\u30EB(\u9001\u4FE1\u6E08\u307F\u30D5\u30E9\u30B0\u306F\u7ACB\u3064)\n\nnarou update\nnarou mail # update\u3067\u65B0\u7740\u304C\u3042\u3063\u305F\u5C0F\u8AAC\u3092\u5168\u3066\u30E1\u30FC\u30EB\n\nnarou mail --force # \u51CD\u7D50\u6E08\u4EE5\u5916\u306E\u5168\u3066\u306E\u5C0F\u8AAC\u3092\u5F37\u5236\u7684\u306B\u30E1\u30FC\u30EB(\u4F7F\u3044\u65B9\u306B\u6CE8\u610F)\n\n Options:\n EOS\n\n @opt.on(\"-f\", \"--force\", \"\u5168\u3066\u306E\u5C0F\u8AAC\u3092\u5F37\u5236\u7684\u306B\u9001\u4FE1\") {\n @options[\"force\"] = true\n }\nend\n"
|
Instance Method Details
#alter_database_add_column_last_mail_date ⇒ Object
122
123
124
125
126
127
128
|
# File 'lib/command/mail.rb', line 122
def alter_database_add_column_last_mail_date
database = Database.instance
database.each do |id, data|
data["last_mail_date"] ||= Time.now
end
database.save_database
end
|
#execute(argv) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/command/mail.rb', line 41
def execute(argv)
super
send_all = false
device = Narou.get_device
database = Database.instance
begin
mailer = Mailer.create
rescue Mailer::SettingNotFound => e
install_mailer_setting
return
rescue Mailer::SettingUncompleteError => e
error e.message
exit 1
end
if argv.empty?
send_all = true
database.each_key do |id|
next if Narou.novel_frozen?(id)
argv << id
end
end
argv.each do |target|
ebook_path = Narou.get_ebook_file_path(target, device ? device.ebook_file_ext : ".epub")
unless ebook_path
error "#{target} は存在しません" unless send_all
next
end
data = Downloader.get_data_by_target(target)
if send_all && !@options["force"]
new_arrivals_date = data["new_arrivals_date"] || Time.now
if data["last_mail_date"] && new_arrivals_date < data["last_mail_date"]
next
end
end
unless File.exists?(ebook_path)
error "まだファイル(#{File.basename(ebook_path)})が無いようです" unless send_all
next
end
id = data["id"]
title = data["title"]
puts "<green>ID:#{id} #{TermColor.escape(title)}</green>".termcolor
print "メールを送信しています"
exit_mail = false
mail_result = nil
Thread.new do
mail_result = mailer.send(File.basename(ebook_path), ebook_path)
exit_mail = true
end
until exit_mail
print "."
sleep(0.5)
end
puts
if mail_result
puts File.basename(ebook_path) + " をメールで送信しました"
database[id]["last_mail_date"] = Time.now
else
error "#{mailer.error_message}"
exit 1
end
end
rescue Interrupt
puts "メール送信を中断しました"
exit 1
ensure
database.save_database if database
end
|
#install_mailer_setting ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/command/mail.rb', line 109
def install_mailer_setting
setting_file_path = File.join(Narou.get_preset_dir, Mailer::SETTING_FILE)
install_path = File.join(Narou.get_root_dir, Mailer::SETTING_FILE)
FileUtils.cp(setting_file_path, install_path)
alter_database_add_column_last_mail_date
puts "created #{install_path}"
puts "メールの設定用ファイルを作成しました。設定ファイルを書き換えることで mail コマンドが有効になります。"
puts "注意:次回以降のupdateで新着があった場合に送信可能フラグが立ちます"
if Helper.confirm("設定ファイルがあるフォルダを開きますか")
Helper.open_directory(Narou.get_root_dir)
end
end
|
#oneline_help ⇒ Object
11
12
13
|
# File 'lib/command/mail.rb', line 11
def oneline_help
"変換したEPUB/MOBIをメールで送信します"
end
|