home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / sfnet / tietolii / ryhmatl / 493 < prev    next >
Encoding:
Text File  |  1992-12-27  |  11.9 KB  |  351 lines

  1. Xref: sparky sfnet.tietoliikenne.ryhmat+listat:493 sfnet.atk.sodat:668 sfnet.tietoliikenne.viestinviejat:37 sfnet.atk.gnu:12
  2. Path: sparky!uunet!mcsun!news.funet.fi!funic!sauna.cs.hut.fi!cs.hut.fi!jpm
  3. From: jpm@cs.hut.fi (Jussi-Pekka Mantere)
  4. Newsgroups: sfnet.tietoliikenne.ryhmat+listat,sfnet.atk.sodat,sfnet.tietoliikenne.viestinviejat,sfnet.atk.gnu
  5. Subject: MIME & GNUS
  6. Followup-To: sfnet.atk.gnu
  7. Date: 27 Dec 92 13:46:23 GMT
  8. Organization: Helsinki University of Technology, Finland
  9. Lines: 332
  10. Distribution: sfnet
  11. Message-ID: <JPM.92Dec27154623@cardhu.cs.hut.fi>
  12. References: <OTTO.92Dec6180704@kalikka.jyu.fi> <JPM.92Dec6221830@cardhu.cs.hut.fi>
  13.     <JARVELAI.92Dec17212955@uranus.csc.fi>
  14.     <JVH.92Dec20013336@laphroaig.cs.hut.fi>
  15.     <1992Dec26.165105.24518@polaris.utu.fi>
  16. NNTP-Posting-Host: cardhu.cs.hut.fi
  17. In-reply-to: mea@polaris.utu.fi's message of Sat, 26 Dec 92 16:51:05 GMT
  18.  
  19. Matti Aarnio <mea@polaris.utu.fi> kirjoittaa:
  20.  
  21.      Tervemenoa tekem{{n GNUS-versio, joka sis{lt{{ uudet speedup
  22.    paketit ja MIME-featuret, sille on varmasti kysynt{{!
  23.  
  24. Avot, t{ss{!
  25.  
  26. Chape
  27.  
  28. Newsgroups: comp.mail.mime,gnu.emacs.gnus
  29. From: spike@world.std.com (Joe Ilacqua)
  30. Subject: MIME support for GNUS.
  31. Message-ID: <BzqJv8.5z9@world.std.com>
  32. Organization: Software Tool & Die
  33. Date: Wed, 23 Dec 1992 23:28:19 GMT
  34.  
  35.  
  36.     This is more of a proof of concept than a finished product,
  37. but it seems to work.  This package allows you to read MIME format
  38. news articles, use richtext in you postings, and insert (presumably
  39. binary) files into you messages.
  40.  
  41.     You need to have "Metamail" installed and have
  42. "transparent.el" in your load path.
  43. Have fun.
  44.  
  45. ->Spike
  46.  
  47. #!/bin/sh
  48. # This is a shell archive (produced by shar 3.50)
  49. # To extract the files from this archive, save it to a file, remove
  50. # everything above the "!/bin/sh" line above, and type "sh file_name".
  51. #
  52. # made 12/23/1992 23:24 UTC by spike@world
  53. # Source directory /staff/spike
  54. #
  55. # existing files will NOT be overwritten unless -c is specified
  56. #
  57. # This shar contains:
  58. # length  mode       name
  59. # ------ ---------- ------------------------------------------
  60. #   9416 -rw-rw-r-- gnus-mime.el
  61. #
  62. # ============= gnus-mime.el ==============
  63. if test -f 'gnus-mime.el' -a X"$1" != X"-c"; then
  64.     echo 'x - skipping gnus-mime.el (File already exists)'
  65. else
  66. echo 'x - extracting gnus-mime.el (Text)'
  67. sed 's/^X//' << 'SHAR_EOF' > 'gnus-mime.el' &&
  68. ;;;  Support to read/post MIME format USENET articles in GNUS.
  69. X
  70. ;;  Author Spike <Spike@world.std.com>
  71. ;;  with code from Michael Littman's <mlittman@breeze.bellcore.com>
  72. ;;  richtext.el and metamail's MH-E patches.
  73. X
  74. X
  75. ;;  This requires that you have the metamail package installed
  76. ;;  (thumper.bellcore.com:/pub/nsb/mm.tar.Z) and transparent.el
  77. ;;  
  78. ;;  This package provides four basic functions
  79. ;;
  80. ;;  gnus-Subject-run-metamail - invokes metamail on the selected news article.
  81. ;;  gnus-inews-article - replaces the standard gnus-inews-article with one
  82. ;;                       which inserts MIME headers and does Richtext style
  83. ;;                       signatures.
  84. ;;  gnus-richtext-posting - converts the posting buffer to Richtext format,
  85. ;;                          knows how to make text bold, italics, and
  86. ;;                          underlined.
  87. ;;  gnus-insert-file-as-mime - Allows you to insert arbitrary data into
  88. ;;                             a posting in MIME format.  Automatically
  89. ;;                             recognizes some formats (GIF, JPEG, PS),
  90. ;;                             more can be add through "auto-mime-id-list".
  91. X
  92. ;;  As ships this binds gnus-Subject-run-metamail to "@" in the "*Subject*"
  93. ;;  buffer.  gnus-richtext-posting to "C-c r" and "gnus-insert-file-as-mime" to
  94. ;;  "C-c i" in the posting buffer.
  95. ;;
  96. X
  97. ;;  To use put "(load-library "gnus-mime.el")" in your ".emacs" or "default.el"
  98. X
  99. ;;  If you want GNUS to announce MIME postings but something like:
  100. ;;  (setq gnus-Article-prepare-hook
  101. ;;       '(lambda ()
  102. ;;      (gnus-Subject-check-content-type)))
  103. ;;  in your ".emacs" file.
  104. X
  105. ;; CAVEATS: You can only insert one file per posting.  You can not call
  106. ;;          gnus-richtext-posting after calling gnus-insert-file-as-mime.
  107. X
  108. (require 'transparent)
  109. (load-library "rnewspost") ;; sigh...  This could be better.
  110. (require 'gnuspost)
  111. (provide 'gnus-mime)
  112. X
  113. (defvar gnus-invoke-mime-key "@" 
  114. X  "The key that calls gnus-Subject-run-metamail")
  115. X
  116. (define-key gnus-Subject-mode-map gnus-invoke-mime-key
  117. X  'gnus-Subject-run-metamail)
  118. X
  119. (define-key news-reply-mode-map "\C-cr" 'gnus-richtext-posting)
  120. (define-key news-reply-mode-map "\C-ci" 'gnus-insert-file-as-mime)
  121. X
  122. (defvar auto-mime-id-list nil "\
  123. A list of filename patterns vs corresponding MIME type strings
  124. Each element looks like (REGEXP . TYPE).")
  125. (setq auto-mime-id-list (mapcar 'purecopy
  126. X                              '(("\\.gif$" . "image/gif")
  127. X                ("\\.jpg$" . "image/jpeg")
  128. X                ("\\.xwd$" . "image/x-xwd")
  129. X                ("\\.ps$"  . "application/PostScript"))))
  130. X
  131. ;;;;;;
  132. X
  133. (defun gnus-Subject-check-content-type ()
  134. X  (if (gnus-fetch-field "Mime-Version")
  135. X      (let ((content-type (gnus-fetch-field "Content-Type")))
  136. X       (message (concat "You can use '" gnus-invoke-mime-key 
  137. X                "' to view this '" content-type 
  138. X                "' MIME format article.")))))
  139. X
  140. (defun gnus-Subject-run-metamail ()
  141. X  (interactive)
  142. X  "Process Selected Article Through \"metamail\"."
  143. X  (gnus-Subject-select-article)
  144. X  (gnus-eval-in-buffer-window gnus-Article-buffer
  145. X  (let ((metamail-tmpfile (make-temp-name "/tmp/rmailct")))
  146. X    (save-restriction
  147. X      (widen)
  148. X      (write-region (point-min) (point-max) metamail-tmpfile))
  149. X    (if 
  150. X    (and window-system (getenv "DISPLAY"))
  151. X    (let ((buffer-read-only nil))
  152. X      (push-mark (point) t)
  153. X      (erase-buffer)
  154. X      (call-process "metamail" nil t t
  155. X         "-m" "mh-e" "-x" "-d" "-q" "-z" metamail-tmpfile)
  156. X      (exchange-point-and-mark)
  157. X      (set-buffer-modified-p nil)
  158. X      (other-window -1))
  159. X      (progn
  160. X    (other-window -1)
  161. X    (switch-to-buffer "METAMAIL")
  162. X    (erase-buffer)
  163. X    (sit-for 0)
  164. X    (transparent-window
  165. X     "METAMAIL"
  166. X     "metamail"
  167. X     (list "-p" "-d" "-q" metamail-tmpfile)
  168. X     nil
  169. X     (concat
  170. X      "\n\r\n\r*****************************************"
  171. X      "*******************************\n\rPress any key "
  172. X      "to go back to EMACS\n\r\n\r***********************" 
  173. X      "*************************************************\n\r")))
  174. X      )
  175. X    )
  176. X  )
  177. X )
  178. X
  179. X
  180. (defvar rich-substitutions
  181. X      '(
  182. X        ("<"        "<lt>") ; in case some one sends less-thans.
  183. X        ("\\B%\\b" "</italic>") ; needs to be first to not get closing tags.
  184. X        ("\\b%\\B" "<italic>")
  185. X        ("\\B\\*\\b" "<bold>")
  186. X        ("\\b\\*\\B" "</bold>")
  187. X        ("
  188. " "
  189. <nl>")
  190. X        ("\\B_\\b" "<underline>")
  191. X        ("\\b_\\B" "</underline>")
  192. X        )
  193. X      "A table of REGEXP to translate text to MIME's text/richtext format.")
  194. X
  195. (defun gnus-richtext-posting ()
  196. X  "Convert the current buffer to MIME's \"text/richtext\" format.
  197. \"*foo*\" is converted to bold, \"%foo%\" to italics, and \"_foo_\" to
  198. underlined. Note: this does not recognize font markers *after*
  199. punctuation, thus \"*foo!*\" will not work."
  200. X  (interactive)
  201. X  (mail-position-on-field "Subject")
  202. X  (or (gnus-fetch-field "Mime-Version")
  203. X      (insert "\nMime-Version: 1.0"))
  204. X  (or (gnus-fetch-field "Content-Type")
  205. X      (insert "\nContent-Type: text/richtext"))
  206. X  (goto-char (point-min))
  207. X  (search-forward (concat "\n" mail-header-separator "\n") nil t)
  208. X  (perform-rich-sub)
  209. X  )
  210. X
  211. (defun perform-rich-sub ()
  212. X  "Perform the rich substiution."
  213. X  (let ((subs rich-substitutions)
  214. X        pat rep
  215. X        (top (point)))
  216. X    (save-excursion
  217. X      (while subs
  218. X        (setq pat (car (car subs)))
  219. X        (setq rep (car (cdr (car subs))))
  220. X        (setq subs (cdr subs))
  221. X        (goto-char top)
  222. X        (while (re-search-forward pat (point-max) t)
  223. X          (replace-match rep))
  224. X        ))))
  225. X
  226. (defun gnus-insert-file-as-mime (filename)
  227. X  "Encode and insert a file into the posting buffer and setup the correct
  228. MIME headers for that file type."
  229. X  (interactive "FFind file: ")
  230. X  (let ((ctype nil)
  231. X    (boundary
  232. X     (concat "GNUS.BOUNDARY." (system-name) "." (current-time-string))))
  233. X    (let ((mlist auto-mime-id-list)
  234. X      (name filename))
  235. X      (while (and (not ctype) mlist)
  236. X    (if (string-match (car (car mlist)) name)
  237. X        (setq ctype (cdr (car mlist))))
  238. X              (setq mlist (cdr mlist))))
  239. X    (if (not ctype)
  240. X    (setq ctype 
  241. X          (read-string "MIME content type: " "application/octet-stream")))
  242. X    (goto-char (point-min))
  243. X    (re-search-forward
  244. X     (concat "^" (regexp-quote mail-header-separator) "\n"))
  245. X    (insert (concat "--" boundary "\n"))
  246. X    (insert "Content-type: text/richtext\n")
  247. X    (insert "Content-Transfer-Encoding: quoted-printable\n\n")
  248. X    (goto-char (point-max))
  249. X    (insert (concat "\n--" boundary "\n"))
  250. X    (insert (concat "Content-type: " ctype "\n"))
  251. X    (insert "Content-Transfer-Encoding: base64\n\n")
  252. X    (shell-command (concat "mmencode " filename) t)
  253. X    (goto-char (point-max))
  254. X    (insert (concat "\n--" boundary "\n"))
  255. X    (mail-position-on-field "Subject")
  256. X    (or (gnus-fetch-field "Mime-Version")
  257. X    (insert "\nMime-Version: 1.0"))
  258. X    (if (gnus-fetch-field "Content-Type")
  259. X    (progn
  260. X      (mail-position-on-field "Content-Type")
  261. X      (beginning-of-line)
  262. X      (delete-region (point) (progn (forward-line 1) (point)))))
  263. X      (insert (concat "Content-Type: multipart/mixed;\n"
  264. X              "\tboundary=\"" boundary "\"\n"))
  265. X    ))
  266. X
  267. (defun gnus-inews-article ()
  268. X  "NNTP inews interface."
  269. X  (let ((signature
  270. X     (if gnus-signature-file
  271. X         (expand-file-name gnus-signature-file nil)))
  272. X    (distribution nil)
  273. X    (artbuf (current-buffer))
  274. X    (tmpbuf (get-buffer-create " *GNUS-posting*"))
  275. X    (ctype nil))
  276. X    (save-excursion
  277. X      (set-buffer tmpbuf)
  278. X      (buffer-flush-undo (current-buffer))
  279. X      (erase-buffer)
  280. X      (insert-buffer-substring artbuf)
  281. X      ;; Get distribution.
  282. X      (setq distribution (gnus-fetch-field "Distribution"))
  283. X      (if signature
  284. X      (progn
  285. X        ;; Change signature file by distribution.
  286. X        ;; Suggested by hyoko@flab.fujitsu.junet.
  287. X        (if (file-exists-p (concat signature "-" distribution))
  288. X        (setq signature (concat signature "-" distribution)))
  289. X        ;; Insert signature.
  290. X        (if (file-exists-p signature)
  291. X        (progn
  292. X          ;; Mime signature format
  293. X          (setq ctype (gnus-fetch-field "Content-Type"))
  294. X          (if (and ctype (string-match "multipart/mixed" ctype))
  295. X              (progn
  296. X            (string-match "boundary=\"" ctype)
  297. X            (setq boundary (substring ctype  (- (match-end 0) 1)))
  298. X            (string-match "\"" boundary)
  299. X            (setq boundary 
  300. X                  (substring boundary 0 (- (match-end 0) 1)))
  301. X            (goto-char (point-max))
  302. X            (insert (concat "--" boundary "\n"))
  303. X            (insert "Content-type: text/richtext\n")
  304. X            (insert "Content-Transfer-Encoding: quoted-printable\n\n")
  305. X            ))
  306. X          (goto-char (point-max))
  307. X          (insert "<signature>")
  308. X          (insert-file-contents signature)
  309. X          (goto-char (point-max))
  310. X          (insert "</signature>\n")))
  311. X        ))
  312. X      ;; Prepare article headers.
  313. X      (save-restriction
  314. X    (goto-char (point-min))
  315. X    (search-forward "\n\n")
  316. X    (narrow-to-region (point-min) (point))
  317. X    (gnus-inews-insert-headers)
  318. X    ;; insert mime headers if needed.
  319. X    (goto-char (point-max))
  320. X    (forward-line -2)
  321. X    (or (gnus-fetch-field "Mime-Version")
  322. X        (insert "Mime-Version: 1.0"\n))
  323. X    (or (gnus-fetch-field "Content-Type")
  324. X        (insert "Content-Type: text/richtext\n"))
  325. X    ;; Save author copy of posted article. The article must be
  326. X    ;;  copied before being posted because `gnus-request-post'
  327. X    ;;  modifies the buffer.
  328. X    (let ((case-fold-search t))
  329. X      ;; Find and handle any FCC fields.
  330. X      (goto-char (point-min))
  331. X      (if (re-search-forward "^FCC:" nil t)
  332. X          (gnus-inews-do-fcc))))
  333. X      (widen)
  334. X      ;; Run final inews hooks.
  335. X      (run-hooks 'gnus-Inews-article-hook)
  336. X      ;; Post an article to NNTP server.
  337. X      ;; Return NIL if post failed.
  338. X      (prog1
  339. X      (gnus-request-post)
  340. X    (kill-buffer (current-buffer)))
  341. X      )))
  342. SHAR_EOF
  343. chmod 0664 gnus-mime.el ||
  344. echo 'restore of gnus-mime.el failed'
  345. Wc_c="`wc -c < 'gnus-mime.el'`"
  346. test 9416 -eq "$Wc_c" ||
  347.     echo 'gnus-mime.el: original size 9416, current size' "$Wc_c"
  348. fi
  349. exit 0
  350.  
  351.