Debian Codegraph @

mew-summary3.el

raw
1 ;;; mew-summary3.el --- Summary mode for Mew
2
3 ;; Author: Kazu Yamamoto <[email protected]>
4 ;; Created: Oct 2, 1996
5
6 ;;; Code:
7
8 (require 'mew)
9
10 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11 ;;;
12 ;;; Subfunctions
13 ;;;
14
15 (defmacro mew-summary-prepare-draft (&rest body)
16 "Common procedure to prepare a draft."
17 (declare (debug (&rest form)))
18 `(progn
19 (unwind-protect
20 (let ((inhibit-quit t))
21 ,@body
22 (mew-redraw)
23 (if quit-flag (setq quit-flag nil)))
24 (mew-draft-save-buffer)) ;; to make sure not to use this draft again
25 (mew-set-file-modes (buffer-file-name))
26 (mew-touch-folder mew-draft-folder)
27 (message "Draft is prepared")))
28
29 (defun mew-summary-prepare-three-windows ()
30 "Prepare three windows: Summary mode, Message mode, and Draft mode"
31 (unless mew-use-other-frame-for-draft
32 (if (get-buffer (mew-buffer-message))
33 (delete-windows-on (mew-buffer-message)))
34 (cond
35 ((< (window-height) 25)
36 (delete-other-windows))
37 (mew-use-full-window
38 (mew-delete-other-window)))
39 (let ((split-window-keep-point t))
40 (split-window-vertically))))
41
42 (defun mew-draft-multi-copy (draft files)
43 (let* ((attach (mew-draft-to-attach draft))
44 (attachdir (mew-expand-folder attach)))
45 (mew-check-directory attachdir)
46 (dolist (file files)
47 (if mew-use-symbolic-link-for-forwarding
48 (mew-symbolic-link file (mew-folder-new-message attach))
49 (copy-file file (mew-folder-new-message attach))))))
50
51 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
52 ;;;
53 ;;; Sending
54 ;;;
55
56 (defun mew-summary-set-message-buffer (fld msg)
57 ;; need to make a cache or a message buffer.
58 (mew-summary-toggle-disp-msg 'on)
59 ;; Since we will switch to a draft buffer,
60 ;; the window of the draft buffer must not be deleted.
61 ;; So, binding mew-use-full-window to nil.
62 (let ((mew-use-full-window nil))
63 (mew-summary-display))
64 (set-buffer (mew-buffer-message))
65 ;; header exists only in cache if multipart
66 (unless (mew-msghdr-p) (set-buffer (mew-cache-hit fld msg))))
67
68 (defun mew-summary-write (&optional from)
69 "Write a message. A new draft is prepared in Draft mode.
70 If called with '\\[universal-argument]', the From: address of
71 the current message is copied to To: in a draft."
72 (interactive "P")
73 (if (null from)
74 (mew-summary-send)
75 (mew-summary-msg-or-part
76 (let ((fld (mew-summary-folder-name))
77 (msg (mew-summary-message-number2))
78 to)
79 (if (not (and fld msg))
80 (message "No message")
81 (save-excursion
82 (mew-summary-set-message-buffer fld msg)
83 (setq to (mew-addrstr-parse-address (mew-header-get-value mew-from:)))
84 (if (mew-is-my-address mew-regex-my-address-list to)
85 (setq to (mew-addrstr-parse-address (mew-header-get-value mew-to:)))))
86 (mew-summary-send to)
87 (goto-char (point-min))
88 (if (search-forward mew-subj: nil t)
89 (end-of-line)))))))
90
91 (defun mew-summary-send (&optional to cc subject newsgroups)
92 "Write a message. A new draft is prepared in Draft mode."
93 (interactive)
94 (let ((draft (mew-folder-new-message mew-draft-folder))
95 asked)
96 (if (and (mew-summary-physical-folder)
97 (mew-folder-nntpp (mew-summary-physical-folder)))
98 (if (null newsgroups) (setq newsgroups ""))
99 (when (and mew-ask-to (null to))
100 (setq to (mew-input-address (concat mew-to: " ")))
101 (setq asked t))
102 (when (and mew-ask-cc (null cc))
103 (setq cc (mew-input-address (concat mew-cc: " ")))
104 (setq asked t)))
105 (mew-current-set-window-config)
106 (mew-window-configure 'draft)
107 (mew-summary-prepare-draft
108 (mew-draft-find-and-switch draft)
109 (mew-delete-directory-recursively (mew-attachdir draft))
110 (mew-draft-header subject nil to cc newsgroups nil nil nil asked)
111 (mew-draft-mode)
112 (run-hooks 'mew-draft-mode-newdraft-hook))))
113
114 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
115 ;;;
116 ;;; Replying
117 ;;;
118
119 (defun mew-subject-simplify (str &optional act-lst no-replace)
120 "A function to simplify a value of Subject: according to
121 'mew-subject-simplify-replace-alist'."
122 (let ((case-fold-search t)
123 (action-list (or act-lst mew-subject-simplify-replace-alist))
124 (ret str)
125 regexp replace)
126 (dolist (action action-list)
127 (setq regexp (mew-alist-get-key action))
128 (setq replace (if no-replace nil (mew-alist-get-value action)))
129 (if (string-match regexp ret)
130 (setq ret (replace-match (if replace (eval replace) "") nil t ret))))
131 ret))
132
133 (defun mew-subject-simplify-ml (str)
134 "Remove leading \"[...]\" and \"(...)\" from subject line."
135 (if (string-match "^[[(][^])]+[])][ \t]*" str)
136 (substring str (match-end 0))
137 str))
138
139 (defun mew-subject-simplify2 (str)
140 (mew-subject-simplify
141 (mew-subject-simplify-ml
142 (mew-subject-simplify str nil 'no-replace)) nil 'no-replace))
143
144 (defun mew-to-cc-newsgroups (replysender)
145 (let (alist key tcn flds to cc newsgroups fromme func)
146 (cond
147 (replysender
148 (setq alist mew-reply-sender-alist)
149 (setq func 'mew-header-parse-address-list2))
150 ((mew-is-my-address mew-regex-my-address-list
151 (mew-header-parse-address mew-from:))
152 (setq fromme t)
153 (setq alist mew-reply-fromme-alist)
154 ;; If from me, let's leave the "anonymous:;" keyword.
155 (setq func 'mew-header-parse-address-list))
156 (t ;; reply all
157 (setq alist mew-reply-all-alist)
158 (setq func 'mew-header-parse-address-list2)))
159 (catch 'loop
160 (dolist (ent alist)
161 (setq key (car ent))
162 (setq ent (cdr ent))
163 (when (or (eq key t)
164 (and (stringp key) (mew-header-get-value key))
165 (and (listp key)
166 (string= (mew-header-get-value (nth 0 key))
167 (nth 1 key))))
168 (dolist (tcn-flds ent)
169 (setq tcn (car tcn-flds))
170 (setq flds (cdr tcn-flds))
171 (cond
172 ((mew-case-equal tcn mew-to:)
173 (setq to (funcall func flds)))
174 ((mew-case-equal tcn mew-cc:)
175 (setq cc (funcall func flds)))
176 ((mew-case-equal tcn mew-newsgroups:)
177 (setq newsgroups (funcall func flds)))))
178 (throw 'loop nil))))
179 (list to cc newsgroups fromme)))
180
181 (defun mew-in-reply-to-references ()
182 (let ((old-message-id (mew-idstr-get-first-id
183 (mew-header-get-value mew-message-id:)))
184 (old-in-reply-to (mew-idstr-get-first-id
185 (mew-header-get-value mew-in-reply-to:)))
186 (old-references (mew-idstr-to-id-list
187 (mew-header-get-value mew-references:) 'rev))
188 id-list in-reply-to references)
189 ;; Assuming that In-Reply-To: contains one ID.
190 (when old-message-id
191 ;; when old-message-id is nil,
192 ;; we do not care even if old-references exist.
193 (setq in-reply-to old-message-id)
194 (cond
195 (old-references
196 (setq id-list old-references)
197 (mew-addq id-list old-in-reply-to)
198 (mew-addq id-list old-message-id)
199 (setq id-list (nreverse id-list)))
200 (t
201 (setq id-list (list old-message-id))
202 (mew-addq id-list old-in-reply-to)))
203 (setq references (mew-id-list-to-idstr id-list)))
204 (list in-reply-to references)))
205
206 (defun mew-summary-reply (&optional replysender)
207 "Reply to this message. A new draft is prepared in Draft mode.
208 Values of To:, Cc:, and Newsgroups: are prepared according to
209 three alists.
210
211 \(1) If called with '\\[universal-argument]', replying to the
212 sender/poster only. In this case, 'mew-reply-sender-alist' is used.
213
214 \(2) If this message is sent by ME, you probably intend to reply with
215 the original header. In this case, 'mew-reply-fromme-alist' is used.
216
217 \(3) Otherwise, replying to all people listed. In this case,
218 'mew-reply-all-alist' is used.
219
220 The default value of 'mew-reply-sender-alist' is as follows:
221
222 '((\"Reply-To:\"
223 (\"To:\" \"Reply-To:\" \"From:\"))
224 (t
225 (\"To:\" \"From:\")))
226
227 This is read as follows:
228
229 (1.1) If Reply-To: exists, copy the values of Reply-To:
230 and From: to new To:.
231 (1.2) Otherwise, copy the value of From: to To:.
232
233 If you would like to reply only to the address on Reply-To: (if any),
234 set 'mew-reply-sender-alist' to:
235
236 '((\"Reply-To:\"
237 (\"To:\" \"Reply-To:\"))
238 (t
239 (\"To:\" \"From:\")))
240
241 The default value of 'mew-reply-fromme-alist' is as follows:
242
243 '((t
244 (\"To:\" \"To:\")
245 (\"Cc:\" \"Cc:\")
246 (\"Newsgroups:\" \"Newsgroups:\"))))
247
248 This is read as follows:
249
250 (2.1) Copying the value of To: to new To: and
251 copying the value of Cc: to new Cc: and
252 copying the value of Newsgroups: to new Newsgroups:.
253
254 The default value of 'mew-reply-all-alist' is as follows:
255
256 '(((\"Followup-To:\" \"poster\")
257 (\"To:\" \"From:\"))
258 (\"Followup-To:\"
259 (\"Newsgroups:\" \"Followup-To:\" \"Newsgroups:\"))
260 (\"Newsgroups:\"
261 (\"Newsgroups:\" \"Newsgroups:\"))
262 (\"Reply-To:\"
263 (\"To:\" \"Reply-To:\" \"From:\")
264 (\"Cc:\" \"To:\" \"Cc:\" \"Apparently-To:\"))
265 (t
266 (\"To:\" \"From:\")
267 (\"Cc:\" \"To:\" \"Cc:\" \"Apparently-To:\")))
268
269 This is read as follows:
270
271 (3.1) If the value of Followup-To: is \"poster\", copying the
272 value of From: to new To:.
273 (3.2) If Followup-To: exists, copying the values of
274 Followup-To: and Newsgroups: to new Newsgroups:.
275 (3.3) If Newsgroups: exists, copying the value of Newsgroups:
276 to Newsgroups:.
277 (3.4) If Reply-To: exists, copying the values of Reply-To: and
278 From: to new To:. And copying the values of To:, Cc: and
279 Apparently-To: to new Cc:.
280
281 (3.5) Otherwise, copying the value of From: to new To:. And
282 copying the values of To:, Cc: and Apparently-To: to
283 new Cc:.
284
285 You may want to set 'mew-reply-all-alist' to:
286
287 '(((\"Followup-To:\" \"poster\")
288 (\"To:\" \"From:\"))
289 (\"Followup-To:\"
290 (\"Newsgroups:\" \"Followup-To:\"))
291 (\"Newsgroups:\"
292 (\"Newsgroups:\" \"Newsgroups:\"))
293 (\"Reply-To:\"
294 (\"To:\" \"Reply-To:\"))
295 (t
296 (\"To:\" \"From:\")
297 (\"Cc:\" \"To:\" \"Cc:\" \"Apparently-To:\")))
298 "
299 (interactive "P")
300 (mew-summary-msg-or-part
301 (mew-summary-not-in-draft
302 (mew-current-set-window-config)
303 (let ((owin (selected-window))
304 (fld (mew-summary-folder-name))
305 (msg (mew-summary-message-number2))
306 (split-width-threshold nil)
307 cwin cbuf draft case
308 subject to cc newsgroups in-reply-to references
309 encrypted fromme ret)
310 (if (string= (mew-summary-folder-name) mew-draft-folder)
311 (message "Cannot reply to draft message")
312 (setq draft (mew-folder-new-message mew-draft-folder))
313 (mew-summary-prepare-draft
314 (mew-summary-prepare-three-windows)
315 (mew-draft-find-and-switch draft t)
316 (mew-delete-directory-recursively (mew-attachdir draft))
317 (setq cwin (selected-window)) ;; draft
318 (setq cbuf (window-buffer cwin))
319 (select-window owin)
320 (mew-summary-set-message-buffer fld msg)
321 (when mew-case-guess-when-replied
322 (setq case (mew-draft-get-case-by-guess
323 mew-case-guess-when-replied-alist)))
324 (setq encrypted (mew-syntax-encrypted-p mew-decode-syntax))
325 (save-restriction
326 ;; if body contains ^L, header is not accessible.
327 ;; mew-header-* cannot widen essentially. So widen here.
328 (widen)
329 ;; now cache buffer
330 ;;
331 ;; Subject:
332 (setq subject (mew-header-get-value mew-subj:))
333 (when subject
334 (setq subject (concat mew-reply-string subject))
335 (setq subject (mew-subject-simplify subject)))
336 ;;
337 ;; To:, Cc:, Newsgroups:
338 (setq ret (mew-to-cc-newsgroups replysender))
339 (mew-set '(to cc newsgroups fromme) ret)
340 ;;
341 ;; In-Reply-To:, References:
342 (setq ret (mew-in-reply-to-references))
343 (mew-set '(in-reply-to references) ret))
344 ;;
345 (if (window-live-p cwin)
346 (select-window cwin) ;; draft
347 (pop-to-buffer cbuf))
348 (when case
349 (if mew-case-guess-addition
350 (setq case (mew-draft-add-case (mew-tinfo-get-case) case)))
351 (mew-tinfo-set-case case))
352 (mew-draft-header subject nil to cc newsgroups in-reply-to references
353 nil fromme)
354 (when (eq mew-summary-reply-position 'body)
355 (goto-char (mew-header-end))
356 (forward-line))
357 (mew-draft-mode encrypted)
358 (run-hooks 'mew-draft-mode-newdraft-hook)))))))
359
360 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
361 ;;;
362 ;;; Replaying with citation
363 ;;;
364
365 (defun mew-summary-reply-with-citation (&optional replysender)
366 "Answer to this message. A new draft is prepared in Draft mode.
367 And this message is automatically cited. See also 'mew-summary-reply'."
368 (interactive "P")
369 (mew-summary-msg-or-part
370 (mew-summary-not-in-draft
371 (let ((mew-summary-reply-position nil)
372 (mew-message-citation-frame-id (mew-frame-id)))
373 (mew-summary-reply replysender)
374 ;; mew-draft-mode-hook may insert text.
375 (save-excursion
376 (goto-char (point-max))
377 (run-hooks 'mew-before-cite-hook)
378 (mew-draft-cite)))
379 ;; the cursor is after To:
380 (cond
381 ((eq mew-summary-reply-with-citation-position 'body)
382 (goto-char (mew-header-end))
383 (forward-line))
384 ((eq mew-summary-reply-with-citation-position 'end)
385 (goto-char (point-max)))))))
386
387 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
388 ;;;
389 ;;; Forwarding
390 ;;;
391
392 (defun mew-summary-forward ()
393 "Forward this message to a third person. A new draft is prepared in
394 Draft mode and this message is automatically attached."
395 (interactive)
396 (mew-summary-msg-or-part
397 (mew-summary-not-in-draft
398 (mew-current-set-window-config)
399 (let* ((owin (selected-window))
400 (fld (mew-summary-folder-name))
401 (msg (mew-summary-message-number2))
402 (file (mew-expand-msg fld msg))
403 (draft (mew-folder-new-message mew-draft-folder))
404 (draftdir (file-name-nondirectory draft))
405 (to (and mew-ask-to (mew-input-address (concat mew-to: " "))))
406 (cc (and mew-ask-cc (mew-input-address (concat mew-cc: " "))))
407 (asked (or mew-ask-to mew-ask-cc))
408 subject fwsubject cwin)
409 (mew-summary-prepare-draft
410 (mew-summary-prepare-three-windows)
411 (mew-draft-find-and-switch draft t)
412 (mew-delete-directory-recursively (mew-attachdir draft))
413 (setq cwin (selected-window)) ;; draft
414 (select-window owin)
415 (mew-summary-set-message-buffer fld msg)
416 (setq subject (mew-header-get-value mew-subj:))
417 (if subject
418 (setq fwsubject (mew-subject-simplify (concat mew-forward-string subject))))
419 (select-window cwin) ;; draft
420 ;;
421 (mew-draft-header fwsubject 'nl to cc nil nil nil nil asked)
422 (mew-draft-mode)
423 (run-hooks 'mew-draft-mode-newdraft-hook)
424 (mew-draft-multi-copy draft (list file))
425 (setq mew-encode-syntax (mew-encode-syntax-initial-multi draftdir 1))
426 (save-excursion
427 (mew-draft-prepare-attachments t)))))))
428
429 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
430 ;;;
431 ;;; Multi forwarding
432 ;;;
433
434 (defun mew-summary-multi-forward ()
435 "Forward messages marked with '*' to a third person. A new draft
436 is prepared in Draft mode and this message is automatically
437 attached."
438 (interactive)
439 (mew-summary-multi-msgs
440 (mew-summary-not-in-draft
441 (mew-current-set-window-config)
442 (let* ((draft (mew-folder-new-message mew-draft-folder))
443 (draftdir (file-name-nondirectory draft))
444 (to (and mew-ask-to (mew-input-address (concat mew-to: " "))))
445 (cc (and mew-ask-cc (mew-input-address (concat mew-cc: " "))))
446 (asked (or mew-ask-to mew-ask-cc)))
447 (mew-summary-prepare-draft
448 (mew-summary-prepare-three-windows)
449 (mew-draft-find-and-switch draft t)
450 (mew-delete-directory-recursively (mew-attachdir draft))
451 (mew-draft-header nil 'nl to cc nil nil nil nil asked)
452 (mew-draft-mode)
453 (run-hooks 'mew-draft-mode-newdraft-hook)
454 (mew-draft-multi-copy draft FILES)
455 (setq mew-encode-syntax
456 (mew-encode-syntax-initial-multi draftdir (length FILES)))
457 (save-excursion
458 (mew-draft-prepare-attachments t)))))))
459
460 (provide 'mew-summary3)
461
462 ;;; Copyright Notice:
463
464 ;; Copyright (C) 1996-2015 Mew developing team.
465 ;; All rights reserved.
466
467 ;; Redistribution and use in source and binary forms, with or without
468 ;; modification, are permitted provided that the following conditions
469 ;; are met:
470 ;;
471 ;; 1. Redistributions of source code must retain the above copyright
472 ;; notice, this list of conditions and the following disclaimer.
473 ;; 2. Redistributions in binary form must reproduce the above copyright
474 ;; notice, this list of conditions and the following disclaimer in the
475 ;; documentation and/or other materials provided with the distribution.
476 ;; 3. Neither the name of the team nor the names of its contributors
477 ;; may be used to endorse or promote products derived from this software
478 ;; without specific prior written permission.
479 ;;
480 ;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND
481 ;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
482 ;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
483 ;; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE
484 ;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
485 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
486 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
487 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
488 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
489 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
490 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
491
492 ;;; mew-summary3.el ends here