Class: Redwood::EditMessageMode
Constant Summary
collapse
- DECORATION_LINES =
1
%w(From To Cc Bcc Subject)
%w(To Cc Bcc)
%w(Message-id Date)
Instance Attribute Summary collapse
#curpos
Attributes inherited from ScrollMode
#botline, #leftcol, #topline
Attributes inherited from Mode
#buffer
Instance Method Summary
collapse
#cleanup, #draw
Methods inherited from ScrollMode
#at_bottom?, #at_top?, #cancel_search!, #col_jump, #col_left, #col_right, #continue_search_in_buffer, #draw, #ensure_mode_validity, #half_page_down, #half_page_up, #in_search?, #jump_to_col, #jump_to_end, #jump_to_left, #jump_to_line, #jump_to_start, #line_down, #line_up, #page_down, #page_up, #resize, #rightcol, #search_goto_line, #search_goto_pos, #search_in_buffer, #search_start_line
Methods inherited from Mode
#blur, #cancel_search!, #cleanup, #draw, #focus, #handle_input, #help_text, #in_search?, keymap, keymaps, load_all_modes, make_name, #name, #pipe_to_process, register_keymap, #resize, #resolve_input, #save_to_file
Constructor Details
Returns a new instance of EditMessageMode.
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# File 'lib/sup/modes/edit_message_mode.rb', line 91
def initialize opts={}
= opts.delete(:header) || {}
= []
@body = opts.delete(:body) || []
if opts[:attachments]
@attachments = opts[:attachments].values
@attachment_names = opts[:attachments].keys
else
@attachments = []
@attachment_names = []
end
begin
hostname = File.open("/etc/mailname", "r").gets.chomp
rescue
nil
end
hostname = Socket.gethostname if hostname.nil? or hostname.empty?
@message_id = "<#{Time.now.to_i}-sup-#{rand 10000}@#{hostname}>"
@edited = false
@sig_edited = false
@selectors = []
@selector_label_width = 0
@async_mode = nil
HookManager.run "before-edit", :header => , :body => @body
@account_selector = nil
if $config[:account_selector] && AccountManager.user_emails.length > 1
user_emails_copy = []
AccountManager.user_emails.each { |e| user_emails_copy.push e.dup }
@account_selector =
HorizontalSelector.new "Account:", AccountManager.user_emails + [nil], user_emails_copy + ["Customized"]
if ["From"] =~ /<?(\S+@(\S+?))>?$/
account_from = @account_selector.can_set_to?($1) ? $1 : nil
@account_selector.set_to account_from
else
@account_selector.set_to nil
end
@account_user = ["From"]
add_selector @account_selector
end
@crypto_selector =
if CryptoManager.have_crypto?
HorizontalSelector.new "Crypto:", [:none] + CryptoManager::OUTGOING_MESSAGE_OPERATIONS.keys, ["None"] + CryptoManager::OUTGOING_MESSAGE_OPERATIONS.values
end
add_selector @crypto_selector if @crypto_selector
if @crypto_selector
HookManager.run "crypto-mode", :header => , :body => @body, :crypto_selector => @crypto_selector
end
super opts
regen_text
end
|
Instance Attribute Details
Returns the value of attribute body.
73
74
75
|
# File 'lib/sup/modes/edit_message_mode.rb', line 73
def body
@body
end
|
Returns the value of attribute header.
73
74
75
|
# File 'lib/sup/modes/edit_message_mode.rb', line 73
def
end
|
Returns the value of attribute status.
72
73
74
|
# File 'lib/sup/modes/edit_message_mode.rb', line 72
def status
@status
end
|
Instance Method Details
165
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/sup/modes/edit_message_mode.rb', line 165
def [] i
if @selectors.empty?
@text[i]
elsif i < @selectors.length
@selectors[i].line @selector_label_width
elsif i == @selectors.length
""
else
@text[i - @selectors.length - DECORATION_LINES]
end
end
|
#attach_file ⇒ Object
307
308
309
310
311
312
313
314
315
316
317
318
319
|
# File 'lib/sup/modes/edit_message_mode.rb', line 307
def attach_file
fn = BufferManager.ask_for_filename :attachment, "File name (enter for browser): "
return unless fn
begin
Dir[fn].each do |f|
@attachments << RMail::Message.make_file_attachment(f)
@attachment_names << f
end
update
rescue SystemCallError => e
BufferManager.flash "Can't read #{fn}: #{e.message}"
end
end
|
#delete_attachment ⇒ Object
321
322
323
324
325
326
327
328
|
# File 'lib/sup/modes/edit_message_mode.rb', line 321
def delete_attachment
i = curpos - @attachment_lines_offset - DECORATION_LINES - 2
if i >= 0 && i < @attachments.size && BufferManager.ask_yes_or_no("Delete attachment #{@attachment_names[i]}?")
@attachments.delete_at i
@attachment_names.delete_at i
update
end
end
|
192
|
# File 'lib/sup/modes/edit_message_mode.rb', line 192
def edit_cc; edit_field "Cc" end
|
#edit_message ⇒ Object
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
|
# File 'lib/sup/modes/edit_message_mode.rb', line 221
def edit_message
old_from = ["From"] if @account_selector
begin
save_message_to_file
rescue SystemCallError => e
BufferManager.flash "Can't save message to file: #{e.message}"
return
end
editor = $config[:editor] || ENV['EDITOR'] || "/usr/bin/vi"
mtime = File.mtime @file.path
BufferManager.shell_out "#{editor} #{@file.path}"
@edited = true if File.mtime(@file.path) > mtime
return @edited unless @edited
, @body = parse_file @file.path
= -
set_sig_edit_flag
if @account_selector and ["From"] != old_from
@account_user = ["From"]
@account_selector.set_to nil
end
handle_new_text , @body
rerun_crypto_selector_hook
update
@edited
end
|
#edit_message_async ⇒ Object
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
|
# File 'lib/sup/modes/edit_message_mode.rb', line 255
def edit_message_async
begin
save_message_to_file
rescue SystemCallError => e
BufferManager.flash "Can't save message to file: #{e.message}"
return
end
@mtime = File.mtime @file.path
subject = ["Subject"] || ""
@async_mode = EditMessageAsyncMode.new self, @file.path, subject
BufferManager.spawn "Waiting for message \"#{subject}\" to be finished", @async_mode
buffer.hidden = true
end
|
#edit_message_async_resume(being_killed = false) ⇒ Object
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
# File 'lib/sup/modes/edit_message_mode.rb', line 275
def edit_message_async_resume being_killed=false
buffer.hidden = false
@async_mode = nil
BufferManager.raise_to_front buffer if !being_killed
@edited = true if File.mtime(@file.path) > @mtime
, @body = parse_file @file.path
= -
set_sig_edit_flag
handle_new_text , @body
update
true
end
|
#edit_message_or_field ⇒ Object
180
181
182
183
184
185
186
187
188
189
|
# File 'lib/sup/modes/edit_message_mode.rb', line 180
def edit_message_or_field
lines = DECORATION_LINES + @selectors.size
if lines > curpos
return
elsif (curpos - lines) >= .length
edit_message
else
edit_field [curpos - lines]
end
end
|
#edit_subject ⇒ Object
193
|
# File 'lib/sup/modes/edit_message_mode.rb', line 193
def edit_subject; edit_field "Subject" end
|
191
|
# File 'lib/sup/modes/edit_message_mode.rb', line 191
def edit_to; edit_field "To" end
|
#handle_new_text(header, body) ⇒ Object
hook for subclasses. i hate this style of programming.
178
|
# File 'lib/sup/modes/edit_message_mode.rb', line 178
def handle_new_text , body; end
|
#killable? ⇒ Boolean
291
292
293
294
295
296
297
298
299
300
301
302
303
|
# File 'lib/sup/modes/edit_message_mode.rb', line 291
def killable?
if !@async_mode.nil?
return false if !@async_mode.killable?
if File.mtime(@file.path) > @mtime
@edited = true
, @body = parse_file @file.path
= -
handle_new_text , @body
update
end
end
!edited? || BufferManager.ask_yes_or_no("Discard message?")
end
|
163
|
# File 'lib/sup/modes/edit_message_mode.rb', line 163
def lines; @text.length + (@selectors.empty? ? 0 : (@selectors.length + DECORATION_LINES)) end
|
#save_message_to_file ⇒ Object
195
196
197
198
199
200
201
202
203
|
# File 'lib/sup/modes/edit_message_mode.rb', line 195
def save_message_to_file
sig = sig_lines.join("\n")
@file = Tempfile.new ["sup.#{self.class.name.gsub(/.*::/, '').camel_to_hyphy}", ".eml"]
@file.puts ( - ).first
@file.puts
@file.puts @body.join("\n")
@file.puts sig if ($config[:edit_signature] and !@sig_edited)
@file.close
end
|
#set_sig_edit_flag ⇒ Object
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
# File 'lib/sup/modes/edit_message_mode.rb', line 205
def set_sig_edit_flag
sig = sig_lines.join("\n")
if $config[:edit_signature]
pbody = @body.join("\n")
blen = pbody.length
slen = sig.length
if blen > slen and pbody[blen-slen..blen] == sig
@sig_edited = false
@body = pbody[0..blen-slen].split("\n")
else
@sig_edited = true
end
end
end
|
#unsaved? ⇒ Boolean
305
|
# File 'lib/sup/modes/edit_message_mode.rb', line 305
def unsaved?; edited? end
|