gnus-uu.el 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145
  1. ;;; gnus-uu.el --- extract (uu)encoded files in Gnus
  2. ;; Copyright (C) 1985-1987, 1993-1998, 2000-2015 Free Software
  3. ;; Foundation, Inc.
  4. ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
  5. ;; Created: 2 Oct 1993
  6. ;; Keyword: news
  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. ;;; Code:
  20. (eval-when-compile (require 'cl))
  21. (require 'gnus)
  22. (require 'gnus-art)
  23. (require 'message)
  24. (require 'gnus-msg)
  25. (require 'mm-decode)
  26. (require 'yenc)
  27. (defgroup gnus-extract nil
  28. "Extracting encoded files."
  29. :prefix "gnus-uu-"
  30. :group 'gnus)
  31. (defgroup gnus-extract-view nil
  32. "Viewing extracted files."
  33. :group 'gnus-extract)
  34. (defgroup gnus-extract-archive nil
  35. "Extracting encoded archives."
  36. :group 'gnus-extract)
  37. (defgroup gnus-extract-post nil
  38. "Extracting encoded archives."
  39. :prefix "gnus-uu-post"
  40. :group 'gnus-extract)
  41. ;; Default viewing action rules
  42. (defcustom gnus-uu-default-view-rules
  43. '(("\\.te?xt$\\|\\.doc$\\|read.*me\\|\\.c?$\\|\\.h$\\|\\.bat$\\|\\.asm$\\|makefile" "cat %s | sed 's/\r$//'")
  44. ("\\.pas$" "cat %s | sed 's/\r$//'")
  45. ("\\.[1-9]$" "groff -mandoc -Tascii %s | sed s/\b.//g")
  46. ("\\.\\(jpe?g\\|gif\\|tiff?\\|p[pgb]m\\|xwd\\|xbm\\|pcx\\)$" "display")
  47. ("\\.tga$" "tgatoppm %s | ee -")
  48. ("\\.\\(wav\\|aiff\\|hcom\\|u[blw]\\|s[bfw]\\|voc\\|smp\\)$"
  49. "sox -v .5 %s -t .au -u - > /dev/audio")
  50. ("\\.au$" "cat %s > /dev/audio")
  51. ("\\.midi?$" "playmidi -f")
  52. ("\\.mod$" "str32")
  53. ("\\.ps$" "ghostview")
  54. ("\\.dvi$" "xdvi")
  55. ("\\.html$" "xmosaic")
  56. ("\\.mpe?g$" "mpeg_play")
  57. ("\\.\\(flc\\|fli\\|rle\\|iff\\|pfx\\|avi\\|sme\\|rpza\\|dl\\|qt\\|rsrc\\|mov\\)$" "xanim")
  58. ("\\.\\(tar\\|arj\\|zip\\|zoo\\|arc\\|gz\\|Z\\|lzh\\|ar\\|lha\\)$"
  59. "gnus-uu-archive"))
  60. "*Default actions to be taken when the user asks to view a file.
  61. To change the behavior, you can either edit this variable or set
  62. `gnus-uu-user-view-rules' to something useful.
  63. For example:
  64. To make gnus-uu use `xli' to display JPEG and GIF files, put the
  65. following in your .emacs file:
  66. (setq gnus-uu-user-view-rules \\='((\"jpg$\\\\|gif$\" \"xli\")))
  67. Both these variables are lists of lists with two string elements. The
  68. first string is a regular expression. If the file name matches this
  69. regular expression, the command in the second string is executed with
  70. the file as an argument.
  71. If the command string contains \"%s\", the file name will be inserted
  72. at that point in the command string. If there's no \"%s\" in the
  73. command string, the file name will be appended to the command string
  74. before executing.
  75. There are several user variables to tailor the behavior of gnus-uu to
  76. your needs. First we have `gnus-uu-user-view-rules', which is the
  77. variable gnus-uu first consults when trying to decide how to view a
  78. file. If this variable contains no matches, gnus-uu examines the
  79. default rule variable provided in this package. If gnus-uu finds no
  80. match here, it uses `gnus-uu-user-view-rules-end' to try to make a
  81. match."
  82. :group 'gnus-extract-view
  83. :type '(repeat (group regexp (string :tag "Command"))))
  84. (defcustom gnus-uu-user-view-rules nil
  85. "What actions are to be taken to view a file.
  86. See the documentation on the `gnus-uu-default-view-rules' variable for
  87. details."
  88. :group 'gnus-extract-view
  89. :type '(repeat (group regexp (string :tag "Command"))))
  90. (defcustom gnus-uu-user-view-rules-end
  91. '(("" "file"))
  92. "*What actions are to be taken if no rule matched the file name.
  93. See the documentation on the `gnus-uu-default-view-rules' variable for
  94. details."
  95. :group 'gnus-extract-view
  96. :type '(repeat (group regexp (string :tag "Command"))))
  97. ;; Default unpacking commands
  98. (defcustom gnus-uu-default-archive-rules
  99. '(("\\.tar$" "tar xf")
  100. ("\\.zip$" "unzip -o")
  101. ("\\.ar$" "ar x")
  102. ("\\.arj$" "unarj x")
  103. ("\\.zoo$" "zoo -e")
  104. ("\\.\\(lzh\\|lha\\)$" "lha x")
  105. ("\\.Z$" "uncompress")
  106. ("\\.gz$" "gunzip")
  107. ("\\.arc$" "arc -x"))
  108. "*See `gnus-uu-user-archive-rules'."
  109. :group 'gnus-extract-archive
  110. :type '(repeat (group regexp (string :tag "Command"))))
  111. (defvar gnus-uu-destructive-archivers
  112. (list "uncompress" "gunzip"))
  113. (defcustom gnus-uu-user-archive-rules nil
  114. "A list that can be set to override the default archive unpacking commands.
  115. To use, for instance, `untar' to unpack tar files and `zip -x' to
  116. unpack zip files, say the following:
  117. (setq gnus-uu-user-archive-rules
  118. \\='((\"\\\\.tar$\" \"untar\")
  119. (\"\\\\.zip$\" \"zip -x\")))"
  120. :group 'gnus-extract-archive
  121. :type '(repeat (group regexp (string :tag "Command"))))
  122. (defcustom gnus-uu-ignore-files-by-name nil
  123. "*A regular expression saying what files should not be viewed based on name.
  124. If, for instance, you want gnus-uu to ignore all .au and .wav files,
  125. you could say something like
  126. (setq gnus-uu-ignore-files-by-name \"\\\\.au$\\\\|\\\\.wav$\")
  127. Note that this variable can be used in conjunction with the
  128. `gnus-uu-ignore-files-by-type' variable."
  129. :group 'gnus-extract
  130. :type '(choice (const :tag "off" nil)
  131. (regexp :format "%v")))
  132. (defcustom gnus-uu-ignore-files-by-type nil
  133. "*A regular expression saying what files that shouldn't be viewed, based on MIME file type.
  134. If, for instance, you want gnus-uu to ignore all audio files and all mpegs,
  135. you could say something like
  136. (setq gnus-uu-ignore-files-by-type \"audio/\\\\|video/mpeg\")
  137. Note that this variable can be used in conjunction with the
  138. `gnus-uu-ignore-files-by-name' variable."
  139. :group 'gnus-extract
  140. :type '(choice (const :tag "off" nil)
  141. (regexp :format "%v")))
  142. ;; Pseudo-MIME support
  143. (defconst gnus-uu-ext-to-mime-list
  144. '(("\\.gif$" "image/gif")
  145. ("\\.jpe?g$" "image/jpeg")
  146. ("\\.tiff?$" "image/tiff")
  147. ("\\.xwd$" "image/xwd")
  148. ("\\.pbm$" "image/pbm")
  149. ("\\.pgm$" "image/pgm")
  150. ("\\.ppm$" "image/ppm")
  151. ("\\.xbm$" "image/xbm")
  152. ("\\.pcx$" "image/pcx")
  153. ("\\.tga$" "image/tga")
  154. ("\\.ps$" "image/postscript")
  155. ("\\.fli$" "video/fli")
  156. ("\\.wav$" "audio/wav")
  157. ("\\.aiff$" "audio/aiff")
  158. ("\\.hcom$" "audio/hcom")
  159. ("\\.voc$" "audio/voc")
  160. ("\\.smp$" "audio/smp")
  161. ("\\.mod$" "audio/mod")
  162. ("\\.dvi$" "image/dvi")
  163. ("\\.mpe?g$" "video/mpeg")
  164. ("\\.au$" "audio/basic")
  165. ("\\.\\(te?xt\\|doc\\|c\\|h\\)$" "text/plain")
  166. ("\\.\\(c\\|h\\)$" "text/source")
  167. ("read.*me" "text/plain")
  168. ("\\.html$" "text/html")
  169. ("\\.bat$" "text/bat")
  170. ("\\.[1-6]$" "text/man")
  171. ("\\.flc$" "video/flc")
  172. ("\\.rle$" "video/rle")
  173. ("\\.pfx$" "video/pfx")
  174. ("\\.avi$" "video/avi")
  175. ("\\.sme$" "video/sme")
  176. ("\\.rpza$" "video/prza")
  177. ("\\.dl$" "video/dl")
  178. ("\\.qt$" "video/qt")
  179. ("\\.rsrc$" "video/rsrc")
  180. ("\\..*$" "unknown/unknown")))
  181. ;; Various variables users may set
  182. (defcustom gnus-uu-tmp-dir
  183. (cond ((fboundp 'temp-directory) (temp-directory))
  184. ((boundp 'temporary-file-directory) temporary-file-directory)
  185. ("/tmp/"))
  186. "*Variable saying where gnus-uu is to do its work.
  187. Default is \"/tmp/\"."
  188. :group 'gnus-extract
  189. :type 'directory)
  190. (defcustom gnus-uu-do-not-unpack-archives nil
  191. "*Non-nil means that gnus-uu won't peek inside archives looking for files to display.
  192. Default is nil."
  193. :group 'gnus-extract-archive
  194. :type 'boolean)
  195. (defcustom gnus-uu-ignore-default-view-rules nil
  196. "*Non-nil means that gnus-uu will ignore the default viewing rules.
  197. Only the user viewing rules will be consulted. Default is nil."
  198. :group 'gnus-extract-view
  199. :type 'boolean)
  200. (defcustom gnus-uu-grabbed-file-functions nil
  201. "Functions run on each file after successful decoding.
  202. They will be called with the name of the file as the argument.
  203. Likely functions you can use in this list are `gnus-uu-grab-view'
  204. and `gnus-uu-grab-move'."
  205. :group 'gnus-extract
  206. :options '(gnus-uu-grab-view gnus-uu-grab-move)
  207. :type 'hook)
  208. (defcustom gnus-uu-ignore-default-archive-rules nil
  209. "*Non-nil means that gnus-uu will ignore the default archive unpacking commands.
  210. Only the user unpacking commands will be consulted. Default is nil."
  211. :group 'gnus-extract-archive
  212. :type 'boolean)
  213. (defcustom gnus-uu-kill-carriage-return t
  214. "*Non-nil means that gnus-uu will strip all carriage returns from articles.
  215. Default is t."
  216. :group 'gnus-extract
  217. :type 'boolean)
  218. (defcustom gnus-uu-view-with-metamail nil
  219. "*Non-nil means that files will be viewed with metamail.
  220. The gnus-uu viewing functions will be ignored and gnus-uu will try
  221. to guess at a content-type based on file name suffixes. Default
  222. it nil."
  223. :group 'gnus-extract
  224. :type 'boolean)
  225. (defcustom gnus-uu-unmark-articles-not-decoded nil
  226. "*Non-nil means that gnus-uu will mark articles that were unsuccessfully decoded as unread.
  227. Default is nil."
  228. :group 'gnus-extract
  229. :type 'boolean)
  230. (defcustom gnus-uu-correct-stripped-uucode nil
  231. "*Non-nil means that gnus-uu will *try* to fix uuencoded files that have had trailing spaces deleted.
  232. Default is nil."
  233. :group 'gnus-extract
  234. :type 'boolean)
  235. (defcustom gnus-uu-save-in-digest nil
  236. "*Non-nil means that gnus-uu, when asked to save without decoding, will save in digests.
  237. If this variable is nil, gnus-uu will just save everything in a
  238. file without any embellishments. The digesting almost conforms to RFC1153 -
  239. no easy way to specify any meaningful volume and issue numbers were found,
  240. so I simply dropped them."
  241. :group 'gnus-extract
  242. :type 'boolean)
  243. (defcustom gnus-uu-pre-uudecode-hook nil
  244. "Hook run before sending a message to uudecode."
  245. :group 'gnus-extract
  246. :type 'hook)
  247. (defcustom gnus-uu-digest-headers
  248. '("^Date:" "^From:" "^To:" "^Cc:" "^Subject:" "^Message-ID:" "^Keywords:"
  249. "^Summary:" "^References:" "^Content-Type:" "^Content-Transfer-Encoding:"
  250. "^MIME-Version:" "^Content-Disposition:" "^Content-Description:"
  251. "^Content-ID:")
  252. "*List of regexps to match headers included in digested messages.
  253. The headers will be included in the sequence they are matched. If nil
  254. include all headers."
  255. :group 'gnus-extract
  256. :type '(repeat regexp))
  257. (defcustom gnus-uu-save-separate-articles nil
  258. "*Non-nil means that gnus-uu will save articles in separate files."
  259. :group 'gnus-extract
  260. :type 'boolean)
  261. (defcustom gnus-uu-be-dangerous 'ask
  262. "*Specifies what to do if unusual situations arise during decoding.
  263. If nil, be as conservative as possible. If t, ignore things that
  264. didn't work, and overwrite existing files. Otherwise, ask each time."
  265. :group 'gnus-extract
  266. :type '(choice (const :tag "conservative" nil)
  267. (const :tag "ask" ask)
  268. (const :tag "liberal" t)))
  269. ;; Internal variables
  270. (defvar gnus-uu-saved-article-name nil)
  271. (defvar gnus-uu-begin-string "^begin[ \t]+0?[0-7][0-7][0-7][ \t]+\\(.*\\)$")
  272. (defvar gnus-uu-end-string "^end[ \t]*$")
  273. (defvar gnus-uu-body-line "^M")
  274. (let ((i 61))
  275. (while (> (setq i (1- i)) 0)
  276. (setq gnus-uu-body-line (concat gnus-uu-body-line "[^a-z]")))
  277. (setq gnus-uu-body-line (concat gnus-uu-body-line ".?$")))
  278. ;"^M.............................................................?$"
  279. (defvar gnus-uu-shar-begin-string "^#! */bin/sh")
  280. (defvar gnus-uu-shar-name-marker
  281. "begin 0?[0-7][0-7][0-7][ \t]+\\(\\(\\w\\|[.\\:]\\)*\\b\\)")
  282. (defvar gnus-uu-postscript-begin-string "^%!PS-")
  283. (defvar gnus-uu-postscript-end-string "^%%EOF$")
  284. (defvar gnus-uu-file-name nil)
  285. (defvar gnus-uu-uudecode-process nil)
  286. (defvar gnus-uu-binhex-article-name nil)
  287. (defvar gnus-uu-yenc-article-name nil)
  288. (defvar gnus-uu-work-dir nil)
  289. (defvar gnus-uu-output-buffer-name " *Gnus UU Output*")
  290. (defvar gnus-uu-default-dir gnus-article-save-directory)
  291. (defvar gnus-uu-digest-from-subject nil)
  292. (defvar gnus-uu-digest-buffer nil)
  293. ;; Commands.
  294. (defun gnus-uu-decode-uu (&optional n)
  295. "Uudecodes the current article."
  296. (interactive "P")
  297. (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n))
  298. (defun gnus-uu-decode-uu-and-save (n dir)
  299. "Decodes and saves the resulting file."
  300. (interactive
  301. (list current-prefix-arg
  302. (file-name-as-directory
  303. (read-directory-name "Uudecode and save in dir: "
  304. gnus-uu-default-dir
  305. gnus-uu-default-dir t))))
  306. (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n dir nil nil t))
  307. (defun gnus-uu-decode-unshar (&optional n)
  308. "Unshars the current article."
  309. (interactive "P")
  310. (gnus-uu-decode-with-method 'gnus-uu-unshar-article n nil nil 'scan t))
  311. (defun gnus-uu-decode-unshar-and-save (n dir)
  312. "Unshars and saves the current article."
  313. (interactive
  314. (list current-prefix-arg
  315. (file-name-as-directory
  316. (read-directory-name "Unshar and save in dir: "
  317. gnus-uu-default-dir
  318. gnus-uu-default-dir t))))
  319. (gnus-uu-decode-with-method 'gnus-uu-unshar-article n dir nil 'scan t))
  320. (defun gnus-uu-decode-save (n file)
  321. "Saves the current article."
  322. (interactive
  323. (list current-prefix-arg
  324. (if gnus-uu-save-separate-articles
  325. (read-directory-name
  326. "Save articles in dir: " gnus-uu-default-dir gnus-uu-default-dir)
  327. (read-file-name
  328. "Save article in file: " gnus-uu-default-dir gnus-uu-default-dir))))
  329. (setq gnus-uu-saved-article-name file)
  330. (gnus-uu-decode-with-method 'gnus-uu-save-article n nil t))
  331. (defun gnus-uu-decode-binhex (n dir)
  332. "Unbinhexes the current article."
  333. (interactive
  334. (list current-prefix-arg
  335. (file-name-as-directory
  336. (read-directory-name "Unbinhex and save in dir: "
  337. gnus-uu-default-dir
  338. gnus-uu-default-dir))))
  339. (gnus-uu-initialize)
  340. (setq gnus-uu-binhex-article-name
  341. (mm-make-temp-file (expand-file-name "binhex" gnus-uu-work-dir)))
  342. (gnus-uu-decode-with-method 'gnus-uu-binhex-article n dir))
  343. (defun gnus-uu-decode-yenc (n dir)
  344. "Decode the yEnc-encoded current article."
  345. (interactive
  346. (list current-prefix-arg
  347. (file-name-as-directory
  348. (read-directory-name "yEnc decode and save in dir: "
  349. gnus-uu-default-dir
  350. gnus-uu-default-dir))))
  351. (setq gnus-uu-yenc-article-name nil)
  352. (gnus-uu-decode-with-method 'gnus-uu-yenc-article n dir nil t))
  353. (defun gnus-uu-decode-uu-view (&optional n)
  354. "Uudecodes and views the current article."
  355. (interactive "P")
  356. (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
  357. (gnus-uu-decode-uu n)))
  358. (defun gnus-uu-decode-uu-and-save-view (n dir)
  359. "Decodes, views and saves the resulting file."
  360. (interactive
  361. (list current-prefix-arg
  362. (read-file-name "Uudecode, view and save in dir: "
  363. gnus-uu-default-dir
  364. gnus-uu-default-dir t)))
  365. (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
  366. (gnus-uu-decode-uu-and-save n dir)))
  367. (defun gnus-uu-decode-unshar-view (&optional n)
  368. "Unshars and views the current article."
  369. (interactive "P")
  370. (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
  371. (gnus-uu-decode-unshar n)))
  372. (defun gnus-uu-decode-unshar-and-save-view (n dir)
  373. "Unshars and saves the current article."
  374. (interactive
  375. (list current-prefix-arg
  376. (read-file-name "Unshar, view and save in dir: "
  377. gnus-uu-default-dir
  378. gnus-uu-default-dir t)))
  379. (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
  380. (gnus-uu-decode-unshar-and-save n dir)))
  381. (defun gnus-uu-decode-save-view (n file)
  382. "Saves and views the current article."
  383. (interactive
  384. (list current-prefix-arg
  385. (if gnus-uu-save-separate-articles
  386. (read-directory-name "Save articles in dir: "
  387. gnus-uu-default-dir gnus-uu-default-dir)
  388. (read-file-name "Save articles in file: "
  389. gnus-uu-default-dir gnus-uu-default-dir))))
  390. (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
  391. (gnus-uu-decode-save n file)))
  392. (defun gnus-uu-decode-binhex-view (n file)
  393. "Unbinhexes and views the current article."
  394. (interactive
  395. (list current-prefix-arg
  396. (read-file-name "Unbinhex, view and save in dir: "
  397. gnus-uu-default-dir gnus-uu-default-dir)))
  398. (gnus-uu-initialize)
  399. (setq gnus-uu-binhex-article-name
  400. (mm-make-temp-file (expand-file-name "binhex" gnus-uu-work-dir)))
  401. (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
  402. (gnus-uu-decode-binhex n file)))
  403. ;; Digest and forward articles
  404. (defun gnus-uu-digest-mail-forward (&optional n post)
  405. "Digests and forwards all articles in this series."
  406. (interactive "P")
  407. (gnus-uu-initialize)
  408. (let ((gnus-uu-save-in-digest t)
  409. (file (mm-make-temp-file (nnheader-concat gnus-uu-work-dir "forward")))
  410. (message-forward-as-mime message-forward-as-mime)
  411. (mail-parse-charset gnus-newsgroup-charset)
  412. (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
  413. gnus-uu-digest-buffer subject from)
  414. (if (and n (not (numberp n)))
  415. (setq message-forward-as-mime (not message-forward-as-mime)
  416. n nil))
  417. (let ((gnus-article-reply (gnus-summary-work-articles n)))
  418. (when (and (not n)
  419. (= (length gnus-article-reply) 1))
  420. ;; The case where neither a number of articles nor a region is
  421. ;; specified.
  422. (gnus-summary-top-thread)
  423. (setq gnus-article-reply (nreverse (gnus-uu-find-articles-matching))))
  424. (gnus-setup-message 'forward
  425. (setq gnus-uu-digest-from-subject nil)
  426. (setq gnus-uu-digest-buffer
  427. (gnus-get-buffer-create " *gnus-uu-forward*"))
  428. ;; Specify articles to be forwarded. Note that they should be
  429. ;; reversed; see `gnus-uu-get-list-of-articles'.
  430. (let ((gnus-newsgroup-processable (reverse gnus-article-reply)))
  431. (gnus-uu-decode-save n file)
  432. (setq gnus-article-reply gnus-newsgroup-processable))
  433. ;; Restore the value of `gnus-newsgroup-processable' to which
  434. ;; it should be set when it is not `let'-bound.
  435. (setq gnus-newsgroup-processable (reverse gnus-article-reply))
  436. (switch-to-buffer gnus-uu-digest-buffer)
  437. (let ((fs gnus-uu-digest-from-subject))
  438. (when fs
  439. (setq from (caar fs)
  440. subject (gnus-simplify-subject-fuzzy (cdar fs))
  441. fs (cdr fs))
  442. (while (and fs (or from subject))
  443. (when from
  444. (unless (string= from (caar fs))
  445. (setq from nil)))
  446. (when subject
  447. (unless (string= (gnus-simplify-subject-fuzzy (cdar fs))
  448. subject)
  449. (setq subject nil)))
  450. (setq fs (cdr fs))))
  451. (unless subject
  452. (setq subject "Digested Articles"))
  453. (unless from
  454. (setq from
  455. (if (gnus-news-group-p gnus-newsgroup-name)
  456. gnus-newsgroup-name
  457. "Various"))))
  458. (goto-char (point-min))
  459. (when (re-search-forward "^Subject: ")
  460. (delete-region (point) (point-at-eol))
  461. (insert subject))
  462. (goto-char (point-min))
  463. (when (re-search-forward "^From:")
  464. (delete-region (point) (point-at-eol))
  465. (insert " " from))
  466. (let ((message-forward-decoded-p t))
  467. (message-forward post t))))
  468. (setq gnus-uu-digest-from-subject nil)))
  469. (defun gnus-uu-digest-post-forward (&optional n)
  470. "Digest and forward to a newsgroup."
  471. (interactive "P")
  472. (gnus-uu-digest-mail-forward n t))
  473. ;; Process marking.
  474. (defun gnus-message-process-mark (unmarkp new-marked)
  475. (let ((old (- (length gnus-newsgroup-processable) (length new-marked))))
  476. (gnus-message 6 "%d mark%s %s%s"
  477. (length new-marked)
  478. (if (= (length new-marked) 1) "" "s")
  479. (if unmarkp "removed" "added")
  480. (cond
  481. ((and (zerop old)
  482. (not unmarkp))
  483. "")
  484. (unmarkp
  485. (format ", %d remain marked"
  486. (length gnus-newsgroup-processable)))
  487. (t
  488. (format ", %d already marked" old))))))
  489. (defun gnus-new-processable (unmarkp articles)
  490. (if unmarkp
  491. (gnus-intersection gnus-newsgroup-processable articles)
  492. (gnus-set-difference articles gnus-newsgroup-processable)))
  493. (defun gnus-uu-mark-by-regexp (regexp &optional unmark)
  494. "Set the process mark on articles whose subjects match REGEXP.
  495. When called interactively, prompt for REGEXP.
  496. Optional UNMARK non-nil means unmark instead of mark."
  497. (interactive "sMark (regexp): \nP")
  498. (save-excursion
  499. (let* ((articles (gnus-uu-find-articles-matching regexp))
  500. (new-marked (gnus-new-processable unmark articles)))
  501. (while articles
  502. (if unmark
  503. (gnus-summary-remove-process-mark (pop articles))
  504. (gnus-summary-set-process-mark (pop articles))))
  505. (gnus-message-process-mark unmark new-marked)))
  506. (gnus-summary-position-point))
  507. (defun gnus-uu-unmark-by-regexp (regexp)
  508. "Remove the process mark from articles whose subjects match REGEXP.
  509. When called interactively, prompt for REGEXP."
  510. (interactive "sUnmark (regexp): ")
  511. (gnus-uu-mark-by-regexp regexp t))
  512. (defun gnus-uu-mark-series (&optional silent)
  513. "Mark the current series with the process mark."
  514. (interactive)
  515. (let* ((articles (gnus-uu-find-articles-matching))
  516. (l (length articles)))
  517. (while articles
  518. (gnus-summary-set-process-mark (car articles))
  519. (setq articles (cdr articles)))
  520. (unless silent
  521. (gnus-message 6 "Marked %d articles" l))
  522. (gnus-summary-position-point)
  523. l))
  524. (defun gnus-uu-mark-region (beg end &optional unmark)
  525. "Set the process mark on all articles between point and mark."
  526. (interactive "r")
  527. (save-excursion
  528. (goto-char beg)
  529. (while (< (point) end)
  530. (if unmark
  531. (gnus-summary-remove-process-mark (gnus-summary-article-number))
  532. (gnus-summary-set-process-mark (gnus-summary-article-number)))
  533. (forward-line 1)))
  534. (gnus-summary-position-point))
  535. (defun gnus-uu-unmark-region (beg end)
  536. "Remove the process mark from all articles between point and mark."
  537. (interactive "r")
  538. (gnus-uu-mark-region beg end t))
  539. (defun gnus-uu-mark-buffer ()
  540. "Set the process mark on all articles in the buffer."
  541. (interactive)
  542. (gnus-uu-mark-region (point-min) (point-max)))
  543. (defun gnus-uu-unmark-buffer ()
  544. "Remove the process mark on all articles in the buffer."
  545. (interactive)
  546. (gnus-uu-mark-region (point-min) (point-max) t))
  547. (defun gnus-uu-mark-thread ()
  548. "Marks all articles downwards in this thread."
  549. (interactive)
  550. (gnus-save-hidden-threads
  551. (let ((level (gnus-summary-thread-level)))
  552. (while (and (gnus-summary-set-process-mark
  553. (gnus-summary-article-number))
  554. (zerop (forward-line 1))
  555. (> (gnus-summary-thread-level) level)))))
  556. (gnus-summary-position-point))
  557. (defun gnus-uu-unmark-thread ()
  558. "Unmarks all articles downwards in this thread."
  559. (interactive)
  560. (let ((level (gnus-summary-thread-level)))
  561. (while (and (gnus-summary-remove-process-mark
  562. (gnus-summary-article-number))
  563. (zerop (forward-line 1))
  564. (> (gnus-summary-thread-level) level))))
  565. (gnus-summary-position-point))
  566. (defun gnus-uu-invert-processable ()
  567. "Invert the list of process-marked articles."
  568. (interactive)
  569. (let ((data gnus-newsgroup-data)
  570. number)
  571. (save-excursion
  572. (while data
  573. (if (memq (setq number (gnus-data-number (pop data)))
  574. gnus-newsgroup-processable)
  575. (gnus-summary-remove-process-mark number)
  576. (gnus-summary-set-process-mark number)))))
  577. (gnus-summary-position-point))
  578. (defun gnus-uu-mark-over (&optional score)
  579. "Mark all articles with a score over SCORE (the prefix)."
  580. (interactive "P")
  581. (let ((score (or score gnus-summary-default-score 0))
  582. (data gnus-newsgroup-data))
  583. (save-excursion
  584. (while data
  585. (when (> (or (cdr (assq (gnus-data-number (car data))
  586. gnus-newsgroup-scored))
  587. gnus-summary-default-score 0)
  588. score)
  589. (gnus-summary-set-process-mark (caar data)))
  590. (setq data (cdr data))))
  591. (gnus-summary-position-point)))
  592. (defun gnus-uu-mark-sparse ()
  593. "Mark all series that have some articles marked."
  594. (interactive)
  595. (let ((marked (nreverse gnus-newsgroup-processable))
  596. subject articles total headers)
  597. (unless marked
  598. (error "No articles marked with the process mark"))
  599. (setq gnus-newsgroup-processable nil)
  600. (save-excursion
  601. (while marked
  602. (and (vectorp (setq headers
  603. (gnus-summary-article-header (car marked))))
  604. (setq subject (mail-header-subject headers)
  605. articles (gnus-uu-find-articles-matching
  606. (gnus-uu-reginize-string subject))
  607. total (nconc total articles)))
  608. (while articles
  609. (gnus-summary-set-process-mark (car articles))
  610. (setcdr marked (delq (car articles) (cdr marked)))
  611. (setq articles (cdr articles)))
  612. (setq marked (cdr marked)))
  613. (setq gnus-newsgroup-processable (nreverse total)))
  614. (gnus-summary-position-point)))
  615. (defun gnus-uu-mark-all ()
  616. "Mark all articles in \"series\" order."
  617. (interactive)
  618. (setq gnus-newsgroup-processable nil)
  619. (save-excursion
  620. (let ((data gnus-newsgroup-data)
  621. (count 0)
  622. number)
  623. (while data
  624. (when (and (not (memq (setq number (gnus-data-number (car data)))
  625. gnus-newsgroup-processable))
  626. (vectorp (gnus-data-header (car data))))
  627. (gnus-summary-goto-subject number)
  628. (setq count (+ count (gnus-uu-mark-series t))))
  629. (setq data (cdr data)))
  630. (gnus-message 6 "Marked %d articles" count)))
  631. (gnus-summary-position-point))
  632. ;; All PostScript functions written by Erik Selberg <speed@cs.washington.edu>.
  633. (defun gnus-uu-decode-postscript (&optional n)
  634. "Gets PostScript of the current article."
  635. (interactive "P")
  636. (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article n))
  637. (defun gnus-uu-decode-postscript-view (&optional n)
  638. "Gets and views the current article."
  639. (interactive "P")
  640. (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
  641. (gnus-uu-decode-postscript n)))
  642. (defun gnus-uu-decode-postscript-and-save (n dir)
  643. "Extracts PostScript and saves the current article."
  644. (interactive
  645. (list current-prefix-arg
  646. (file-name-as-directory
  647. (read-directory-name "Save in dir: "
  648. gnus-uu-default-dir
  649. gnus-uu-default-dir t))))
  650. (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article
  651. n dir nil nil t))
  652. (defun gnus-uu-decode-postscript-and-save-view (n dir)
  653. "Decodes, views and saves the resulting file."
  654. (interactive
  655. (list current-prefix-arg
  656. (read-file-name "Where do you want to save the file(s)? "
  657. gnus-uu-default-dir
  658. gnus-uu-default-dir t)))
  659. (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
  660. (gnus-uu-decode-postscript-and-save n dir)))
  661. ;; Internal functions.
  662. (defun gnus-uu-decode-with-method (method n &optional save not-insert
  663. scan cdir)
  664. (gnus-uu-initialize scan)
  665. (when save
  666. (setq gnus-uu-default-dir save))
  667. ;; Create the directory we save to.
  668. (when (and scan cdir save
  669. (not (file-exists-p save)))
  670. (make-directory save t))
  671. (let ((articles (gnus-uu-get-list-of-articles n))
  672. files)
  673. (setq files (gnus-uu-grab-articles articles method t))
  674. (let ((gnus-current-article (car articles)))
  675. (when scan
  676. (setq files (gnus-uu-scan-directory gnus-uu-work-dir))))
  677. (when save
  678. (gnus-uu-save-files files save))
  679. (when (eq gnus-uu-do-not-unpack-archives nil)
  680. (setq files (gnus-uu-unpack-files files)))
  681. (setq files (nreverse (gnus-uu-get-actions files)))
  682. (or not-insert (not gnus-insert-pseudo-articles)
  683. (gnus-summary-insert-pseudos files save))))
  684. (defun gnus-uu-scan-directory (dir &optional rec)
  685. "Return a list of all files under DIR."
  686. (let ((files (directory-files dir t))
  687. out file)
  688. (while (setq file (pop files))
  689. (unless (member (file-name-nondirectory file) '("." ".."))
  690. (push (list (cons 'name file)
  691. (cons 'article gnus-current-article))
  692. out)
  693. (when (file-directory-p file)
  694. (setq out (nconc (gnus-uu-scan-directory file t) out)))))
  695. (if rec
  696. out
  697. (nreverse out))))
  698. (defun gnus-uu-save-files (files dir)
  699. "Save FILES in DIR."
  700. (let ((len (length files))
  701. (reg (concat "^" (regexp-quote gnus-uu-work-dir)))
  702. to-file file fromdir)
  703. (while (setq file (cdr (assq 'name (pop files))))
  704. (when (file-exists-p file)
  705. (string-match reg file)
  706. (setq fromdir (substring file (match-end 0)))
  707. (if (file-directory-p file)
  708. (gnus-make-directory (concat dir fromdir))
  709. (setq to-file (concat dir fromdir))
  710. (when (or (not (file-exists-p to-file))
  711. (eq gnus-uu-be-dangerous t)
  712. (and gnus-uu-be-dangerous
  713. (gnus-y-or-n-p (format "%s exists; overwrite? "
  714. to-file))))
  715. (copy-file file to-file t t)))))
  716. (gnus-message 5 "Saved %d file%s" len (if (= len 1) "" "s"))))
  717. ;; Functions for saving and possibly digesting articles without
  718. ;; any decoding.
  719. ;; Function called by gnus-uu-grab-articles to treat each article.
  720. (defun gnus-uu-save-article (buffer in-state)
  721. (cond
  722. (gnus-uu-save-separate-articles
  723. (with-current-buffer buffer
  724. (let ((coding-system-for-write mm-text-coding-system))
  725. (gnus-write-buffer
  726. (concat gnus-uu-saved-article-name gnus-current-article)))
  727. (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin))
  728. ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name
  729. 'begin 'end))
  730. ((eq in-state 'last) (list 'end))
  731. (t (list 'middle)))))
  732. ((not gnus-uu-save-in-digest)
  733. (with-current-buffer buffer
  734. (write-region (point-min) (point-max) gnus-uu-saved-article-name t)
  735. (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin))
  736. ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name
  737. 'begin 'end))
  738. ((eq in-state 'last) (list 'end))
  739. (t (list 'middle)))))
  740. (t
  741. (let ((header (gnus-summary-article-header)))
  742. (push (cons (mail-header-from header)
  743. (mail-header-subject header))
  744. gnus-uu-digest-from-subject))
  745. (let ((name (file-name-nondirectory gnus-uu-saved-article-name))
  746. beg subj headers headline sorthead body end-string state)
  747. (if (or (eq in-state 'first)
  748. (eq in-state 'first-and-last))
  749. (progn
  750. (setq state (list 'begin))
  751. (with-current-buffer (gnus-get-buffer-create "*gnus-uu-body*")
  752. (erase-buffer))
  753. (with-current-buffer (gnus-get-buffer-create "*gnus-uu-pre*")
  754. (erase-buffer)
  755. (insert (format
  756. "Date: %s\nFrom: %s\nSubject: %s Digest\n\n"
  757. (message-make-date) name name))
  758. (when (and message-forward-as-mime gnus-uu-digest-buffer)
  759. (insert
  760. "<#mml type=message/rfc822>\nSubject: Topics\n\n<#/mml>\n")
  761. (forward-line -1))
  762. (insert "Topics:\n")))
  763. (when (not (eq in-state 'end))
  764. (setq state (list 'middle))))
  765. (with-current-buffer "*gnus-uu-body*"
  766. (goto-char (setq beg (point-max)))
  767. (with-current-buffer buffer
  768. (save-restriction
  769. (let ((inhibit-read-only t))
  770. (set-text-properties (point-min) (point-max) nil)
  771. ;; These two are necessary for XEmacs 19.12 fascism.
  772. (put-text-property (point-min) (point-max) 'invisible nil)
  773. (put-text-property (point-min) (point-max) 'intangible nil))
  774. (when (and message-forward-as-mime
  775. message-forward-show-mml
  776. gnus-uu-digest-buffer)
  777. (mm-enable-multibyte)
  778. (mime-to-mml))
  779. (goto-char (point-min))
  780. (search-forward "\n\n")
  781. (unless (and message-forward-as-mime gnus-uu-digest-buffer)
  782. ;; Quote all 30-dash lines.
  783. (save-excursion
  784. (while (re-search-forward "^-" nil t)
  785. (beginning-of-line)
  786. (delete-char 1)
  787. (insert "- "))))
  788. (setq body (buffer-substring (1- (point)) (point-max)))
  789. (narrow-to-region (point-min) (point))
  790. (if (not (setq headers gnus-uu-digest-headers))
  791. (setq sorthead (buffer-string))
  792. (while headers
  793. (setq headline (car headers))
  794. (setq headers (cdr headers))
  795. (goto-char (point-min))
  796. (while (re-search-forward headline nil t)
  797. (setq sorthead
  798. (concat sorthead
  799. (buffer-substring
  800. (match-beginning 0)
  801. (or (and (re-search-forward "^[^ \t]" nil t)
  802. (1- (point)))
  803. (progn (forward-line 1) (point)))))))))))
  804. (if (and message-forward-as-mime gnus-uu-digest-buffer)
  805. (if message-forward-show-mml
  806. (progn
  807. (insert "\n<#mml type=message/rfc822>\n")
  808. (insert sorthead) (goto-char (point-max))
  809. (insert body) (goto-char (point-max))
  810. (insert "\n<#/mml>\n"))
  811. (let ((buf (mml-generate-new-buffer " *mml*")))
  812. (with-current-buffer buf
  813. (insert sorthead)
  814. (goto-char (point-min))
  815. (when (re-search-forward "^Subject: \\(.*\\)$" nil t)
  816. (setq subj (buffer-substring (match-beginning 1)
  817. (match-end 1))))
  818. (goto-char (point-max))
  819. (insert body))
  820. (insert "\n<#part type=message/rfc822"
  821. " buffer=\"" (buffer-name buf) "\">\n")))
  822. (insert sorthead) (goto-char (point-max))
  823. (insert body) (goto-char (point-max))
  824. (insert (concat "\n" (make-string 30 ?-) "\n\n")))
  825. (goto-char beg)
  826. (when (re-search-forward "^Subject: \\(.*\\)$" nil t)
  827. (setq subj (buffer-substring (match-beginning 1) (match-end 1))))
  828. (when subj
  829. (with-current-buffer "*gnus-uu-pre*"
  830. (insert (format " %s\n" subj)))))
  831. (when (or (eq in-state 'last)
  832. (eq in-state 'first-and-last))
  833. (if (and message-forward-as-mime gnus-uu-digest-buffer)
  834. (with-current-buffer gnus-uu-digest-buffer
  835. (erase-buffer)
  836. (insert-buffer-substring "*gnus-uu-pre*")
  837. (goto-char (point-max))
  838. (insert-buffer-substring "*gnus-uu-body*"))
  839. (with-current-buffer "*gnus-uu-pre*"
  840. (insert (format "\n\n%s\n\n" (make-string 70 ?-)))
  841. (if gnus-uu-digest-buffer
  842. (with-current-buffer gnus-uu-digest-buffer
  843. (erase-buffer)
  844. (insert-buffer-substring "*gnus-uu-pre*"))
  845. (let ((coding-system-for-write mm-text-coding-system))
  846. (gnus-write-buffer gnus-uu-saved-article-name))))
  847. (with-current-buffer "*gnus-uu-body*"
  848. (goto-char (point-max))
  849. (insert
  850. (concat (setq end-string (format "End of %s Digest" name))
  851. "\n"))
  852. (insert (concat (make-string (length end-string) ?*) "\n"))
  853. (if gnus-uu-digest-buffer
  854. (with-current-buffer gnus-uu-digest-buffer
  855. (goto-char (point-max))
  856. (insert-buffer-substring "*gnus-uu-body*"))
  857. (let ((coding-system-for-write mm-text-coding-system)
  858. (file-name-coding-system nnmail-pathname-coding-system))
  859. (write-region
  860. (point-min) (point-max) gnus-uu-saved-article-name t)))))
  861. (gnus-kill-buffer "*gnus-uu-pre*")
  862. (gnus-kill-buffer "*gnus-uu-body*")
  863. (push 'end state))
  864. (if (memq 'begin state)
  865. (cons gnus-uu-saved-article-name state)
  866. state)))))
  867. ;; Binhex treatment - not very advanced.
  868. (defvar gnus-uu-binhex-body-line
  869. "^[^:]...............................................................$")
  870. (defvar gnus-uu-binhex-begin-line
  871. "^:...............................................................$")
  872. (defvar gnus-uu-binhex-end-line
  873. ":$")
  874. (defun gnus-uu-binhex-article (buffer in-state)
  875. (let (state start-char)
  876. (with-current-buffer buffer
  877. (widen)
  878. (goto-char (point-min))
  879. (when (not (re-search-forward gnus-uu-binhex-begin-line nil t))
  880. (when (not (re-search-forward gnus-uu-binhex-body-line nil t))
  881. (setq state (list 'wrong-type))))
  882. (if (memq 'wrong-type state)
  883. ()
  884. (beginning-of-line)
  885. (setq start-char (point))
  886. (if (looking-at gnus-uu-binhex-begin-line)
  887. (progn
  888. (setq state (list 'begin))
  889. (write-region (point-min) (point-min)
  890. gnus-uu-binhex-article-name))
  891. (setq state (list 'middle)))
  892. (goto-char (point-max))
  893. (re-search-backward (concat gnus-uu-binhex-body-line "\\|"
  894. gnus-uu-binhex-end-line)
  895. nil t)
  896. (when (looking-at gnus-uu-binhex-end-line)
  897. (setq state (if (memq 'begin state)
  898. (cons 'end state)
  899. (list 'end))))
  900. (beginning-of-line)
  901. (forward-line 1)
  902. (when (file-exists-p gnus-uu-binhex-article-name)
  903. (mm-append-to-file start-char (point) gnus-uu-binhex-article-name))))
  904. (if (memq 'begin state)
  905. (cons gnus-uu-binhex-article-name state)
  906. state)))
  907. ;; yEnc
  908. (defun gnus-uu-yenc-article (buffer in-state)
  909. (with-current-buffer gnus-original-article-buffer
  910. (widen)
  911. (let ((file-name (yenc-extract-filename))
  912. state start-char)
  913. (when (not file-name)
  914. (setq state (list 'wrong-type)))
  915. (if (memq 'wrong-type state)
  916. ()
  917. (when (yenc-first-part-p)
  918. (setq gnus-uu-yenc-article-name
  919. (expand-file-name file-name gnus-uu-work-dir))
  920. (push 'begin state))
  921. (when (yenc-last-part-p)
  922. (push 'end state))
  923. (unless state
  924. (push 'middle state))
  925. (mm-with-unibyte-buffer
  926. (insert-buffer-substring gnus-original-article-buffer)
  927. (yenc-decode-region (point-min) (point-max))
  928. (when (and (member 'begin state)
  929. (file-exists-p gnus-uu-yenc-article-name))
  930. (delete-file gnus-uu-yenc-article-name))
  931. (mm-append-to-file (point-min) (point-max)
  932. gnus-uu-yenc-article-name)))
  933. (if (memq 'begin state)
  934. (cons file-name state)
  935. state))))
  936. ;; PostScript
  937. (defun gnus-uu-decode-postscript-article (process-buffer in-state)
  938. (let ((state (list 'ok))
  939. start-char end-char file-name)
  940. (with-current-buffer process-buffer
  941. (goto-char (point-min))
  942. (if (not (re-search-forward gnus-uu-postscript-begin-string nil t))
  943. (setq state (list 'wrong-type))
  944. (beginning-of-line)
  945. (setq start-char (point))
  946. (if (not (re-search-forward gnus-uu-postscript-end-string nil t))
  947. (setq state (list 'wrong-type))
  948. (setq end-char (point))
  949. (set-buffer (gnus-get-buffer-create gnus-uu-output-buffer-name))
  950. (insert-buffer-substring process-buffer start-char end-char)
  951. (setq file-name (concat gnus-uu-work-dir
  952. (cdr gnus-article-current) ".ps"))
  953. (write-region (point-min) (point-max) file-name)
  954. (setq state (list file-name 'begin 'end)))))
  955. state))
  956. ;; Find actions.
  957. (defun gnus-uu-get-actions (files)
  958. (let ((ofiles files)
  959. action name)
  960. (while files
  961. (setq name (cdr (assq 'name (car files))))
  962. (and
  963. (setq action (gnus-uu-get-action name))
  964. (setcar files (nconc (list (if (string= action "gnus-uu-archive")
  965. (cons 'action "file")
  966. (cons 'action action))
  967. (cons 'execute (gnus-uu-command
  968. action name)))
  969. (car files))))
  970. (setq files (cdr files)))
  971. ofiles))
  972. (defun gnus-uu-get-action (file-name)
  973. (let (action)
  974. (setq action
  975. (gnus-uu-choose-action
  976. file-name
  977. (append
  978. gnus-uu-user-view-rules
  979. (if gnus-uu-ignore-default-view-rules
  980. nil
  981. gnus-uu-default-view-rules)
  982. gnus-uu-user-view-rules-end)))
  983. (when (and (not (string= (or action "") "gnus-uu-archive"))
  984. gnus-uu-view-with-metamail)
  985. (when (setq action
  986. (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list))
  987. (setq action (format "metamail -d -b -c \"%s\"" action))))
  988. action))
  989. ;; Functions for treating subjects and collecting series.
  990. (defun gnus-uu-reginize-string (string)
  991. ;; Takes a string and puts a \ in front of every special character;
  992. ;; replaces the last thing that looks like "2/3" with "[0-9]+/3"
  993. ;; or, if it can't find something like that, tries "2 of 3", then
  994. ;; finally just replaces the next to last number with "[0-9]+".
  995. (with-current-buffer (gnus-get-buffer-create gnus-uu-output-buffer-name)
  996. (buffer-disable-undo)
  997. (erase-buffer)
  998. (insert (regexp-quote string))
  999. (setq case-fold-search nil)
  1000. (end-of-line)
  1001. (if (re-search-backward "\\([^0-9]\\)[0-9]+/\\([0-9]+\\)" nil t)
  1002. (replace-match "\\1[0-9]+/\\2")
  1003. (end-of-line)
  1004. (if (re-search-backward "\\([^0-9]\\)[0-9]+[ \t]*of[ \t]*\\([0-9]+\\)"
  1005. nil t)
  1006. (replace-match "\\1[0-9]+ of \\2")
  1007. (end-of-line)
  1008. (if (re-search-backward "\\([^0-9]\\)[0-9]+\\([^0-9]+\\)[0-9]+"
  1009. nil t)
  1010. (replace-match "\\1[0-9]+\\2[0-9]+" t nil nil nil))))
  1011. (goto-char (point-min))
  1012. (while (re-search-forward "[ \t]+" nil t)
  1013. (replace-match "[ \t]+" t t))
  1014. (buffer-string)))
  1015. (defun gnus-uu-get-list-of-articles (n)
  1016. ;; If N is non-nil, the article numbers of the N next articles
  1017. ;; will be returned.
  1018. ;; If any articles have been marked as processable, they will be
  1019. ;; returned.
  1020. ;; Failing that, articles that have subjects that are part of the
  1021. ;; same "series" as the current will be returned.
  1022. (let (articles)
  1023. (cond
  1024. (n
  1025. (setq n (prefix-numeric-value n))
  1026. (let ((backward (< n 0))
  1027. (n (abs n)))
  1028. (save-excursion
  1029. (while (and (> n 0)
  1030. (push (gnus-summary-article-number)
  1031. articles)
  1032. (gnus-summary-search-forward nil nil backward))
  1033. (setq n (1- n))))
  1034. (nreverse articles)))
  1035. (gnus-newsgroup-processable
  1036. (reverse gnus-newsgroup-processable))
  1037. (t
  1038. (gnus-uu-find-articles-matching)))))
  1039. (defun gnus-uu-string< (l1 l2)
  1040. (string< (car l1) (car l2)))
  1041. (defun gnus-uu-find-articles-matching
  1042. (&optional subject only-unread do-not-translate)
  1043. ;; Finds all articles that matches the regexp SUBJECT. If it is
  1044. ;; nil, the current article name will be used. If ONLY-UNREAD is
  1045. ;; non-nil, only unread articles are chosen. If DO-NOT-TRANSLATE is
  1046. ;; non-nil, article names are not equalized before sorting.
  1047. (let ((subject (or subject
  1048. (gnus-uu-reginize-string (gnus-summary-article-subject))))
  1049. list-of-subjects)
  1050. (save-excursion
  1051. (when subject
  1052. ;; Collect all subjects matching subject.
  1053. (let ((case-fold-search t)
  1054. (data gnus-newsgroup-data)
  1055. subj mark d)
  1056. (while data
  1057. (setq d (pop data))
  1058. (and (not (gnus-data-pseudo-p d))
  1059. (or (not only-unread)
  1060. (= (setq mark (gnus-data-mark d))
  1061. gnus-unread-mark)
  1062. (= mark gnus-ticked-mark)
  1063. (= mark gnus-dormant-mark))
  1064. (setq subj (mail-header-subject (gnus-data-header d)))
  1065. (string-match subject subj)
  1066. (push (cons subj (gnus-data-number d))
  1067. list-of-subjects))))
  1068. ;; Expand numbers, sort, and return the list of article
  1069. ;; numbers.
  1070. (mapcar 'cdr
  1071. (sort (gnus-uu-expand-numbers
  1072. list-of-subjects
  1073. (not do-not-translate))
  1074. 'gnus-uu-string<))))))
  1075. (defun gnus-uu-expand-numbers (string-list &optional translate)
  1076. ;; Takes a list of strings and "expands" all numbers in all the
  1077. ;; strings. That is, this function makes all numbers equal length by
  1078. ;; prepending lots of zeroes before each number. This is to ease later
  1079. ;; sorting to find out what sequence the articles are supposed to be
  1080. ;; decoded in. Returns the list of expanded strings.
  1081. (let ((out-list string-list)
  1082. string)
  1083. (with-current-buffer (gnus-get-buffer-create gnus-uu-output-buffer-name)
  1084. (buffer-disable-undo)
  1085. (while string-list
  1086. (erase-buffer)
  1087. (insert (caar string-list))
  1088. ;; Translate multiple spaces to one space.
  1089. (goto-char (point-min))
  1090. (while (re-search-forward "[ \t]+" nil t)
  1091. (replace-match " "))
  1092. ;; Translate all characters to "a".
  1093. (goto-char (point-min))
  1094. (when translate
  1095. (while (re-search-forward "[A-Za-z]" nil t)
  1096. (replace-match "a" t t)))
  1097. ;; Expand numbers.
  1098. (goto-char (point-min))
  1099. (while (re-search-forward "[0-9]+" nil t)
  1100. (ignore-errors
  1101. (replace-match
  1102. (format "%06d"
  1103. (string-to-number (buffer-substring
  1104. (match-beginning 0) (match-end 0)))))))
  1105. (setq string (buffer-substring (point-min) (point-max)))
  1106. (setcar (car string-list) string)
  1107. (setq string-list (cdr string-list))))
  1108. out-list))
  1109. ;; `gnus-uu-grab-articles' is the general multi-article treatment
  1110. ;; function. It takes a list of articles to be grabbed and a function
  1111. ;; to apply to each article.
  1112. ;;
  1113. ;; The function to be called should take two parameters. The first
  1114. ;; parameter is the article buffer. The function should leave the
  1115. ;; result, if any, in this buffer. Most treatment functions will just
  1116. ;; generate files...
  1117. ;;
  1118. ;; The second parameter is the state of the list of articles, and can
  1119. ;; have four values: `first', `middle', `last' and `first-and-last'.
  1120. ;;
  1121. ;; The function should return a list. The list may contain the
  1122. ;; following symbols:
  1123. ;; `error' if an error occurred
  1124. ;; `begin' if the beginning of an encoded file has been received
  1125. ;; If the list returned contains a `begin', the first element of
  1126. ;; the list *must* be a string with the file name of the decoded
  1127. ;; file.
  1128. ;; `end' if the end of an encoded file has been received
  1129. ;; `middle' if the article was a body part of an encoded file
  1130. ;; `wrong-type' if the article was not a part of an encoded file
  1131. ;; `ok', which can be used everything is ok
  1132. (defvar gnus-uu-has-been-grabbed nil)
  1133. (defun gnus-uu-unmark-list-of-grabbed (&optional dont-unmark-last-article)
  1134. (let (art)
  1135. (if (not (and gnus-uu-has-been-grabbed
  1136. gnus-uu-unmark-articles-not-decoded))
  1137. ()
  1138. (when dont-unmark-last-article
  1139. (setq art (car gnus-uu-has-been-grabbed))
  1140. (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed)))
  1141. (while gnus-uu-has-been-grabbed
  1142. (gnus-summary-tick-article (car gnus-uu-has-been-grabbed) t)
  1143. (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed)))
  1144. (when dont-unmark-last-article
  1145. (setq gnus-uu-has-been-grabbed (list art))))))
  1146. ;; This function takes a list of articles and a function to apply to
  1147. ;; each article grabbed.
  1148. ;;
  1149. ;; This function returns a list of files decoded if the grabbing and
  1150. ;; the process-function has been successful and nil otherwise.
  1151. (defun gnus-uu-grab-articles (articles process-function
  1152. &optional sloppy limit no-errors)
  1153. (require 'gnus-async)
  1154. (let ((state 'first)
  1155. (gnus-asynchronous nil)
  1156. (gnus-inhibit-treatment t)
  1157. has-been-begin article result-file result-files process-state
  1158. gnus-summary-display-article-function
  1159. gnus-article-prepare-hook gnus-display-mime-function
  1160. article-series files)
  1161. (while (and articles
  1162. (not (memq 'error process-state))
  1163. (or sloppy
  1164. (not (memq 'end process-state))))
  1165. (setq article (pop articles))
  1166. (when (vectorp (gnus-summary-article-header article))
  1167. (push article article-series)
  1168. (unless articles
  1169. (if (eq state 'first)
  1170. (setq state 'first-and-last)
  1171. (setq state 'last)))
  1172. (let ((part (gnus-uu-part-number article)))
  1173. (gnus-message 6 "Getting article %d%s..."
  1174. article (if (string= part "") "" (concat ", " part))))
  1175. (gnus-summary-display-article article)
  1176. ;; Push the article to the processing function.
  1177. (with-current-buffer gnus-original-article-buffer
  1178. (let ((buffer-read-only nil))
  1179. (with-current-buffer gnus-summary-buffer
  1180. (setq process-state
  1181. (funcall process-function
  1182. gnus-original-article-buffer state)))))
  1183. (gnus-summary-remove-process-mark article)
  1184. ;; If this is the beginning of a decoded file, we push it
  1185. ;; on to a list.
  1186. (when (or (memq 'begin process-state)
  1187. (and (or (eq state 'first)
  1188. (eq state 'first-and-last))
  1189. (memq 'ok process-state)))
  1190. (when has-been-begin
  1191. ;; If there is a `result-file' here, that means that the
  1192. ;; file was unsuccessfully decoded, so we delete it.
  1193. (when (and result-file
  1194. (file-exists-p result-file)
  1195. (not gnus-uu-be-dangerous)
  1196. (or (eq gnus-uu-be-dangerous t)
  1197. (gnus-y-or-n-p
  1198. (format "Delete unsuccessfully decoded file %s? "
  1199. result-file))))
  1200. (delete-file result-file)))
  1201. (when (memq 'begin process-state)
  1202. (setq result-file (car process-state)))
  1203. (setq has-been-begin t))
  1204. ;; Check whether we have decoded one complete file.
  1205. (when (memq 'end process-state)
  1206. (setq article-series nil)
  1207. (setq has-been-begin nil)
  1208. (if (stringp result-file)
  1209. (setq files (list result-file))
  1210. (setq files result-file))
  1211. (setq result-file (car files))
  1212. (while files
  1213. (push (list (cons 'name (pop files))
  1214. (cons 'article article))
  1215. result-files))
  1216. ;; Allow user-defined functions to be run on this file.
  1217. (when gnus-uu-grabbed-file-functions
  1218. (let ((funcs gnus-uu-grabbed-file-functions))
  1219. (unless (listp funcs)
  1220. (setq funcs (list funcs)))
  1221. (while funcs
  1222. (funcall (pop funcs) result-file))))
  1223. (setq result-file nil)
  1224. ;; Check whether we have decoded enough articles.
  1225. (and limit (= (length result-files) limit)
  1226. (setq articles nil)))
  1227. ;; If this is the last article to be decoded, and
  1228. ;; we still haven't reached the end, then we delete
  1229. ;; the partially decoded file.
  1230. (and (or (eq state 'last) (eq state 'first-and-last))
  1231. (not (memq 'end process-state))
  1232. result-file
  1233. (file-exists-p result-file)
  1234. (not gnus-uu-be-dangerous)
  1235. (or (eq gnus-uu-be-dangerous t)
  1236. (gnus-y-or-n-p
  1237. (format "Delete incomplete file %s? " result-file)))
  1238. (delete-file result-file))
  1239. ;; If this was a file of the wrong sort, then
  1240. (when (and (or (memq 'wrong-type process-state)
  1241. (memq 'error process-state))
  1242. gnus-uu-unmark-articles-not-decoded)
  1243. (gnus-summary-tick-article article t))
  1244. ;; Set the new series state.
  1245. (if (and (not has-been-begin)
  1246. (not sloppy)
  1247. (or (memq 'end process-state)
  1248. (memq 'middle process-state)))
  1249. (progn
  1250. (setq process-state (list 'error))
  1251. (gnus-message 2 "No begin part at the beginning")
  1252. (sleep-for 2))
  1253. (setq state 'middle))))
  1254. ;; When there are no result-files, then something must be wrong.
  1255. (if result-files
  1256. (message "")
  1257. (cond
  1258. ((not has-been-begin)
  1259. (gnus-message 2 "Wrong type file"))
  1260. ((memq 'error process-state)
  1261. (gnus-message 2 "An error occurred during decoding"))
  1262. ((not (or (memq 'ok process-state)
  1263. (memq 'end process-state)))
  1264. (gnus-message 2 "End of articles reached before end of file")))
  1265. ;; Make unsuccessfully decoded articles unread.
  1266. (when gnus-uu-unmark-articles-not-decoded
  1267. (while article-series
  1268. (gnus-summary-tick-article (pop article-series) t))))
  1269. ;; The original article buffer is hosed, shoot it down.
  1270. (gnus-kill-buffer gnus-original-article-buffer)
  1271. (setq gnus-current-article nil)
  1272. result-files))
  1273. (defun gnus-uu-grab-view (file)
  1274. "View FILE using the gnus-uu methods."
  1275. (let ((action (gnus-uu-get-action file)))
  1276. (gnus-execute-command
  1277. (if (string-match "%" action)
  1278. (format action file)
  1279. (concat action " " file))
  1280. (eq gnus-view-pseudos 'not-confirm))))
  1281. (defun gnus-uu-grab-move (file)
  1282. "Move FILE to somewhere."
  1283. (when gnus-uu-default-dir
  1284. (let ((to-file (concat (file-name-as-directory gnus-uu-default-dir)
  1285. (file-name-nondirectory file))))
  1286. (rename-file file to-file)
  1287. (unless (file-exists-p file)
  1288. (make-symbolic-link to-file file)))))
  1289. (defun gnus-uu-part-number (article)
  1290. (let* ((header (gnus-summary-article-header article))
  1291. (subject (and header (mail-header-subject header)))
  1292. (part nil))
  1293. (if subject
  1294. (while (string-match "[0-9]+/[0-9]+\\|[0-9]+[ \t]+of[ \t]+[0-9]+"
  1295. subject)
  1296. (setq part (match-string 0 subject))
  1297. (setq subject (substring subject (match-end 0)))))
  1298. (or part
  1299. (while (string-match "[0-9]+[^0-9]+[0-9]+" subject)
  1300. (setq part (match-string 0 subject))
  1301. (setq subject (substring subject (match-end 0)))))
  1302. (or part "")))
  1303. (defun gnus-uu-uudecode-sentinel (process event)
  1304. (delete-process (get-process process)))
  1305. (defun gnus-uu-uustrip-article (process-buffer in-state)
  1306. ;; Uudecodes a file asynchronously.
  1307. (with-current-buffer process-buffer
  1308. (let ((state (list 'wrong-type))
  1309. process-connection-type case-fold-search buffer-read-only
  1310. files start-char)
  1311. (goto-char (point-min))
  1312. ;; Deal with ^M at the end of the lines.
  1313. (when gnus-uu-kill-carriage-return
  1314. (save-excursion
  1315. (while (search-forward "\r" nil t)
  1316. (delete-char -1))))
  1317. (while (or (re-search-forward gnus-uu-begin-string nil t)
  1318. (re-search-forward gnus-uu-body-line nil t))
  1319. (setq state (list 'ok))
  1320. ;; Ok, we are at the first uucoded line.
  1321. (beginning-of-line)
  1322. (setq start-char (point))
  1323. (if (not (looking-at gnus-uu-begin-string))
  1324. (setq state (list 'middle))
  1325. ;; This is the beginning of a uuencoded article.
  1326. ;; We replace certain characters that could make things messy.
  1327. (setq gnus-uu-file-name
  1328. (gnus-map-function
  1329. mm-file-name-rewrite-functions
  1330. (file-name-nondirectory (match-string 1))))
  1331. (replace-match (concat "begin 644 " gnus-uu-file-name) t t)
  1332. ;; Remove any non gnus-uu-body-line right after start.
  1333. (forward-line 1)
  1334. (while (and (not (eobp))
  1335. (not (looking-at gnus-uu-body-line)))
  1336. (gnus-delete-line))
  1337. ;; If a process is running, we kill it.
  1338. (when (and gnus-uu-uudecode-process
  1339. (memq (process-status gnus-uu-uudecode-process)
  1340. '(run stop)))
  1341. (delete-process gnus-uu-uudecode-process)
  1342. (gnus-uu-unmark-list-of-grabbed t))
  1343. ;; Start a new uudecoding process.
  1344. (let ((cdir default-directory))
  1345. (unwind-protect
  1346. (progn
  1347. (cd gnus-uu-work-dir)
  1348. (setq gnus-uu-uudecode-process
  1349. (start-process
  1350. "*uudecode*"
  1351. (gnus-get-buffer-create gnus-uu-output-buffer-name)
  1352. shell-file-name shell-command-switch
  1353. (format "cd %s %s uudecode" gnus-uu-work-dir
  1354. gnus-shell-command-separator))))
  1355. (cd cdir)))
  1356. (set-process-sentinel
  1357. gnus-uu-uudecode-process 'gnus-uu-uudecode-sentinel)
  1358. (setq state (list 'begin))
  1359. (push (concat gnus-uu-work-dir gnus-uu-file-name) files))
  1360. ;; We look for the end of the thing to be decoded.
  1361. (if (re-search-forward gnus-uu-end-string nil t)
  1362. (push 'end state)
  1363. (goto-char (point-max))
  1364. (re-search-backward gnus-uu-body-line nil t))
  1365. (forward-line 1)
  1366. (when gnus-uu-uudecode-process
  1367. (when (memq (process-status gnus-uu-uudecode-process) '(run stop))
  1368. ;; Try to correct mishandled uucode.
  1369. (when gnus-uu-correct-stripped-uucode
  1370. (gnus-uu-check-correct-stripped-uucode start-char (point)))
  1371. (gnus-run-hooks 'gnus-uu-pre-uudecode-hook)
  1372. ;; Send the text to the process.
  1373. (condition-case nil
  1374. (process-send-region
  1375. gnus-uu-uudecode-process start-char (point))
  1376. (error
  1377. (progn
  1378. (delete-process gnus-uu-uudecode-process)
  1379. (gnus-message 2 "gnus-uu: Couldn't uudecode")
  1380. (setq state (list 'wrong-type)))))
  1381. (if (memq 'end state)
  1382. (progn
  1383. ;; Send an EOF, just in case.
  1384. (ignore-errors
  1385. (process-send-eof gnus-uu-uudecode-process))
  1386. (while (memq (process-status gnus-uu-uudecode-process)
  1387. '(open run))
  1388. (accept-process-output gnus-uu-uudecode-process 1)))
  1389. (when (or (not gnus-uu-uudecode-process)
  1390. (not (memq (process-status gnus-uu-uudecode-process)
  1391. '(run stop))))
  1392. (setq state (list 'wrong-type)))))))
  1393. (if (memq 'begin state)
  1394. (cons (if (= (length files) 1) (car files) files) state)
  1395. state))))
  1396. (defvar gnus-uu-unshar-warning
  1397. "*** WARNING ***
  1398. Shell archives are an archaic method of bundling files for distribution
  1399. across computer networks. During the unpacking process, arbitrary commands
  1400. are executed on your system, and all kinds of nasty things can happen.
  1401. Please examine the archive very carefully before you instruct Emacs to
  1402. unpack it. You can browse the archive buffer using \\[scroll-other-window].
  1403. If you are unsure what to do, please answer \"no\"."
  1404. "Text of warning message displayed by `gnus-uu-unshar-article'.
  1405. Make sure that this text consists only of few text lines. Otherwise,
  1406. Gnus might fail to display all of it.")
  1407. ;; This function is used by `gnus-uu-grab-articles' to treat
  1408. ;; a shared article.
  1409. (defun gnus-uu-unshar-article (process-buffer in-state)
  1410. (let ((state (list 'ok))
  1411. start-char)
  1412. (with-current-buffer process-buffer
  1413. (goto-char (point-min))
  1414. (if (not (re-search-forward gnus-uu-shar-begin-string nil t))
  1415. (setq state (list 'wrong-type))
  1416. (save-window-excursion
  1417. (save-excursion
  1418. (switch-to-buffer (current-buffer))
  1419. (delete-other-windows)
  1420. (let ((buffer (get-buffer-create (generate-new-buffer-name
  1421. "*Warning*"))))
  1422. (unless
  1423. (unwind-protect
  1424. (with-current-buffer buffer
  1425. (insert (substitute-command-keys
  1426. gnus-uu-unshar-warning))
  1427. (goto-char (point-min))
  1428. (display-buffer buffer)
  1429. (yes-or-no-p "This is a shell archive, unshar it? "))
  1430. (kill-buffer buffer))
  1431. (setq state (list 'error))))))
  1432. (unless (memq 'error state)
  1433. (beginning-of-line)
  1434. (setq start-char (point))
  1435. (call-process-region
  1436. start-char (point-max) shell-file-name nil
  1437. (gnus-get-buffer-create gnus-uu-output-buffer-name) nil
  1438. shell-command-switch
  1439. (concat "cd " gnus-uu-work-dir " "
  1440. gnus-shell-command-separator " sh")))))
  1441. state))
  1442. ;; `gnus-uu-choose-action' chooses what action to perform given the name
  1443. ;; and `gnus-uu-file-action-list'. Returns either nil if no action is
  1444. ;; found, or the name of the command to run if such a rule is found.
  1445. (defun gnus-uu-choose-action (file-name file-action-list &optional no-ignore)
  1446. (let ((action-list (copy-sequence file-action-list))
  1447. (case-fold-search t)
  1448. rule action)
  1449. (and
  1450. (unless no-ignore
  1451. (and (not
  1452. (and gnus-uu-ignore-files-by-name
  1453. (string-match gnus-uu-ignore-files-by-name file-name)))
  1454. (not
  1455. (and gnus-uu-ignore-files-by-type
  1456. (string-match gnus-uu-ignore-files-by-type
  1457. (or (gnus-uu-choose-action
  1458. file-name gnus-uu-ext-to-mime-list t)
  1459. ""))))))
  1460. (while (not (or (eq action-list ()) action))
  1461. (setq rule (car action-list))
  1462. (setq action-list (cdr action-list))
  1463. (when (string-match (car rule) file-name)
  1464. (setq action (cadr rule)))))
  1465. action))
  1466. (defun gnus-uu-treat-archive (file-path)
  1467. ;; Unpacks an archive. Returns t if unpacking is successful.
  1468. (let ((did-unpack t)
  1469. action command dir)
  1470. (setq action (gnus-uu-choose-action
  1471. file-path (append gnus-uu-user-archive-rules
  1472. (if gnus-uu-ignore-default-archive-rules
  1473. nil
  1474. gnus-uu-default-archive-rules))))
  1475. (when (not action)
  1476. (error "No unpackers for the file %s" file-path))
  1477. (string-match "/[^/]*$" file-path)
  1478. (setq dir (substring file-path 0 (match-beginning 0)))
  1479. (when (member action gnus-uu-destructive-archivers)
  1480. (copy-file file-path (concat file-path "~") t))
  1481. (setq command (format "cd %s ; %s" dir (gnus-uu-command action file-path)))
  1482. (with-current-buffer (gnus-get-buffer-create gnus-uu-output-buffer-name)
  1483. (erase-buffer))
  1484. (gnus-message 5 "Unpacking: %s..." (gnus-uu-command action file-path))
  1485. (if (eq 0 (call-process shell-file-name nil
  1486. (gnus-get-buffer-create gnus-uu-output-buffer-name)
  1487. nil shell-command-switch command))
  1488. (message "")
  1489. (gnus-message 2 "Error during unpacking of archive")
  1490. (setq did-unpack nil))
  1491. (when (member action gnus-uu-destructive-archivers)
  1492. (rename-file (concat file-path "~") file-path t))
  1493. did-unpack))
  1494. (defun gnus-uu-dir-files (dir)
  1495. (let ((dirs (directory-files dir t "[^/][^\\.][^\\.]?$"))
  1496. files file)
  1497. (while dirs
  1498. (if (file-directory-p (setq file (car dirs)))
  1499. (setq files (append files (gnus-uu-dir-files file)))
  1500. (push file files))
  1501. (setq dirs (cdr dirs)))
  1502. files))
  1503. (defun gnus-uu-unpack-files (files &optional ignore)
  1504. ;; Go through FILES and look for files to unpack.
  1505. (let* ((totfiles (gnus-uu-ls-r gnus-uu-work-dir))
  1506. (ofiles files)
  1507. file did-unpack)
  1508. (while files
  1509. (setq file (cdr (assq 'name (car files))))
  1510. (when (and (not (member file ignore))
  1511. (equal (gnus-uu-get-action (file-name-nondirectory file))
  1512. "gnus-uu-archive"))
  1513. (push file did-unpack)
  1514. (unless (gnus-uu-treat-archive file)
  1515. (gnus-message 2 "Error during unpacking of %s" file))
  1516. (let* ((newfiles (gnus-uu-ls-r gnus-uu-work-dir))
  1517. (nfiles newfiles))
  1518. (while nfiles
  1519. (unless (member (car nfiles) totfiles)
  1520. (push (list (cons 'name (car nfiles))
  1521. (cons 'original file))
  1522. ofiles))
  1523. (setq nfiles (cdr nfiles)))
  1524. (setq totfiles newfiles)))
  1525. (setq files (cdr files)))
  1526. (if did-unpack
  1527. (gnus-uu-unpack-files ofiles (append did-unpack ignore))
  1528. ofiles)))
  1529. (defun gnus-uu-ls-r (dir)
  1530. (let* ((files (gnus-uu-directory-files dir t))
  1531. (ofiles files))
  1532. (while files
  1533. (when (file-directory-p (car files))
  1534. (setq ofiles (delete (car files) ofiles))
  1535. (setq ofiles (append ofiles (gnus-uu-ls-r (car files)))))
  1536. (setq files (cdr files)))
  1537. ofiles))
  1538. ;; Various stuff
  1539. (defun gnus-uu-directory-files (dir &optional full)
  1540. (let (files out file)
  1541. (setq files (directory-files dir full))
  1542. (while files
  1543. (setq file (car files))
  1544. (setq files (cdr files))
  1545. (unless (member (file-name-nondirectory file) '("." ".."))
  1546. (push file out)))
  1547. (setq out (nreverse out))
  1548. out))
  1549. (defun gnus-uu-check-correct-stripped-uucode (start end)
  1550. (save-excursion
  1551. (let (found beg length)
  1552. (unless gnus-uu-correct-stripped-uucode
  1553. (goto-char start)
  1554. (if (re-search-forward " \\|`" end t)
  1555. (progn
  1556. (goto-char start)
  1557. (while (not (eobp))
  1558. (progn
  1559. (when (looking-at "\n")
  1560. (replace-match ""))
  1561. (forward-line 1))))
  1562. (while (not (eobp))
  1563. (unless (looking-at (concat gnus-uu-begin-string "\\|"
  1564. gnus-uu-end-string))
  1565. (when (not found)
  1566. (setq length (- (point-at-eol) (point-at-bol))))
  1567. (setq found t)
  1568. (beginning-of-line)
  1569. (setq beg (point))
  1570. (end-of-line)
  1571. (unless (= length (- (point) beg))
  1572. (insert (make-string (- length (- (point) beg)) ? ))))
  1573. (forward-line 1)))))))
  1574. (defvar gnus-uu-tmp-alist nil)
  1575. (defun gnus-uu-initialize (&optional scan)
  1576. (let (entry)
  1577. (if (and (not scan)
  1578. (when (setq entry (assoc gnus-newsgroup-name gnus-uu-tmp-alist))
  1579. (if (file-exists-p (cdr entry))
  1580. (setq gnus-uu-work-dir (cdr entry))
  1581. (setq gnus-uu-tmp-alist (delq entry gnus-uu-tmp-alist))
  1582. nil)))
  1583. t
  1584. (setq gnus-uu-tmp-dir (file-name-as-directory
  1585. (expand-file-name gnus-uu-tmp-dir)))
  1586. (if (not (file-directory-p gnus-uu-tmp-dir))
  1587. (error "Temp directory %s doesn't exist" gnus-uu-tmp-dir)
  1588. (when (not (file-writable-p gnus-uu-tmp-dir))
  1589. (error "Temp directory %s can't be written to"
  1590. gnus-uu-tmp-dir)))
  1591. (setq gnus-uu-work-dir
  1592. (mm-make-temp-file (concat gnus-uu-tmp-dir "gnus") 'dir))
  1593. (gnus-set-file-modes gnus-uu-work-dir 448)
  1594. (setq gnus-uu-work-dir (file-name-as-directory gnus-uu-work-dir))
  1595. (push (cons gnus-newsgroup-name gnus-uu-work-dir)
  1596. gnus-uu-tmp-alist))))
  1597. ;; Kills the temporary uu buffers, kills any processes, etc.
  1598. (defun gnus-uu-clean-up ()
  1599. (let (buf)
  1600. (and gnus-uu-uudecode-process
  1601. (memq (process-status (or gnus-uu-uudecode-process "nevair"))
  1602. '(stop run))
  1603. (delete-process gnus-uu-uudecode-process))
  1604. (when (setq buf (get-buffer gnus-uu-output-buffer-name))
  1605. (kill-buffer buf))))
  1606. ;; Inputs an action and a filename and returns a full command, making sure
  1607. ;; that the filename will be treated as a single argument when the shell
  1608. ;; executes the command.
  1609. (defun gnus-uu-command (action file)
  1610. (let ((quoted-file (shell-quote-argument file)))
  1611. (if (string-match "%s" action)
  1612. (format action quoted-file)
  1613. (concat action " " quoted-file))))
  1614. (defun gnus-uu-delete-work-dir (&optional dir)
  1615. "Delete recursively all files and directories under `gnus-uu-work-dir'."
  1616. (if dir
  1617. (gnus-message 7 "Deleting directory %s..." dir)
  1618. (setq dir gnus-uu-work-dir))
  1619. (when (and dir
  1620. (file-exists-p dir))
  1621. (let ((files (directory-files dir t nil t))
  1622. file)
  1623. (while (setq file (pop files))
  1624. (unless (member (file-name-nondirectory file) '("." ".."))
  1625. (if (file-directory-p file)
  1626. (gnus-uu-delete-work-dir file)
  1627. (gnus-message 9 "Deleting file %s..." file)
  1628. (condition-case err
  1629. (delete-file file)
  1630. (error (gnus-message 3 "Deleting file %s failed... %s" file err))))))
  1631. (condition-case err
  1632. (delete-directory dir)
  1633. (error (gnus-message 3 "Deleting directory %s failed... %s" file err))))
  1634. (gnus-message 7 "")))
  1635. ;; Initializing
  1636. (add-hook 'gnus-summary-prepare-exit-hook 'gnus-uu-clean-up)
  1637. (add-hook 'gnus-summary-prepare-exit-hook 'gnus-uu-delete-work-dir)
  1638. ;;;
  1639. ;;; uuencoded posting
  1640. ;;;
  1641. ;; Any function that is to be used as and encoding method will take two
  1642. ;; parameters: PATH-NAME and FILE-NAME. (E.g. "/home/gaga/spiral.jpg"
  1643. ;; and "spiral.jpg", respectively.) The function should return nil if
  1644. ;; the encoding wasn't successful.
  1645. (defcustom gnus-uu-post-encode-method 'gnus-uu-post-encode-uuencode
  1646. "Function used for encoding binary files.
  1647. There are three functions supplied with gnus-uu for encoding files:
  1648. `gnus-uu-post-encode-uuencode', which does straight uuencoding;
  1649. `gnus-uu-post-encode-mime', which encodes with base64 and adds MIME
  1650. headers; and `gnus-uu-post-encode-mime-uuencode', which encodes with
  1651. uuencode and adds MIME headers."
  1652. :group 'gnus-extract-post
  1653. :type '(radio (function-item gnus-uu-post-encode-uuencode)
  1654. (function-item gnus-uu-post-encode-mime)
  1655. (function-item gnus-uu-post-encode-mime-uuencode)
  1656. (function :tag "Other")))
  1657. (defcustom gnus-uu-post-include-before-composing nil
  1658. "Non-nil means that gnus-uu will ask for a file to encode before you compose the article.
  1659. If this variable is t, you can either include an encoded file with
  1660. \\[gnus-uu-post-insert-binary-in-article] or have one included for you when you post the article."
  1661. :group 'gnus-extract-post
  1662. :type 'boolean)
  1663. (defcustom gnus-uu-post-length 990
  1664. "Maximum length of an article.
  1665. The encoded file will be split into how many articles it takes to
  1666. post the entire file."
  1667. :group 'gnus-extract-post
  1668. :type 'integer)
  1669. (defcustom gnus-uu-post-threaded nil
  1670. "Non-nil means that gnus-uu will post the encoded file in a thread.
  1671. This may not be smart, as no other decoder I have seen are able to
  1672. follow threads when collecting uuencoded articles. (Well, I have seen
  1673. one package that does that - gnus-uu, but somehow, I don't think that
  1674. counts...) The default is nil."
  1675. :group 'gnus-extract-post
  1676. :type 'boolean)
  1677. (defcustom gnus-uu-post-separate-description t
  1678. "Non-nil means that the description will be posted in a separate article.
  1679. The first article will typically be numbered (0/x). If this variable
  1680. is nil, the description the user enters will be included at the
  1681. beginning of the first article, which will be numbered (1/x). Default
  1682. is t."
  1683. :group 'gnus-extract-post
  1684. :type 'boolean)
  1685. (defvar gnus-uu-post-binary-separator "--binary follows this line--")
  1686. (defvar gnus-uu-post-message-id nil)
  1687. (defvar gnus-uu-post-inserted-file-name nil)
  1688. (defvar gnus-uu-winconf-post-news nil)
  1689. (defun gnus-uu-post-news ()
  1690. "Compose an article and post an encoded file."
  1691. (interactive)
  1692. (setq gnus-uu-post-inserted-file-name nil)
  1693. (setq gnus-uu-winconf-post-news (current-window-configuration))
  1694. (gnus-summary-post-news)
  1695. (let ((map (make-sparse-keymap)))
  1696. (set-keymap-parent map (current-local-map))
  1697. (use-local-map map))
  1698. ;;(local-set-key "\C-c\C-c" 'gnus-summary-edit-article-done)
  1699. (local-set-key "\C-c\C-c" 'gnus-uu-post-news-inews)
  1700. (local-set-key "\C-c\C-s" 'gnus-uu-post-news-inews)
  1701. (local-set-key "\C-c\C-i" 'gnus-uu-post-insert-binary-in-article)
  1702. (when gnus-uu-post-include-before-composing
  1703. (save-excursion (setq gnus-uu-post-inserted-file-name
  1704. (gnus-uu-post-insert-binary)))))
  1705. (defun gnus-uu-post-insert-binary-in-article ()
  1706. "Inserts an encoded file in the buffer.
  1707. The user will be asked for a file name."
  1708. (interactive)
  1709. (save-excursion
  1710. (setq gnus-uu-post-inserted-file-name (gnus-uu-post-insert-binary))))
  1711. ;; Encodes with uuencode and substitutes all spaces with backticks.
  1712. (defun gnus-uu-post-encode-uuencode (path file-name)
  1713. (when (gnus-uu-post-encode-file "uuencode" path file-name)
  1714. (goto-char (point-min))
  1715. (forward-line 1)
  1716. (while (search-forward " " nil t)
  1717. (replace-match "`"))
  1718. t))
  1719. ;; Encodes with uuencode and adds MIME headers.
  1720. (defun gnus-uu-post-encode-mime-uuencode (path file-name)
  1721. (when (gnus-uu-post-encode-uuencode path file-name)
  1722. (gnus-uu-post-make-mime file-name "x-uue")
  1723. t))
  1724. ;; Encodes with base64 and adds MIME headers
  1725. (defun gnus-uu-post-encode-mime (path file-name)
  1726. (when (eq 0 (call-process shell-file-name nil t nil shell-command-switch
  1727. (format "%s %s -o %s" "mmencode" path file-name)))
  1728. (gnus-uu-post-make-mime file-name "base64")
  1729. t))
  1730. ;; Adds MIME headers.
  1731. (defun gnus-uu-post-make-mime (file-name encoding)
  1732. (goto-char (point-min))
  1733. (insert (format "Content-Type: %s; name=\"%s\"\n"
  1734. (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list)
  1735. file-name))
  1736. (insert (format "Content-Transfer-Encoding: %s\n\n" encoding))
  1737. (save-restriction
  1738. (set-buffer gnus-message-buffer)
  1739. (goto-char (point-min))
  1740. (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
  1741. (forward-line -1)
  1742. (narrow-to-region (point-min) (point))
  1743. (unless (mail-fetch-field "mime-version")
  1744. (widen)
  1745. (insert "MIME-Version: 1.0\n"))
  1746. (widen)))
  1747. ;; Encodes a file PATH with COMMAND, leaving the result in the
  1748. ;; current buffer.
  1749. (defun gnus-uu-post-encode-file (command path file-name)
  1750. (eq 0 (call-process shell-file-name nil t nil shell-command-switch
  1751. (format "%s %s %s" command path file-name))))
  1752. (defun gnus-uu-post-news-inews ()
  1753. "Posts the composed news article and encoded file.
  1754. If no file has been included, the user will be asked for a file."
  1755. (interactive)
  1756. (let (file-name)
  1757. (if gnus-uu-post-inserted-file-name
  1758. (setq file-name gnus-uu-post-inserted-file-name)
  1759. (setq file-name (gnus-uu-post-insert-binary)))
  1760. (gnus-uu-post-encoded file-name gnus-uu-post-threaded))
  1761. (setq gnus-uu-post-inserted-file-name nil)
  1762. (when gnus-uu-winconf-post-news
  1763. (set-window-configuration gnus-uu-winconf-post-news)))
  1764. ;; Asks for a file to encode, encodes it and inserts the result in
  1765. ;; the current buffer. Returns the file name the user gave.
  1766. (defun gnus-uu-post-insert-binary ()
  1767. (let ((uuencode-buffer-name "*uuencode buffer*")
  1768. file-path uubuf file-name)
  1769. (setq file-path (read-file-name
  1770. "What file do you want to encode? "))
  1771. (when (not (file-exists-p file-path))
  1772. (error "%s: No such file" file-path))
  1773. (goto-char (point-max))
  1774. (insert (format "\n%s\n" gnus-uu-post-binary-separator))
  1775. ;; #### Unix-specific?
  1776. (when (string-match "^~/" file-path)
  1777. (setq file-path (concat "$HOME" (substring file-path 1))))
  1778. ;; #### Unix-specific?
  1779. (if (string-match "/[^/]*$" file-path)
  1780. (setq file-name (substring file-path (1+ (match-beginning 0))))
  1781. (setq file-name file-path))
  1782. (unwind-protect
  1783. (if (with-current-buffer
  1784. (setq uubuf (gnus-get-buffer-create uuencode-buffer-name))
  1785. (erase-buffer)
  1786. (funcall gnus-uu-post-encode-method file-path file-name))
  1787. (insert-buffer-substring uubuf)
  1788. (error "Encoding unsuccessful"))
  1789. (kill-buffer uubuf))
  1790. file-name))
  1791. ;; Posts the article and all of the encoded file.
  1792. (defun gnus-uu-post-encoded (file-name &optional threaded)
  1793. (let ((send-buffer-name "*uuencode send buffer*")
  1794. (encoded-buffer-name "*encoded buffer*")
  1795. (top-string "[ cut here %s (%s %d/%d) %s gnus-uu ]")
  1796. (separator (concat mail-header-separator "\n\n"))
  1797. uubuf length parts header i end beg
  1798. beg-line minlen post-buf whole-len beg-binary end-binary)
  1799. (setq post-buf (current-buffer))
  1800. (goto-char (point-min))
  1801. (when (not (re-search-forward
  1802. (if gnus-uu-post-separate-description
  1803. (concat "^" (regexp-quote gnus-uu-post-binary-separator)
  1804. "$")
  1805. (concat "^" (regexp-quote mail-header-separator) "$"))
  1806. nil t))
  1807. (error "Internal error: No binary/header separator"))
  1808. (beginning-of-line)
  1809. (forward-line 1)
  1810. (setq beg-binary (point))
  1811. (setq end-binary (point-max))
  1812. (with-current-buffer
  1813. (setq uubuf (gnus-get-buffer-create encoded-buffer-name))
  1814. (erase-buffer)
  1815. (insert-buffer-substring post-buf beg-binary end-binary)
  1816. (goto-char (point-min))
  1817. (setq length (count-lines (point-min) (point-max)))
  1818. (setq parts (/ length gnus-uu-post-length))
  1819. (unless (< (% length gnus-uu-post-length) 4)
  1820. (incf parts)))
  1821. (when gnus-uu-post-separate-description
  1822. (forward-line -1))
  1823. (delete-region (point) (point-max))
  1824. (goto-char (point-min))
  1825. (re-search-forward
  1826. (concat "^" (regexp-quote mail-header-separator) "$") nil t)
  1827. (setq header (buffer-substring (point-min) (point-at-bol)))
  1828. (goto-char (point-min))
  1829. (when gnus-uu-post-separate-description
  1830. (when (re-search-forward "^Subject: " nil t)
  1831. (end-of-line)
  1832. (insert (format " (0/%d)" parts)))
  1833. (save-excursion
  1834. (message-send))
  1835. (setq gnus-uu-post-message-id (message-fetch-field "message-id")))
  1836. (save-excursion
  1837. (setq i 1)
  1838. (setq beg 1)
  1839. (while (not (> i parts))
  1840. (set-buffer (gnus-get-buffer-create send-buffer-name))
  1841. (erase-buffer)
  1842. (insert header)
  1843. (when (and threaded gnus-uu-post-message-id)
  1844. (insert "References: " gnus-uu-post-message-id "\n"))
  1845. (insert separator)
  1846. (setq whole-len
  1847. (- 62 (length (format top-string "" file-name i parts ""))))
  1848. (when (> 1 (setq minlen (/ whole-len 2)))
  1849. (setq minlen 1))
  1850. (setq
  1851. beg-line
  1852. (format top-string
  1853. (make-string minlen ?-)
  1854. file-name i parts
  1855. (make-string
  1856. (if (= 0 (% whole-len 2)) (1- minlen) minlen) ?-)))
  1857. (goto-char (point-min))
  1858. (when (re-search-forward "^Subject: " nil t)
  1859. (end-of-line)
  1860. (insert (format " (%d/%d)" i parts)))
  1861. (goto-char (point-max))
  1862. (with-current-buffer uubuf
  1863. (goto-char beg)
  1864. (if (= i parts)
  1865. (goto-char (point-max))
  1866. (forward-line gnus-uu-post-length))
  1867. (when (and (= (1+ i) parts) (< (count-lines (point) (point-max)) 4))
  1868. (forward-line -4))
  1869. (setq end (point)))
  1870. (insert-buffer-substring uubuf beg end)
  1871. (insert beg-line "\n")
  1872. (setq beg end)
  1873. (incf i)
  1874. (goto-char (point-min))
  1875. (re-search-forward
  1876. (concat "^" (regexp-quote mail-header-separator) "$") nil t)
  1877. (beginning-of-line)
  1878. (forward-line 2)
  1879. (when (re-search-forward
  1880. (concat "^" (regexp-quote gnus-uu-post-binary-separator) "$")
  1881. nil t)
  1882. (replace-match "")
  1883. (forward-line 1))
  1884. (insert beg-line)
  1885. (insert "\n")
  1886. (let (message-sent-message-via)
  1887. (save-excursion
  1888. (message-send))
  1889. (setq gnus-uu-post-message-id
  1890. (concat (message-fetch-field "references") " "
  1891. (message-fetch-field "message-id"))))))
  1892. (gnus-kill-buffer send-buffer-name)
  1893. (gnus-kill-buffer encoded-buffer-name)
  1894. (when (not gnus-uu-post-separate-description)
  1895. (set-buffer-modified-p nil)
  1896. (bury-buffer))))
  1897. (provide 'gnus-uu)
  1898. ;;; gnus-uu.el ends here