mh-gnus.el 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. ;;; mh-gnus.el --- make MH-E compatible with various versions of Gnus
  2. ;; Copyright (C) 2003-2004, 2006-2012 Free Software Foundation, Inc.
  3. ;; Author: Satyaki Das <satyaki@theforce.stanford.edu>
  4. ;; Maintainer: Bill Wohler <wohler@newt.com>
  5. ;; Keywords: mail
  6. ;; See: mh-e.el
  7. ;; This file is part of GNU Emacs.
  8. ;; GNU Emacs is free software: you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation, either version 3 of the License, or
  11. ;; (at your option) any later version.
  12. ;; GNU Emacs is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  18. ;;; Commentary:
  19. ;;; Change Log:
  20. ;;; Code:
  21. (require 'mh-e)
  22. (mh-require 'gnus-util nil t)
  23. (mh-require 'mm-bodies nil t)
  24. (mh-require 'mm-decode nil t)
  25. (mh-require 'mm-view nil t)
  26. (mh-require 'mml nil t)
  27. ;; Copy of function from gnus-util.el.
  28. ;; TODO This is not in Gnus 5.11.
  29. (defun-mh mh-gnus-local-map-property gnus-local-map-property (map)
  30. "Return a list suitable for a text property list specifying keymap MAP."
  31. (cond ((featurep 'xemacs) (list 'keymap map))
  32. ((>= emacs-major-version 21) (list 'keymap map))
  33. (t (list 'local-map map))))
  34. ;; Copy of function from mm-decode.el.
  35. (defun-mh mh-mm-merge-handles mm-merge-handles (handles1 handles2)
  36. (append
  37. (if (listp (car handles1))
  38. handles1
  39. (list handles1))
  40. (if (listp (car handles2))
  41. handles2
  42. (list handles2))))
  43. ;; Copy of function from mm-decode.el.
  44. (defun-mh mh-mm-set-handle-multipart-parameter
  45. mm-set-handle-multipart-parameter (handle parameter value)
  46. ;; HANDLE could be a CTL.
  47. (when handle
  48. (put-text-property 0 (length (car handle)) parameter value
  49. (car handle))))
  50. ;; Copy of function from mm-view.el.
  51. (defun-mh mh-mm-inline-text-vcard mm-inline-text-vcard (handle)
  52. (let ((inhibit-read-only t))
  53. (mm-insert-inline
  54. handle
  55. (concat "\n-- \n"
  56. (ignore-errors
  57. (if (fboundp 'vcard-pretty-print)
  58. (vcard-pretty-print (mm-get-part handle))
  59. (vcard-format-string
  60. (vcard-parse-string (mm-get-part handle)
  61. 'vcard-standard-filter))))))))
  62. ;; Function from mm-decode.el used in PGP messages. Just define it with older
  63. ;; Gnus to avoid compiler warning.
  64. (defun-mh mh-mm-possibly-verify-or-decrypt
  65. mm-possibly-verify-or-decrypt (parts ctl)
  66. nil)
  67. ;; Copy of macro in mm-decode.el.
  68. (defmacro-mh mh-mm-handle-multipart-ctl-parameter
  69. mm-handle-multipart-ctl-parameter (handle parameter)
  70. `(get-text-property 0 ,parameter (car ,handle)))
  71. ;; Copy of function in mm-decode.el.
  72. (defun-mh mh-mm-readable-p mm-readable-p (handle)
  73. "Say whether the content of HANDLE is readable."
  74. (and (< (with-current-buffer (mm-handle-buffer handle)
  75. (buffer-size)) 10000)
  76. (mm-with-unibyte-buffer
  77. (mm-insert-part handle)
  78. (and (eq (mm-body-7-or-8) '7bit)
  79. (not (mh-mm-long-lines-p 76))))))
  80. ;; Copy of function in mm-bodies.el.
  81. (defun-mh mh-mm-long-lines-p mm-long-lines-p (length)
  82. "Say whether any of the lines in the buffer is longer than LENGTH."
  83. (save-excursion
  84. (goto-char (point-min))
  85. (end-of-line)
  86. (while (and (not (eobp))
  87. (not (> (current-column) length)))
  88. (forward-line 1)
  89. (end-of-line))
  90. (and (> (current-column) length)
  91. (current-column))))
  92. (defun-mh mh-mm-keep-viewer-alive-p mm-keep-viewer-alive-p (handle)
  93. ;; Released Gnus doesn't keep handles associated with externally displayed
  94. ;; MIME parts. So this will always return nil.
  95. nil)
  96. (defun-mh mh-mm-destroy-parts mm-destroy-parts (list)
  97. "Older versions of Emacs don't have this function."
  98. nil)
  99. (defun-mh mh-mm-uu-dissect-text-parts mm-uu-dissect-text-parts (handles)
  100. "Emacs 21 and XEmacs don't have this function."
  101. nil)
  102. ;; Copy of function in mml.el.
  103. (defun-mh mh-mml-minibuffer-read-disposition
  104. mml-minibuffer-read-disposition (type &optional default filename)
  105. (unless default
  106. (setq default (mml-content-disposition type filename)))
  107. (let ((disposition (completing-read
  108. (format "Disposition (default %s): " default)
  109. '(("attachment") ("inline") (""))
  110. nil t nil nil default)))
  111. (if (not (equal disposition ""))
  112. disposition
  113. default)))
  114. ;; This is mm-save-part from Gnus 5.11 since that function in Emacs
  115. ;; 21.2 is buggy (the args to read-file-name are incorrect) and the
  116. ;; version in Emacs 22 is not consistent with C-x C-w in that you
  117. ;; can't just specify a directory and have the right thing happen.
  118. (defun mh-mm-save-part (handle &optional prompt)
  119. "Write HANDLE to a file.
  120. PROMPT overrides the default one used to ask user for a file name."
  121. (let ((filename (or (mail-content-type-get
  122. (mm-handle-disposition handle) 'filename)
  123. (mail-content-type-get
  124. (mm-handle-type handle) 'name)))
  125. file)
  126. (when filename
  127. (setq filename (gnus-map-function mm-file-name-rewrite-functions
  128. (file-name-nondirectory filename))))
  129. (setq file
  130. (read-file-name (or prompt "Save MIME part to: ")
  131. (or mm-default-directory default-directory)
  132. nil nil (or filename "")))
  133. (setq mm-default-directory (file-name-directory file))
  134. (and (or (not (file-exists-p file))
  135. (yes-or-no-p (format "File %s already exists; overwrite? "
  136. file)))
  137. (progn
  138. (mm-save-part-to-file handle file)
  139. file))))
  140. (defun mh-mm-text-html-renderer ()
  141. "Find the renderer Gnus is using to display text/html MIME parts."
  142. (or (and (boundp 'mm-inline-text-html-renderer) mm-inline-text-html-renderer)
  143. (and (boundp 'mm-text-html-renderer) mm-text-html-renderer)))
  144. (provide 'mh-gnus)
  145. ;; Local Variables:
  146. ;; no-byte-compile: t
  147. ;; no-update-autoloads: t
  148. ;; indent-tabs-mode: nil
  149. ;; sentence-end-double-space: nil
  150. ;; End:
  151. ;;; mh-gnus.el ends here