comparison lisp/mh-e/mh-mime.el @ 67758:6b063593fdad

Follow Emacs coding conventions. Use default setting of emacs-lisp-docstring-fill-column which is 65.
author Bill Wohler <wohler@newt.com>
date Fri, 23 Dec 2005 07:40:40 +0000
parents 7ff92ad99326
children b7b75914a27d
comparison
equal deleted inserted replaced
67757:488b4dbc7482 67758:6b063593fdad
53 (autoload 'widget-convert-button "wid-edit") 53 (autoload 'widget-convert-button "wid-edit")
54 54
55 ;;;###mh-autoload 55 ;;;###mh-autoload
56 (defun mh-compose-insertion (&optional inline) 56 (defun mh-compose-insertion (&optional inline)
57 "Add tag to include a file such as an image or sound. 57 "Add tag to include a file such as an image or sound.
58 You are prompted for the filename containing the object, the media type if it 58
59 cannot be determined automatically, and a content description. If you're using 59 You are prompted for the filename containing the object, the
60 MH-style directives, you will also be prompted for additional attributes. 60 media type if it cannot be determined automatically, and a
61 61 content description. If you're using MH-style directives, you
62 The option `mh-compose-insertion' controls what type of tags are inserted. 62 will also be prompted for additional attributes.
63 Optional argument INLINE means make it an inline attachment." 63
64 The option `mh-compose-insertion' controls what type of tags are
65 inserted. Optional argument INLINE means make it an inline
66 attachment."
64 (interactive "P") 67 (interactive "P")
65 (if (equal mh-compose-insertion 'mml) 68 (if (equal mh-compose-insertion 'mml)
66 (if inline 69 (if inline
67 (mh-mml-attach-file "inline") 70 (mh-mml-attach-file "inline")
68 (mh-mml-attach-file)) 71 (mh-mml-attach-file))
69 (call-interactively 'mh-mh-attach-file))) 72 (call-interactively 'mh-mh-attach-file)))
70 73
71 ;;;###mh-autoload 74 ;;;###mh-autoload
72 (defun mh-compose-forward (&optional description folder messages) 75 (defun mh-compose-forward (&optional description folder messages)
73 "Add tag to forward a message. 76 "Add tag to forward a message.
74 You are prompted for a content DESCRIPTION, the name of the FOLDER in which 77
75 the messages to forward are located, and the MESSAGES' numbers. 78 You are prompted for a content DESCRIPTION, the name of the
79 FOLDER in which the messages to forward are located, and the
80 MESSAGES' numbers.
76 81
77 The option `mh-compose-insertion' controls what type of tags are inserted." 82 The option `mh-compose-insertion' controls what type of tags are inserted."
78 (interactive (let* 83 (interactive (let*
79 ((description (mml-minibuffer-read-description)) 84 ((description (mml-minibuffer-read-description))
80 (folder (mh-prompt-for-folder "Message from" 85 (folder (mh-prompt-for-folder "Message from"
115 ;; MIME option to mh-forward 120 ;; MIME option to mh-forward
116 ;; command to move to content-description insertion point 121 ;; command to move to content-description insertion point
117 122
118 (defvar mh-mh-to-mime-args nil 123 (defvar mh-mh-to-mime-args nil
119 "Extra arguments for \\[mh-mh-to-mime] to pass to the \"mhbuild\" command. 124 "Extra arguments for \\[mh-mh-to-mime] to pass to the \"mhbuild\" command.
120 The arguments are passed to \"mhbuild\" if \\[mh-mh-to-mime] is given a prefix 125 The arguments are passed to \"mhbuild\" if \\[mh-mh-to-mime] is
121 argument. Normally default arguments to \"mhbuild\" are specified in the MH 126 given a prefix argument. Normally default arguments to
122 profile.") 127 \"mhbuild\" are specified in the MH profile.")
123 128
124 (defvar mh-media-type-regexp 129 (defvar mh-media-type-regexp
125 (concat (regexp-opt '("text" "image" "audio" "video" "application" 130 (concat (regexp-opt '("text" "image" "audio" "video" "application"
126 "multipart" "message") t) 131 "multipart" "message") t)
127 "/[-.+a-zA-Z0-9]+") 132 "/[-.+a-zA-Z0-9]+")
149 '(("application/msword" "\.xls" "application/ms-excel") 154 '(("application/msword" "\.xls" "application/ms-excel")
150 ("application/msword" "\.ppt" "application/ms-powerpoint") 155 ("application/msword" "\.ppt" "application/ms-powerpoint")
151 ("text/plain" "\.vcf" "text/x-vcard")) 156 ("text/plain" "\.vcf" "text/x-vcard"))
152 "Substitutions to make for Content-Type returned from file command. 157 "Substitutions to make for Content-Type returned from file command.
153 The first element is the Content-Type returned by the file command. 158 The first element is the Content-Type returned by the file command.
154 The second element is a regexp matching the file name, usually the extension. 159 The second element is a regexp matching the file name, usually the
160 extension.
155 The third element is the Content-Type to replace with.") 161 The third element is the Content-Type to replace with.")
156 162
157 (defun mh-file-mime-type-substitute (content-type filename) 163 (defun mh-file-mime-type-substitute (content-type filename)
158 "Return possibly changed CONTENT-TYPE on the FILENAME. 164 "Return possibly changed CONTENT-TYPE on the FILENAME.
159 Substitutions are made from the `mh-file-mime-type-substitutions' variable." 165 Substitutions are made from the `mh-file-mime-type-substitutions'
166 variable."
160 (let ((subst mh-file-mime-type-substitutions) 167 (let ((subst mh-file-mime-type-substitutions)
161 (type) (match) (answer content-type) 168 (type) (match) (answer content-type)
162 (case-fold-search t)) 169 (case-fold-search t))
163 (while subst 170 (while subst
164 (setq type (car (car subst)) 171 (setq type (car (car subst))
223 ;; mml-minibuffer-read-type when Emacs20 is no longer supported unless we 230 ;; mml-minibuffer-read-type when Emacs20 is no longer supported unless we
224 ;; think (mh-file-mime-type) is better than (mm-default-file-encoding). 231 ;; think (mh-file-mime-type) is better than (mm-default-file-encoding).
225 232
226 (defun mh-minibuffer-read-type (filename &optional default) 233 (defun mh-minibuffer-read-type (filename &optional default)
227 "Return the content type associated with the given FILENAME. 234 "Return the content type associated with the given FILENAME.
228 If the \"file\" command exists and recognizes the given file, then its value 235 If the \"file\" command exists and recognizes the given file,
229 is returned\; otherwise, the user is prompted for a type (see 236 then its value is returned\; otherwise, the user is prompted for
230 `mailcap-mime-types' and for Emacs 20, `mh-mime-content-types'). 237 a type (see `mailcap-mime-types' and for Emacs 20,
238 `mh-mime-content-types').
231 Optional argument DEFAULT is returned if a type isn't entered." 239 Optional argument DEFAULT is returned if a type isn't entered."
232 (mailcap-parse-mimetypes) 240 (mailcap-parse-mimetypes)
233 (let* ((default (or default 241 (let* ((default (or default
234 (mm-default-file-encoding filename) 242 (mm-default-file-encoding filename)
235 "application/octet-stream")) 243 "application/octet-stream"))
270 "Valid MIME access-type values.") 278 "Valid MIME access-type values.")
271 279
272 ;;;###mh-autoload 280 ;;;###mh-autoload
273 (defun mh-mh-attach-file (filename type description attributes) 281 (defun mh-mh-attach-file (filename type description attributes)
274 "Add a tag to insert a MIME message part from a file. 282 "Add a tag to insert a MIME message part from a file.
275 You are prompted for the FILENAME containing the object, the media TYPE if it 283 You are prompted for the FILENAME containing the object, the
276 cannot be determined automatically, and a content DESCRIPTION. In addition, 284 media TYPE if it cannot be determined automatically, and a
277 you are also prompted for additional ATTRIBUTES. 285 content DESCRIPTION. In addition, you are also prompted for
286 additional ATTRIBUTES.
278 287
279 See also \\[mh-mh-to-mime]." 288 See also \\[mh-mh-to-mime]."
280 (interactive (let ((filename (mml-minibuffer-read-file "Attach file: "))) 289 (interactive (let ((filename (mml-minibuffer-read-file "Attach file: ")))
281 (list 290 (list
282 filename 291 filename
289 (mh-mh-compose-type filename type description attributes)) 298 (mh-mh-compose-type filename type description attributes))
290 299
291 (defun mh-mh-compose-type (filename type 300 (defun mh-mh-compose-type (filename type
292 &optional description attributes comment) 301 &optional description attributes comment)
293 "Insert an MH-style directive to insert a file. 302 "Insert an MH-style directive to insert a file.
294 The file specified by FILENAME is encoded as TYPE. An optional DESCRIPTION is 303 The file specified by FILENAME is encoded as TYPE. An optional
295 used as the Content-Description field, optional set of ATTRIBUTES and an 304 DESCRIPTION is used as the Content-Description field, optional
296 optional COMMENT can also be included." 305 set of ATTRIBUTES and an optional COMMENT can also be included."
297 (beginning-of-line) 306 (beginning-of-line)
298 (insert "#" type) 307 (insert "#" type)
299 (and attributes 308 (and attributes
300 (insert "; " attributes)) 309 (insert "; " attributes))
301 (and comment 310 (and comment
307 (insert "\n")) 316 (insert "\n"))
308 317
309 ;;;###mh-autoload 318 ;;;###mh-autoload
310 (defun mh-mh-compose-anon-ftp (host filename type description) 319 (defun mh-mh-compose-anon-ftp (host filename type description)
311 "Add tag to include anonymous ftp reference to a file. 320 "Add tag to include anonymous ftp reference to a file.
312 You can even have your message initiate an \"ftp\" transfer when the 321 You can even have your message initiate an \"ftp\" transfer when
313 recipient reads the message. You are prompted for the remote 322 the recipient reads the message. You are prompted for the remote
314 HOST and FILENAME, the media TYPE, and the content DESCRIPTION. 323 HOST and FILENAME, the media TYPE, and the content DESCRIPTION.
315 324
316 See also \\[mh-mh-to-mime]." 325 See also \\[mh-mh-to-mime]."
317 (interactive (list 326 (interactive (list
318 (read-string "Remote host: ") 327 (read-string "Remote host: ")
323 type description)) 332 type description))
324 333
325 ;;;###mh-autoload 334 ;;;###mh-autoload
326 (defun mh-mh-compose-external-compressed-tar (host filename description) 335 (defun mh-mh-compose-external-compressed-tar (host filename description)
327 "Add tag to include anonymous ftp reference to a compressed tar file. 336 "Add tag to include anonymous ftp reference to a compressed tar file.
328 In addition to retrieving the file via anonymous \"ftp\" as per the 337 In addition to retrieving the file via anonymous \"ftp\" as per
329 \\[mh-mh-compose-anon-ftp] command, the file will also be uncompressed and 338 the \\[mh-mh-compose-anon-ftp] command, the file will also be
330 untarred. You are prompted for the remote HOST and FILENAME and the content 339 uncompressed and untarred. You are prompted for the remote HOST
331 DESCRIPTION. 340 and FILENAME and the content DESCRIPTION.
332 341
333 See also \\[mh-mh-to-mime]." 342 See also \\[mh-mh-to-mime]."
334 (interactive (list 343 (interactive (list
335 (read-string "Remote host: ") 344 (read-string "Remote host: ")
336 (read-string "Remote filename: ") 345 (read-string "Remote filename: ")
345 (defun mh-mh-compose-external-type (access-type host filename type 354 (defun mh-mh-compose-external-type (access-type host filename type
346 &optional description 355 &optional description
347 attributes parameters 356 attributes parameters
348 comment) 357 comment)
349 "Add tag to refer to a remote file. 358 "Add tag to refer to a remote file.
350 This command is a general utility for referencing external files. In fact, all 359 This command is a general utility for referencing external files.
351 of the other commands that insert directives to access external files call 360 In fact, all of the other commands that insert directives to
352 this command. You are prompted for the ACCESS-TYPE, remote HOST and FILENAME, 361 access external files call this command. You are prompted for the
353 and content TYPE. If you provide a prefix argument, you are also prompted for 362 ACCESS-TYPE, remote HOST and FILENAME, and content TYPE. If you
354 a content DESCRIPTION, ATTRIBUTES, PARAMETERS, and a COMMENT. 363 provide a prefix argument, you are also prompted for a content
364 DESCRIPTION, ATTRIBUTES, PARAMETERS, and a COMMENT.
355 365
356 See also \\[mh-mh-to-mime]." 366 See also \\[mh-mh-to-mime]."
357 (interactive (list 367 (interactive (list
358 (completing-read "Access type: " mh-access-types) 368 (completing-read "Access type: " mh-access-types)
359 (read-string "Remote host: ") 369 (read-string "Remote host: ")
384 (insert "\n")) 394 (insert "\n"))
385 395
386 ;;;###mh-autoload 396 ;;;###mh-autoload
387 (defun mh-mh-forward-message (&optional description folder messages) 397 (defun mh-mh-forward-message (&optional description folder messages)
388 "Add tag to forward a message. 398 "Add tag to forward a message.
389 You are prompted for a content DESCRIPTION, the name of the FOLDER in which 399 You are prompted for a content DESCRIPTION, the name of the
390 the messages to forward are located, and the MESSAGES' numbers. 400 FOLDER in which the messages to forward are located, and the
401 MESSAGES' numbers.
391 402
392 See also \\[mh-mh-to-mime]." 403 See also \\[mh-mh-to-mime]."
393 (interactive (list 404 (interactive (list
394 (mml-minibuffer-read-description) 405 (mml-minibuffer-read-description)
395 (mh-prompt-for-folder "Message from" mh-sent-from-folder nil) 406 (mh-prompt-for-folder "Message from" mh-sent-from-folder nil)
418 429
419 ;;;###mh-autoload 430 ;;;###mh-autoload
420 (defun mh-mh-to-mime (&optional extra-args) 431 (defun mh-mh-to-mime (&optional extra-args)
421 "Compose MIME message from MH-style directives. 432 "Compose MIME message from MH-style directives.
422 433
423 Typically, you send a message with attachments just like any other message. 434 Typically, you send a message with attachments just like any other
424 However, you may take a sneak preview of the MIME encoding if you wish by 435 message. However, you may take a sneak preview of the MIME encoding if
425 running this command. 436 you wish by running this command.
426 437
427 If you wish to pass additional arguments to \"mhbuild\" (\"mhn\") to affect 438 If you wish to pass additional arguments to \"mhbuild\" (\"mhn\") to
428 how it builds your message, use the `mh-mh-to-mime-args' option. For example, 439 affect how it builds your message, use the `mh-mh-to-mime-args'
429 you can build a consistency check into the message by setting 440 option. For example, you can build a consistency check into the
430 `mh-mh-to-mime-args' to \"-check\". The recipient of your message can then run 441 message by setting `mh-mh-to-mime-args' to \"-check\". The recipient
431 \"mhbuild -check\" on the message--\"mhbuild\" (\"mhn\") will complain if the 442 of your message can then run \"mhbuild -check\" on the
432 message has been corrupted on the way. This command only consults this option 443 message--\"mhbuild\" (\"mhn\") will complain if the message has been
433 when given a prefix argument EXTRA-ARGS. 444 corrupted on the way. This command only consults this option when
445 given a prefix argument EXTRA-ARGS.
434 446
435 The hook `mh-mh-to-mime-hook' is called after the message has been 447 The hook `mh-mh-to-mime-hook' is called after the message has been
436 formatted. 448 formatted.
437 449
438 The effects of this command can be undone by running \\[mh-mh-to-mime-undo]." 450 The effects of this command can be undone by running
451 \\[mh-mh-to-mime-undo]."
439 (interactive "*P") 452 (interactive "*P")
440 (mh-mh-quote-unescaped-sharp) 453 (mh-mh-quote-unescaped-sharp)
441 (save-buffer) 454 (save-buffer)
442 (message "Running %s..." (if (mh-variant-p 'nmh) "mhbuild" "mhn")) 455 (message "Running %s..." (if (mh-variant-p 'nmh) "mhbuild" "mhn"))
443 (cond 456 (cond
455 (message "Running %s...done" (if (mh-variant-p 'nmh) "mhbuild" "mhn")) 468 (message "Running %s...done" (if (mh-variant-p 'nmh) "mhbuild" "mhn"))
456 (run-hooks 'mh-mh-to-mime-hook)) 469 (run-hooks 'mh-mh-to-mime-hook))
457 470
458 (defun mh-mh-quote-unescaped-sharp () 471 (defun mh-mh-quote-unescaped-sharp ()
459 "Quote `#' characters that haven't been quoted for \"mhbuild\". 472 "Quote `#' characters that haven't been quoted for \"mhbuild\".
460 If the `#' character is present in the first column, but it isn't part of a 473 If the `#' character is present in the first column, but it isn't
461 MH-style directive then \"mhbuild\" gives an error. This function will quote 474 part of a MH-style directive then \"mhbuild\" gives an error.
462 all such characters." 475 This function will quote all such characters."
463 (save-excursion 476 (save-excursion
464 (goto-char (point-min)) 477 (goto-char (point-min))
465 (while (re-search-forward "^#" nil t) 478 (while (re-search-forward "^#" nil t)
466 (beginning-of-line) 479 (beginning-of-line)
467 (unless (mh-mh-directive-present-p (point) (line-end-position)) 480 (unless (mh-mh-directive-present-p (point) (line-end-position))
469 (goto-char (line-end-position))))) 482 (goto-char (line-end-position)))))
470 483
471 ;;;###mh-autoload 484 ;;;###mh-autoload
472 (defun mh-mh-to-mime-undo (noconfirm) 485 (defun mh-mh-to-mime-undo (noconfirm)
473 "Undo effects of \\[mh-mh-to-mime]. 486 "Undo effects of \\[mh-mh-to-mime].
474 Optional non-nil argument NOCONFIRM means don't ask for confirmation." 487 Optional non-nil argument NOCONFIRM means don't ask for
488 confirmation."
475 (interactive "*P") 489 (interactive "*P")
476 (if (null buffer-file-name) 490 (if (null buffer-file-name)
477 (error "Buffer does not seem to be associated with any file")) 491 (error "Buffer does not seem to be associated with any file"))
478 (let ((backup-strings '("," "#")) 492 (let ((backup-strings '("," "#"))
479 backup-file) 493 backup-file)
497 (after-find-file nil))) 511 (after-find-file nil)))
498 512
499 ;;;###mh-autoload 513 ;;;###mh-autoload
500 (defun mh-mh-directive-present-p (&optional begin end) 514 (defun mh-mh-directive-present-p (&optional begin end)
501 "Check if the text between BEGIN and END might be a MH-style directive. 515 "Check if the text between BEGIN and END might be a MH-style directive.
502 The optional argument BEGIN defaults to the beginning of the buffer, while END 516 The optional argument BEGIN defaults to the beginning of the
503 defaults to the the end of the buffer." 517 buffer, while END defaults to the the end of the buffer."
504 (unless begin (setq begin (point-min))) 518 (unless begin (setq begin (point-min)))
505 (unless end (setq end (point-max))) 519 (unless end (setq end (point-max)))
506 (save-excursion 520 (save-excursion
507 (block 'search-for-mh-directive 521 (block 'search-for-mh-directive
508 (goto-char begin) 522 (goto-char begin)
523 ;;; MIME composition functions 537 ;;; MIME composition functions
524 538
525 ;;;###mh-autoload 539 ;;;###mh-autoload
526 (defun mh-mml-to-mime () 540 (defun mh-mml-to-mime ()
527 "Compose MIME message from MML tags. 541 "Compose MIME message from MML tags.
528 Typically, you send a message with attachments just like any other message. 542
529 However, you may take a sneak preview of the MIME encoding if you wish by 543 Typically, you send a message with attachments just like any
530 running this command. 544 other message. However, you may take a sneak preview of the MIME
545 encoding if you wish by running this command.
531 546
532 This action can be undone by running \\[undo]." 547 This action can be undone by running \\[undo]."
533 (interactive) 548 (interactive)
534 (require 'message) 549 (require 'message)
535 (when mh-pgp-support-flag ;; This is only needed for PGP 550 (when mh-pgp-support-flag ;; This is only needed for PGP
546 (error (error-message-string err)))))) 561 (error (error-message-string err))))))
547 562
548 ;;;###mh-autoload 563 ;;;###mh-autoload
549 (defun mh-mml-forward-message (description folder message) 564 (defun mh-mml-forward-message (description folder message)
550 "Forward a message as attachment. 565 "Forward a message as attachment.
551 The function will prompt the user for a DESCRIPTION, a FOLDER and MESSAGE 566
552 number." 567 The function will prompt the user for a DESCRIPTION, a FOLDER and
568 MESSAGE number."
553 (let ((msg (if (and (equal message "") (numberp mh-sent-from-msg)) 569 (let ((msg (if (and (equal message "") (numberp mh-sent-from-msg))
554 mh-sent-from-msg 570 mh-sent-from-msg
555 (car (read-from-string message))))) 571 (car (read-from-string message)))))
556 (cond ((integerp msg) 572 (cond ((integerp msg)
557 (if (string= "" description) 573 (if (string= "" description)
580 mh-mml-method-default)) 596 mh-mml-method-default))
581 597
582 ;;;###mh-autoload 598 ;;;###mh-autoload
583 (defun mh-mml-attach-file (&optional disposition) 599 (defun mh-mml-attach-file (&optional disposition)
584 "Add a tag to insert a MIME message part from a file. 600 "Add a tag to insert a MIME message part from a file.
585 You are prompted for the filename containing the object, the media type if it 601
586 cannot be determined automatically, a content description and the DISPOSITION 602 You are prompted for the filename containing the object, the
587 of the attachment. 603 media type if it cannot be determined automatically, a content
604 description and the DISPOSITION of the attachment.
588 605
589 This is basically `mml-attach-file' from Gnus, modified such that a prefix 606 This is basically `mml-attach-file' from Gnus, modified such that a prefix
590 argument yields an `inline' disposition and Content-Type is determined 607 argument yields an `inline' disposition and Content-Type is determined
591 automatically." 608 automatically."
592 (let* ((file (mml-minibuffer-read-file "Attach file: ")) 609 (let* ((file (mml-minibuffer-read-file "Attach file: "))
599 616
600 (defvar mh-identity-pgg-default-user-id) 617 (defvar mh-identity-pgg-default-user-id)
601 618
602 (defun mh-secure-message (method mode &optional identity) 619 (defun mh-secure-message (method mode &optional identity)
603 "Add tag to encrypt or sign message. 620 "Add tag to encrypt or sign message.
621
604 METHOD should be one of: \"pgpmime\", \"pgp\", \"smime\". 622 METHOD should be one of: \"pgpmime\", \"pgp\", \"smime\".
605 MODE should be one of: \"sign\", \"encrypt\", \"signencrypt\", \"none\". 623 MODE should be one of: \"sign\", \"encrypt\", \"signencrypt\", \"none\".
606 IDENTITY is optionally the default-user-id to use." 624 IDENTITY is optionally the default-user-id to use."
607 (if (not mh-pgp-support-flag) 625 (if (not mh-pgp-support-flag)
608 (error "Your version of Gnus does not support PGP/GPG") 626 (error "Your version of Gnus does not support PGP/GPG")
633 (mml-unsecure-message))) 651 (mml-unsecure-message)))
634 652
635 ;;;###mh-autoload 653 ;;;###mh-autoload
636 (defun mh-mml-secure-message-sign (method) 654 (defun mh-mml-secure-message-sign (method)
637 "Add tag to sign the message. 655 "Add tag to sign the message.
638 A proper multipart message is created for you when you send the message. Use 656
639 the \\[mh-mml-unsecure-message] command to remove this tag. Use a prefix 657 A proper multipart message is created for you when you send the
640 argument METHOD to be prompted for one of the possible security methods 658 message. Use the \\[mh-mml-unsecure-message] command to remove
641 \(see `mh-mml-method-default')." 659 this tag. Use a prefix argument METHOD to be prompted for one of
660 the possible security methods \(see `mh-mml-method-default')."
642 (interactive (list (mh-mml-query-cryptographic-method))) 661 (interactive (list (mh-mml-query-cryptographic-method)))
643 (mh-secure-message method "sign" mh-identity-pgg-default-user-id)) 662 (mh-secure-message method "sign" mh-identity-pgg-default-user-id))
644 663
645 ;;;###mh-autoload 664 ;;;###mh-autoload
646 (defun mh-mml-secure-message-encrypt (method) 665 (defun mh-mml-secure-message-encrypt (method)
647 "Add tag to encrypt the message. 666 "Add tag to encrypt the message.
648 A proper multipart message is created for you when you send the message. Use 667
649 the \\[mh-mml-unsecure-message] command to remove this tag. Use a prefix 668 A proper multipart message is created for you when you send the
650 argument METHOD to be prompted for one of the possible security methods 669 message. Use the \\[mh-mml-unsecure-message] command to remove
651 \(see `mh-mml-method-default')." 670 this tag. Use a prefix argument METHOD to be prompted for one of
671 the possible security methods \(see `mh-mml-method-default')."
652 (interactive (list (mh-mml-query-cryptographic-method))) 672 (interactive (list (mh-mml-query-cryptographic-method)))
653 (mh-secure-message method "encrypt" mh-identity-pgg-default-user-id)) 673 (mh-secure-message method "encrypt" mh-identity-pgg-default-user-id))
654 674
655 ;;;###mh-autoload 675 ;;;###mh-autoload
656 (defun mh-mml-secure-message-signencrypt (method) 676 (defun mh-mml-secure-message-signencrypt (method)
657 "Add tag to encrypt and sign the message. 677 "Add tag to encrypt and sign the message.
658 A proper multipart message is created for you when you send the message. Use 678
659 the \\[mh-mml-unsecure-message] command to remove this tag. Use a prefix 679 A proper multipart message is created for you when you send the
660 argument METHOD to be prompted for one of the possible security methods 680 message. Use the \\[mh-mml-unsecure-message] command to remove
661 \(see `mh-mml-method-default')." 681 this tag. Use a prefix argument METHOD to be prompted for one of
682 the possible security methods \(see `mh-mml-method-default')."
662 (interactive (list (mh-mml-query-cryptographic-method))) 683 (interactive (list (mh-mml-query-cryptographic-method)))
663 (mh-secure-message method "signencrypt" mh-identity-pgg-default-user-id)) 684 (mh-secure-message method "signencrypt" mh-identity-pgg-default-user-id))
664 685
665 ;;;###mh-autoload 686 ;;;###mh-autoload
666 (defun mh-mml-tag-present-p () 687 (defun mh-mml-tag-present-p ()
693 (mm-destroy-parts (mh-mime-handles mime-data))) 714 (mm-destroy-parts (mh-mime-handles mime-data)))
694 (remhash (current-buffer) mh-globals-hash))) 715 (remhash (current-buffer) mh-globals-hash)))
695 716
696 (defun mh-handle-set-external-undisplayer (folder handle function) 717 (defun mh-handle-set-external-undisplayer (folder handle function)
697 "Replacement for `mm-handle-set-external-undisplayer'. 718 "Replacement for `mm-handle-set-external-undisplayer'.
698 This is only called in recent versions of Gnus. The MIME handles are stored 719
699 in data structures corresponding to MH-E folder buffer FOLDER instead of in 720 This is only called in recent versions of Gnus. The MIME handles
700 Gnus (as in the original). The MIME part, HANDLE is associated with the 721 are stored in data structures corresponding to MH-E folder buffer
701 undisplayer FUNCTION." 722 FOLDER instead of in Gnus (as in the original). The MIME part,
723 HANDLE is associated with the undisplayer FUNCTION."
702 (if (mm-keep-viewer-alive-p handle) 724 (if (mm-keep-viewer-alive-p handle)
703 (let ((new-handle (copy-sequence handle))) 725 (let ((new-handle (copy-sequence handle)))
704 (mm-handle-set-undisplayer new-handle function) 726 (mm-handle-set-undisplayer new-handle function)
705 (mm-handle-set-undisplayer handle nil) 727 (mm-handle-set-undisplayer handle nil)
706 (save-excursion 728 (save-excursion
714 (eval-when-compile (require 'font-lock)) 736 (eval-when-compile (require 'font-lock))
715 737
716 ;;;###mh-autoload 738 ;;;###mh-autoload
717 (defun mh-add-missing-mime-version-header () 739 (defun mh-add-missing-mime-version-header ()
718 "Some mail programs don't put a MIME-Version header. 740 "Some mail programs don't put a MIME-Version header.
719 I have seen this only in spam, so maybe we shouldn't fix this ;-)" 741 I have seen this only in spam, so maybe we shouldn't fix
742 this ;-)"
720 (save-excursion 743 (save-excursion
721 (goto-char (point-min)) 744 (goto-char (point-min))
722 (re-search-forward "\n\n" nil t) 745 (re-search-forward "\n\n" nil t)
723 (save-restriction 746 (save-restriction
724 (narrow-to-region (point-min) (point)) 747 (narrow-to-region (point-min) (point))
727 (goto-char (point-min)) 750 (goto-char (point-min))
728 (insert "MIME-Version: 1.0\n"))))) 751 (insert "MIME-Version: 1.0\n")))))
729 752
730 (defun mh-small-show-buffer-p () 753 (defun mh-small-show-buffer-p ()
731 "Check if show buffer is small. 754 "Check if show buffer is small.
732 This is used to decide if smileys and graphical emphasis will be displayed." 755 This is used to decide if smileys and graphical emphasis will be
756 displayed."
733 (let ((max nil)) 757 (let ((max nil))
734 (when (and (boundp 'font-lock-maximum-size) font-lock-maximum-size) 758 (when (and (boundp 'font-lock-maximum-size) font-lock-maximum-size)
735 (cond ((numberp font-lock-maximum-size) 759 (cond ((numberp font-lock-maximum-size)
736 (setq max font-lock-maximum-size)) 760 (setq max font-lock-maximum-size))
737 ((listp font-lock-maximum-size) 761 ((listp font-lock-maximum-size)
801 825
802 ;;;###mh-autoload 826 ;;;###mh-autoload
803 (defun mh-mime-save-parts (prompt) 827 (defun mh-mime-save-parts (prompt)
804 "Save attachments. 828 "Save attachments.
805 829
806 You can save all of the attachments at once with this command. The attachments 830 You can save all of the attachments at once with this command.
807 are saved in the directory specified by the option 831 The attachments are saved in the directory specified by the
808 `mh-mime-save-parts-default-directory' unless you use a prefix argument PROMPT 832 option `mh-mime-save-parts-default-directory' unless you use a
809 in which case you are prompted for the directory. These directories may be 833 prefix argument PROMPT in which case you are prompted for the
810 superseded by MH profile components, since this function calls on 834 directory. These directories may be superseded by MH profile
811 \"mhstore\" (\"mhn\") to do the work." 835 components, since this function calls on \"mhstore\" (\"mhn\") to
836 do the work."
812 (interactive "P") 837 (interactive "P")
813 (let ((msg (if (eq major-mode 'mh-show-mode) 838 (let ((msg (if (eq major-mode 'mh-show-mode)
814 (mh-show-buffer-message-number) 839 (mh-show-buffer-message-number)
815 (mh-get-msg-num t))) 840 (mh-get-msg-num t)))
816 (folder (if (eq major-mode 'mh-show-mode) 841 (folder (if (eq major-mode 'mh-show-mode)
898 (rfc2047-decode-region (point-min) (mh-mail-header-end))))) 923 (rfc2047-decode-region (point-min) (mh-mail-header-end)))))
899 924
900 ;;;###mh-autoload 925 ;;;###mh-autoload
901 (defun mh-mime-display (&optional pre-dissected-handles) 926 (defun mh-mime-display (&optional pre-dissected-handles)
902 "Display (and possibly decode) MIME handles. 927 "Display (and possibly decode) MIME handles.
903 Optional argument, PRE-DISSECTED-HANDLES is a list of MIME handles. If 928 Optional argument, PRE-DISSECTED-HANDLES is a list of MIME
904 present they are displayed otherwise the buffer is parsed and then 929 handles. If present they are displayed otherwise the buffer is
905 displayed." 930 parsed and then displayed."
906 (let ((handles ()) 931 (let ((handles ())
907 (folder mh-show-folder-buffer) 932 (folder mh-show-folder-buffer)
908 (raw-message-data (buffer-string))) 933 (raw-message-data (buffer-string)))
909 (flet ((mm-handle-set-external-undisplayer 934 (flet ((mm-handle-set-external-undisplayer
910 (handle function) 935 (handle function)
972 (goto-char (point-max)))) 997 (goto-char (point-max))))
973 (t (mh-mime-display-mixed handles))))) 998 (t (mh-mime-display-mixed handles)))))
974 999
975 (defun mh-mime-maybe-display-alternatives (alternatives) 1000 (defun mh-mime-maybe-display-alternatives (alternatives)
976 "Show buttons for ALTERNATIVES. 1001 "Show buttons for ALTERNATIVES.
977 If `mh-mime-display-alternatives-flag' is non-nil then display buttons for 1002 If `mh-mime-display-alternatives-flag' is non-nil then display
978 alternative parts that are usually suppressed." 1003 buttons for alternative parts that are usually suppressed."
979 (when (and mh-display-buttons-for-alternatives-flag alternatives) 1004 (when (and mh-display-buttons-for-alternatives-flag alternatives)
980 (insert "\n----------------------------------------------------\n") 1005 (insert "\n----------------------------------------------------\n")
981 (insert "Alternatives:\n") 1006 (insert "Alternatives:\n")
982 (dolist (x alternatives) 1007 (dolist (x alternatives)
983 (insert "\n") 1008 (insert "\n")
988 "Display the list of MIME parts, HANDLES recursively." 1013 "Display the list of MIME parts, HANDLES recursively."
989 (mapcar #'mh-mime-display-part handles)) 1014 (mapcar #'mh-mime-display-part handles))
990 1015
991 (defun mh-mime-part-index (handle) 1016 (defun mh-mime-part-index (handle)
992 "Generate the button number for MIME part, HANDLE. 1017 "Generate the button number for MIME part, HANDLE.
993 Notice that a hash table is used to display the same number when buttons need 1018 Notice that a hash table is used to display the same number when
994 to be displayed multiple times (for instance when nested messages are 1019 buttons need to be displayed multiple times (for instance when
995 opened)." 1020 nested messages are opened)."
996 (or (gethash handle (mh-mime-part-index-hash (mh-buffer-data))) 1021 (or (gethash handle (mh-mime-part-index-hash (mh-buffer-data)))
997 (setf (gethash handle (mh-mime-part-index-hash (mh-buffer-data))) 1022 (setf (gethash handle (mh-mime-part-index-hash (mh-buffer-data)))
998 (incf (mh-mime-parts-count (mh-buffer-data)))))) 1023 (incf (mh-mime-parts-count (mh-buffer-data))))))
999 1024
1000 (defun mh-small-image-p (handle) 1025 (defun mh-small-image-p (handle)
1073 (mh-mm-display-part handle))) 1098 (mh-mm-display-part handle)))
1074 (goto-char (point-max))))) 1099 (goto-char (point-max)))))
1075 1100
1076 (defun mh-signature-highlight (&optional handle) 1101 (defun mh-signature-highlight (&optional handle)
1077 "Highlight message signature in HANDLE. 1102 "Highlight message signature in HANDLE.
1078 The optional argument, HANDLE is a MIME handle if the function is being used 1103 The optional argument, HANDLE is a MIME handle if the function is
1079 to highlight the signature in a MIME part." 1104 being used to highlight the signature in a MIME part."
1080 (let ((regexp 1105 (let ((regexp
1081 (cond ((not handle) "^-- $") 1106 (cond ((not handle) "^-- $")
1082 ((not (and (equal (mm-handle-media-supertype handle) "text") 1107 ((not (and (equal (mm-handle-media-supertype handle) "text")
1083 (equal (mm-handle-media-subtype handle) "html"))) 1108 (equal (mm-handle-media-subtype handle) "html")))
1084 "^-- $") 1109 "^-- $")
1099 (defvar dots) 1124 (defvar dots)
1100 (defvar type)) 1125 (defvar type))
1101 1126
1102 (defun mh-insert-mime-button (handle index displayed) 1127 (defun mh-insert-mime-button (handle index displayed)
1103 "Insert MIME button for HANDLE. 1128 "Insert MIME button for HANDLE.
1104 INDEX is the part number that will be DISPLAYED. It is also used by commands 1129 INDEX is the part number that will be DISPLAYED. It is also used
1105 like \"K v\" which operate on individual MIME parts." 1130 by commands like \"K v\" which operate on individual MIME parts."
1106 ;; The button could be displayed by a previous decode. In that case 1131 ;; The button could be displayed by a previous decode. In that case
1107 ;; undisplay it if we need a hidden button. 1132 ;; undisplay it if we need a hidden button.
1108 (when (and (mm-handle-displayed-p handle) (not displayed)) 1133 (when (and (mm-handle-displayed-p handle) (not displayed))
1109 (mm-display-part handle)) 1134 (mm-display-part handle))
1110 (let ((name (or (mail-content-type-get (mm-handle-type handle) 'name) 1135 (let ((name (or (mail-content-type-get (mm-handle-type handle) 'name)
1212 1237
1213 ;;;###mh-autoload 1238 ;;;###mh-autoload
1214 (defun mh-press-button () 1239 (defun mh-press-button ()
1215 "View contents of button. 1240 "View contents of button.
1216 1241
1217 This command is a toggle so if you use it again on the same attachment, the 1242 This command is a toggle so if you use it again on the same
1218 attachment is hidden." 1243 attachment, the attachment is hidden."
1219 (interactive) 1244 (interactive)
1220 (let ((mm-inline-media-tests mh-mm-inline-media-tests) 1245 (let ((mm-inline-media-tests mh-mm-inline-media-tests)
1221 (data (get-text-property (point) 'mh-data)) 1246 (data (get-text-property (point) 'mh-data))
1222 (function (get-text-property (point) 'mh-callback)) 1247 (function (get-text-property (point) 'mh-callback))
1223 (buffer-read-only nil) 1248 (buffer-read-only nil)
1231 (set-buffer-modified-p nil))))) 1256 (set-buffer-modified-p nil)))))
1232 1257
1233 ;;;###mh-autoload 1258 ;;;###mh-autoload
1234 (defun mh-push-button (event) 1259 (defun mh-push-button (event)
1235 "Click MIME button for EVENT. 1260 "Click MIME button for EVENT.
1236 If the MIME part is visible then it is removed. Otherwise the part is 1261
1237 displayed. This function is called when the mouse is used to click the MIME 1262 If the MIME part is visible then it is removed. Otherwise the
1238 button." 1263 part is displayed. This function is called when the mouse is used
1264 to click the MIME button."
1239 (interactive "e") 1265 (interactive "e")
1240 (mh-do-at-event-location event 1266 (mh-do-at-event-location event
1241 (let ((folder mh-show-folder-buffer) 1267 (let ((folder mh-show-folder-buffer)
1242 (mm-inline-media-tests mh-mm-inline-media-tests) 1268 (mm-inline-media-tests mh-mm-inline-media-tests)
1243 (data (get-text-property (point) 'mh-data)) 1269 (data (get-text-property (point) 'mh-data))
1287 1313
1288 ;;;###mh-autoload 1314 ;;;###mh-autoload
1289 (defun mh-display-with-external-viewer (part-index) 1315 (defun mh-display-with-external-viewer (part-index)
1290 "View attachment externally. 1316 "View attachment externally.
1291 1317
1292 If Emacs does not know how to view an attachment, you could save it into a 1318 If Emacs does not know how to view an attachment, you could save
1293 file and then run some program to open it. It is easier, however, to launch 1319 it into a file and then run some program to open it. It is
1294 the program directly from MH-E with this command. While you'll most likely use 1320 easier, however, to launch the program directly from MH-E with
1295 this to view spreadsheets and documents, it is also useful to use your browser 1321 this command. While you'll most likely use this to view
1296 to view HTML attachments with higher fidelity than what Emacs can provide. 1322 spreadsheets and documents, it is also useful to use your browser
1297 1323 to view HTML attachments with higher fidelity than what Emacs can
1298 This command displays the attachment associated with the button under the 1324 provide.
1299 cursor. If the cursor is not located over a button, then the cursor first 1325
1300 moves to the next button, wrapping to the beginning of the message if 1326 This command displays the attachment associated with the button
1301 necessary. You can provide a numeric prefix argument PART-INDEX to view the 1327 under the cursor. If the cursor is not located over a button,
1302 attachment labeled with that number. 1328 then the cursor first moves to the next button, wrapping to the
1303 1329 beginning of the message if necessary. You can provide a numeric
1304 This command tries to provide a reasonable default for the viewer by calling 1330 prefix argument PART-INDEX to view the attachment labeled with
1305 the Emacs function `mailcap-mime-info'. This function usually reads the file 1331 that number.
1306 \"/etc/mailcap\"." 1332
1333 This command tries to provide a reasonable default for the viewer
1334 by calling the Emacs function `mailcap-mime-info'. This function
1335 usually reads the file \"/etc/mailcap\"."
1307 (interactive "P") 1336 (interactive "P")
1308 (when (consp part-index) (setq part-index (car part-index))) 1337 (when (consp part-index) (setq part-index (car part-index)))
1309 (mh-folder-mime-action 1338 (mh-folder-mime-action
1310 part-index 1339 part-index
1311 #'(lambda () 1340 #'(lambda ()
1456 "(passphrase may be incorrect)" ""))) 1485 "(passphrase may be incorrect)" "")))
1457 (message "%s %s failed %s" crypto-type type warning))))) 1486 (message "%s %s failed %s" crypto-type type warning)))))
1458 1487
1459 (defun mh-mm-inline-message (handle) 1488 (defun mh-mm-inline-message (handle)
1460 "Display message, HANDLE. 1489 "Display message, HANDLE.
1461 The function decodes the message and displays it. It avoids decoding the same 1490 The function decodes the message and displays it. It avoids
1462 message multiple times." 1491 decoding the same message multiple times."
1463 (let ((b (point)) 1492 (let ((b (point))
1464 (clean-message-header mh-clean-message-header-flag) 1493 (clean-message-header mh-clean-message-header-flag)
1465 (invisible-headers mh-invisible-header-fields-compiled) 1494 (invisible-headers mh-invisible-header-fields-compiled)
1466 (visible-headers nil)) 1495 (visible-headers nil))
1467 (save-excursion 1496 (save-excursion