gnus-msg.el 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918
  1. ;;; gnus-msg.el --- mail and post interface for Gnus
  2. ;; Copyright (C) 1995-2012 Free Software Foundation, Inc.
  3. ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
  4. ;; Lars Magne Ingebrigtsen <larsi@gnus.org>
  5. ;; Keywords: news
  6. ;; This file is part of GNU Emacs.
  7. ;; GNU Emacs is free software: you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;;; Code:
  19. (eval-when-compile (require 'cl))
  20. (require 'gnus)
  21. (require 'gnus-ems)
  22. (require 'message)
  23. (require 'gnus-art)
  24. (require 'gnus-util)
  25. (defcustom gnus-post-method 'current
  26. "*Preferred method for posting USENET news.
  27. If this variable is `current' (which is the default), Gnus will use
  28. the \"current\" select method when posting. If it is `native', Gnus
  29. will use the native select method when posting.
  30. This method will not be used in mail groups and the like, only in
  31. \"real\" newsgroups.
  32. If not `native' nor `current', the value must be a valid method as discussed
  33. in the documentation of `gnus-select-method'. It can also be a list of
  34. methods. If that is the case, the user will be queried for what select
  35. method to use when posting."
  36. :group 'gnus-group-foreign
  37. :link '(custom-manual "(gnus)Posting Server")
  38. :type `(choice (const native)
  39. (const current)
  40. (sexp :tag "Methods" ,gnus-select-method)))
  41. (defcustom gnus-outgoing-message-group nil
  42. "All outgoing messages will be put in this group.
  43. If you want to store all your outgoing mail and articles in the group
  44. \"nnml:archive\", you set this variable to that value. This variable
  45. can also be a list of group names.
  46. If you want to have greater control over what group to put each
  47. message in, you can set this variable to a function that checks the
  48. current newsgroup name and then returns a suitable group name (or list
  49. of names)."
  50. :group 'gnus-message
  51. :type '(choice (const nil)
  52. (function)
  53. (string :tag "Group")
  54. (repeat :tag "List of groups" (string :tag "Group"))))
  55. (make-obsolete-variable 'gnus-outgoing-message-group 'gnus-message-archive-group "24.1")
  56. (defcustom gnus-mailing-list-groups nil
  57. "*If non-nil a regexp matching groups that are really mailing lists.
  58. This is useful when you're reading a mailing list that has been
  59. gatewayed to a newsgroup, and you want to followup to an article in
  60. the group."
  61. :group 'gnus-message
  62. :type '(choice (regexp)
  63. (const nil)))
  64. (defcustom gnus-add-to-list nil
  65. "*If non-nil, add a `to-list' parameter automatically."
  66. :group 'gnus-message
  67. :type 'boolean)
  68. (defcustom gnus-crosspost-complaint
  69. "Hi,
  70. You posted the article below with the following Newsgroups header:
  71. Newsgroups: %s
  72. The %s group, at least, was an inappropriate recipient
  73. of this message. Please trim your Newsgroups header to exclude this
  74. group before posting in the future.
  75. Thank you.
  76. "
  77. "Format string to be inserted when complaining about crossposts.
  78. The first %s will be replaced by the Newsgroups header;
  79. the second with the current group name."
  80. :group 'gnus-message
  81. :type 'string)
  82. (defcustom gnus-message-setup-hook nil
  83. "Hook run after setting up a message buffer."
  84. :group 'gnus-message
  85. :options '(message-remove-blank-cited-lines)
  86. :type 'hook)
  87. (defcustom gnus-bug-create-help-buffer t
  88. "*Should we create the *Gnus Help Bug* buffer?"
  89. :group 'gnus-message
  90. :type 'boolean)
  91. (defcustom gnus-posting-styles nil
  92. "*Alist of styles to use when posting.
  93. See Info node `(gnus)Posting Styles'."
  94. :group 'gnus-message
  95. :link '(custom-manual "(gnus)Posting Styles")
  96. :type '(repeat (cons (choice (regexp)
  97. (variable)
  98. (list (const header)
  99. (string :tag "Header")
  100. (regexp :tag "Regexp"))
  101. (function)
  102. (sexp))
  103. (repeat (list
  104. (choice (const signature)
  105. (const signature-file)
  106. (const organization)
  107. (const address)
  108. (const x-face-file)
  109. (const name)
  110. (const body)
  111. (symbol)
  112. (string :tag "Header"))
  113. (choice (string)
  114. (function)
  115. (variable)
  116. (sexp)))))))
  117. (defcustom gnus-gcc-mark-as-read nil
  118. "If non-nil, automatically mark Gcc articles as read."
  119. :version "22.1"
  120. :group 'gnus-message
  121. :type 'boolean)
  122. (make-obsolete-variable 'gnus-inews-mark-gcc-as-read
  123. 'gnus-gcc-mark-as-read "Emacs 22.1")
  124. (defcustom gnus-gcc-externalize-attachments nil
  125. "Should local-file attachments be included as external parts in Gcc copies?
  126. If it is `all', attach files as external parts;
  127. if a regexp and matches the Gcc group name, attach files as external parts;
  128. if nil, attach files as normal parts."
  129. :version "22.1"
  130. :group 'gnus-message
  131. :type '(choice (const nil :tag "None")
  132. (const all :tag "Any")
  133. (string :tag "Regexp")))
  134. (gnus-define-group-parameter
  135. posting-charset-alist
  136. :type list
  137. :function-document
  138. "Return the permitted unencoded charsets for posting of GROUP."
  139. :variable gnus-group-posting-charset-alist
  140. :variable-default
  141. '(("^\\(no\\|fr\\)\\.[^,]*\\(,[ \t\n]*\\(no\\|fr\\)\\.[^,]*\\)*$" iso-8859-1 (iso-8859-1))
  142. ("^\\(fido7\\|relcom\\)\\.[^,]*\\(,[ \t\n]*\\(fido7\\|relcom\\)\\.[^,]*\\)*$" koi8-r (koi8-r))
  143. (message-this-is-mail nil nil)
  144. (message-this-is-news nil t))
  145. :variable-document
  146. "Alist of regexps and permitted unencoded charsets for posting.
  147. Each element of the alist has the form (TEST HEADER BODY-LIST), where
  148. TEST is either a regular expression matching the newsgroup header or a
  149. variable to query,
  150. HEADER is the charset which may be left unencoded in the header (nil
  151. means encode all charsets),
  152. BODY-LIST is a list of charsets which may be encoded using 8bit
  153. content-transfer encoding in the body, or one of the special values
  154. nil (always encode using quoted-printable) or t (always use 8bit).
  155. Note that any value other than nil for HEADER infringes some RFCs, so
  156. use this option with care."
  157. :variable-group gnus-charset
  158. :variable-type
  159. '(repeat (list :tag "Permitted unencoded charsets"
  160. (choice :tag "Where"
  161. (regexp :tag "Group")
  162. (const :tag "Mail message" :value message-this-is-mail)
  163. (const :tag "News article" :value message-this-is-news))
  164. (choice :tag "Header"
  165. (const :tag "None" nil)
  166. (symbol :tag "Charset"))
  167. (choice :tag "Body"
  168. (const :tag "Any" :value t)
  169. (const :tag "None" :value nil)
  170. (repeat :tag "Charsets"
  171. (symbol :tag "Charset")))))
  172. :parameter-type '(choice :tag "Permitted unencoded charsets"
  173. :value nil
  174. (repeat (symbol)))
  175. :parameter-document "\
  176. List of charsets that are permitted to be unencoded.")
  177. (defcustom gnus-debug-files
  178. '("gnus.el" "gnus-sum.el" "gnus-group.el"
  179. "gnus-art.el" "gnus-start.el" "gnus-async.el"
  180. "gnus-msg.el" "gnus-score.el" "gnus-win.el" "gnus-topic.el"
  181. "gnus-agent.el" "gnus-cache.el" "gnus-srvr.el"
  182. "mm-util.el" "mm-decode.el" "nnmail.el" "message.el")
  183. "Files whose variables will be reported in `gnus-bug'."
  184. :version "22.1"
  185. :group 'gnus-message
  186. :type '(repeat (string :tag "File")))
  187. (defcustom gnus-debug-exclude-variables
  188. '(mm-mime-mule-charset-alist
  189. nnmail-split-fancy message-minibuffer-local-map)
  190. "Variables that should not be reported in `gnus-bug'."
  191. :version "22.1"
  192. :group 'gnus-message
  193. :type '(repeat (symbol :tag "Variable")))
  194. (defcustom gnus-discouraged-post-methods
  195. '(nndraft nnml nnimap nnmaildir nnmh nnfolder nndir)
  196. "A list of back ends that are not used in \"real\" newsgroups.
  197. This variable is used only when `gnus-post-method' is `current'."
  198. :version "22.1"
  199. :group 'gnus-group-foreign
  200. :type '(repeat (symbol :tag "Back end")))
  201. (defcustom gnus-message-replysign
  202. nil
  203. "Automatically sign replies to signed messages.
  204. See also the `mml-default-sign-method' variable."
  205. :group 'gnus-message
  206. :type 'boolean)
  207. (defcustom gnus-message-replyencrypt t
  208. "Automatically encrypt replies to encrypted messages.
  209. See also the `mml-default-encrypt-method' variable."
  210. :version "24.1"
  211. :group 'gnus-message
  212. :type 'boolean)
  213. (defcustom gnus-message-replysignencrypted
  214. t
  215. "Setting this causes automatically encrypted messages to also be signed."
  216. :group 'gnus-message
  217. :type 'boolean)
  218. (defcustom gnus-confirm-mail-reply-to-news (and gnus-novice-user
  219. (not gnus-expert-user))
  220. "If non-nil, Gnus requests confirmation when replying to news.
  221. This is done because new users often reply by mistake when reading
  222. news.
  223. This can also be a function receiving the group name as the only
  224. parameter, which should return non-nil if a confirmation is needed; or
  225. a regexp, in which case a confirmation is asked for if the group name
  226. matches the regexp."
  227. :version "23.1" ;; No Gnus (default changed)
  228. :group 'gnus-message
  229. :type '(choice (const :tag "No" nil)
  230. (const :tag "Yes" t)
  231. (regexp :tag "If group matches regexp")
  232. (function :tag "If function evaluates to non-nil")))
  233. (defcustom gnus-confirm-treat-mail-like-news
  234. nil
  235. "If non-nil, Gnus will treat mail like news with regard to confirmation
  236. when replying by mail. See the `gnus-confirm-mail-reply-to-news' variable
  237. for fine-tuning this.
  238. If nil, Gnus will never ask for confirmation if replying to mail."
  239. :version "22.1"
  240. :group 'gnus-message
  241. :type 'boolean)
  242. (defcustom gnus-summary-resend-default-address t
  243. "If non-nil, Gnus tries to suggest a default address to resend to.
  244. If nil, the address field will always be empty after invoking
  245. `gnus-summary-resend-message'."
  246. :version "22.1"
  247. :group 'gnus-message
  248. :type 'boolean)
  249. (defcustom gnus-message-highlight-citation
  250. t ;; gnus-treat-highlight-citation ;; gnus-cite dependency
  251. "Enable highlighting of different citation levels in message-mode."
  252. :version "23.1" ;; No Gnus
  253. :group 'gnus-cite
  254. :group 'gnus-message
  255. :type 'boolean)
  256. (autoload 'gnus-message-citation-mode "gnus-cite" nil t)
  257. ;;; Internal variables.
  258. (defvar gnus-inhibit-posting-styles nil
  259. "Inhibit the use of posting styles.")
  260. (defvar gnus-article-yanked-articles nil)
  261. (defvar gnus-message-buffer "*Mail Gnus*")
  262. (defvar gnus-article-copy nil)
  263. (defvar gnus-check-before-posting nil)
  264. (defvar gnus-last-posting-server nil)
  265. (defvar gnus-message-group-art nil)
  266. (defvar gnus-msg-force-broken-reply-to nil)
  267. (defconst gnus-bug-message
  268. "Sending a bug report to the Gnus Towers.
  269. ========================================
  270. The buffer below is a mail buffer. When you press `C-c C-c', it will
  271. be sent to the Gnus Bug Exterminators.
  272. The thing near the bottom of the buffer is how the environment
  273. settings will be included in the mail. Please do not delete that.
  274. They will tell the Bug People what your environment is, so that it
  275. will be easier to locate the bugs.
  276. If you have found a bug that makes Emacs go \"beep\", set
  277. debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET')
  278. and include the backtrace in your bug report.
  279. Please describe the bug in annoying, painstaking detail.
  280. Thank you for your help in stamping out bugs.
  281. ")
  282. (autoload 'gnus-uu-post-news "gnus-uu" nil t)
  283. ;;;
  284. ;;; Gnus Posting Functions
  285. ;;;
  286. (gnus-define-keys (gnus-summary-send-map "S" gnus-summary-mode-map)
  287. "p" gnus-summary-post-news
  288. "i" gnus-summary-news-other-window
  289. "f" gnus-summary-followup
  290. "F" gnus-summary-followup-with-original
  291. "c" gnus-summary-cancel-article
  292. "s" gnus-summary-supersede-article
  293. "r" gnus-summary-reply
  294. "y" gnus-summary-yank-message
  295. "R" gnus-summary-reply-with-original
  296. "L" gnus-summary-reply-to-list-with-original
  297. "w" gnus-summary-wide-reply
  298. "W" gnus-summary-wide-reply-with-original
  299. "v" gnus-summary-very-wide-reply
  300. "V" gnus-summary-very-wide-reply-with-original
  301. "n" gnus-summary-followup-to-mail
  302. "N" gnus-summary-followup-to-mail-with-original
  303. "m" gnus-summary-mail-other-window
  304. "u" gnus-uu-post-news
  305. "\M-c" gnus-summary-mail-crosspost-complaint
  306. "Br" gnus-summary-reply-broken-reply-to
  307. "BR" gnus-summary-reply-broken-reply-to-with-original
  308. "om" gnus-summary-mail-forward
  309. "op" gnus-summary-post-forward
  310. "Om" gnus-uu-digest-mail-forward
  311. "Op" gnus-uu-digest-post-forward)
  312. (gnus-define-keys (gnus-send-bounce-map "D" gnus-summary-send-map)
  313. "b" gnus-summary-resend-bounced-mail
  314. ;; "c" gnus-summary-send-draft
  315. "r" gnus-summary-resend-message
  316. "e" gnus-summary-resend-message-edit)
  317. ;;; Internal functions.
  318. (defun gnus-inews-make-draft (articles)
  319. `(lambda ()
  320. (gnus-inews-make-draft-meta-information
  321. ,(gnus-group-decoded-name gnus-newsgroup-name) ',articles)))
  322. (defvar gnus-article-reply nil)
  323. (defmacro gnus-setup-message (config &rest forms)
  324. (let ((winconf (make-symbol "gnus-setup-message-winconf"))
  325. (winconf-name (make-symbol "gnus-setup-message-winconf-name"))
  326. (buffer (make-symbol "gnus-setup-message-buffer"))
  327. (article (make-symbol "gnus-setup-message-article"))
  328. (yanked (make-symbol "gnus-setup-yanked-articles"))
  329. (group (make-symbol "gnus-setup-message-group")))
  330. `(let ((,winconf (current-window-configuration))
  331. (,winconf-name gnus-current-window-configuration)
  332. (,buffer (buffer-name (current-buffer)))
  333. (,article gnus-article-reply)
  334. (,yanked gnus-article-yanked-articles)
  335. (,group gnus-newsgroup-name)
  336. (message-header-setup-hook
  337. (copy-sequence message-header-setup-hook))
  338. (mbl mml-buffer-list)
  339. (message-mode-hook (copy-sequence message-mode-hook)))
  340. (setq mml-buffer-list nil)
  341. (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc)
  342. ;; message-newsreader and message-mailer were formerly set in
  343. ;; gnus-inews-add-send-actions, but this is too late when
  344. ;; message-generate-headers-first is used. --ansel
  345. (add-hook 'message-mode-hook
  346. (lambda nil
  347. (setq message-newsreader
  348. (setq message-mailer (gnus-extended-version)))))
  349. ;; #### FIXME: for a reason that I did not manage to identify yet,
  350. ;; the variable `gnus-newsgroup-name' does not honor a dynamically
  351. ;; scoped or setq'ed value from a caller like `C-u gnus-summary-mail'.
  352. ;; After evaluation of @forms below, it gets the value we actually want
  353. ;; to override, and the posting styles are used. For that reason, I've
  354. ;; added an optional argument to `gnus-configure-posting-styles' to
  355. ;; make sure that the correct value for the group name is used. -- drv
  356. (add-hook 'message-mode-hook
  357. (if (memq ,config '(reply-yank reply))
  358. (lambda ()
  359. (gnus-configure-posting-styles ,group))
  360. (lambda ()
  361. ;; There may be an old " *gnus article copy*" buffer.
  362. (let (gnus-article-copy)
  363. (gnus-configure-posting-styles ,group)))))
  364. (gnus-alist-pull ',(intern gnus-draft-meta-information-header)
  365. message-required-headers)
  366. (when (and ,group
  367. (not (string= ,group "")))
  368. (push (cons
  369. (intern gnus-draft-meta-information-header)
  370. (gnus-inews-make-draft (or ,yanked ,article)))
  371. message-required-headers))
  372. (unwind-protect
  373. (progn
  374. ,@forms)
  375. (gnus-inews-add-send-actions ,winconf ,buffer ,article ,config
  376. ,yanked ,winconf-name)
  377. (setq gnus-message-buffer (current-buffer))
  378. (set (make-local-variable 'gnus-message-group-art)
  379. (cons ,group ,article))
  380. (set (make-local-variable 'gnus-newsgroup-name) ,group)
  381. ;; Enable highlighting of different citation levels
  382. (when gnus-message-highlight-citation
  383. (gnus-message-citation-mode 1))
  384. (gnus-run-hooks 'gnus-message-setup-hook)
  385. (if (eq major-mode 'message-mode)
  386. (let ((mbl1 mml-buffer-list))
  387. (setq mml-buffer-list mbl) ;; Global value
  388. (set (make-local-variable 'mml-buffer-list) mbl1);; Local value
  389. (gnus-make-local-hook 'kill-buffer-hook)
  390. (gnus-make-local-hook 'change-major-mode-hook)
  391. (add-hook 'change-major-mode-hook 'mml-destroy-buffers nil t)
  392. (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))
  393. (mml-destroy-buffers)
  394. (setq mml-buffer-list mbl)))
  395. (message-hide-headers)
  396. (gnus-add-buffer)
  397. (gnus-configure-windows ,config t)
  398. (run-hooks 'post-command-hook)
  399. (set-buffer-modified-p nil))))
  400. (defun gnus-inews-make-draft-meta-information (group articles)
  401. (when (numberp articles)
  402. (setq articles (list articles)))
  403. (concat "(\"" group "\""
  404. (if articles
  405. (concat " "
  406. (mapconcat
  407. (lambda (elem)
  408. (number-to-string
  409. (if (consp elem)
  410. (car elem)
  411. elem)))
  412. articles " "))
  413. "")
  414. ")"))
  415. ;;;###autoload
  416. (defun gnus-msg-mail (&optional to subject other-headers continue
  417. switch-action yank-action send-actions
  418. return-action)
  419. "Start editing a mail message to be sent.
  420. Like `message-mail', but with Gnus paraphernalia, particularly the
  421. Gcc: header for archiving purposes.
  422. If Gnus isn't running, a plain `message-mail' setup is used
  423. instead."
  424. (interactive)
  425. (if (not (gnus-alive-p))
  426. (message-mail to subject other-headers continue
  427. nil yank-action send-actions return-action)
  428. (let ((buf (current-buffer))
  429. (gnus-newsgroup-name (or gnus-newsgroup-name ""))
  430. mail-buf)
  431. (gnus-setup-message 'message
  432. (message-mail to subject other-headers continue
  433. nil yank-action send-actions return-action))
  434. (when switch-action
  435. (setq mail-buf (current-buffer))
  436. (switch-to-buffer buf)
  437. (apply switch-action mail-buf nil))
  438. ;; COMPOSEFUNC should return t if succeed. Undocumented ???
  439. t)))
  440. ;;;###autoload
  441. (defun gnus-button-mailto (address)
  442. "Mail to ADDRESS."
  443. (set-buffer (gnus-copy-article-buffer))
  444. (gnus-setup-message 'message
  445. (message-reply address)))
  446. ;;;###autoload
  447. (defun gnus-button-reply (&optional to-address wide)
  448. "Like `message-reply'."
  449. (interactive)
  450. (gnus-setup-message 'message
  451. (message-reply to-address wide)))
  452. ;;;###autoload
  453. (define-mail-user-agent 'gnus-user-agent
  454. 'gnus-msg-mail 'message-send-and-exit
  455. 'message-kill-buffer 'message-send-hook)
  456. (defun gnus-setup-posting-charset (group)
  457. (let ((alist gnus-group-posting-charset-alist)
  458. (group (or group ""))
  459. elem)
  460. (when group
  461. (catch 'found
  462. (while (setq elem (pop alist))
  463. (when (or (and (stringp (car elem))
  464. (string-match (car elem) group))
  465. (and (functionp (car elem))
  466. (funcall (car elem) group))
  467. (and (symbolp (car elem))
  468. (symbol-value (car elem))))
  469. (throw 'found (cons (cadr elem) (caddr elem)))))))))
  470. (defun gnus-inews-add-send-actions (winconf buffer article
  471. &optional config yanked
  472. winconf-name)
  473. (gnus-make-local-hook 'message-sent-hook)
  474. (add-hook 'message-sent-hook (if gnus-agent 'gnus-agent-possibly-do-gcc
  475. 'gnus-inews-do-gcc) nil t)
  476. (when gnus-agent
  477. (gnus-make-local-hook 'message-header-hook)
  478. (add-hook 'message-header-hook 'gnus-agent-possibly-save-gcc nil t))
  479. (setq message-post-method
  480. `(lambda (&optional arg)
  481. (gnus-post-method arg ,gnus-newsgroup-name)))
  482. (message-add-action
  483. `(progn
  484. (setq gnus-current-window-configuration ',winconf-name)
  485. (when (gnus-buffer-exists-p ,buffer)
  486. (set-window-configuration ,winconf)))
  487. 'exit 'postpone 'kill)
  488. (let ((to-be-marked (cond
  489. (yanked
  490. (mapcar
  491. (lambda (x) (if (listp x) (car x) x)) yanked))
  492. (article (if (listp article) article (list article)))
  493. (t nil))))
  494. (message-add-action
  495. `(when (gnus-buffer-exists-p ,buffer)
  496. (with-current-buffer ,buffer
  497. ,(when to-be-marked
  498. (if (eq config 'forward)
  499. `(gnus-summary-mark-article-as-forwarded ',to-be-marked)
  500. `(gnus-summary-mark-article-as-replied ',to-be-marked)))))
  501. 'send)))
  502. (put 'gnus-setup-message 'lisp-indent-function 1)
  503. (put 'gnus-setup-message 'edebug-form-spec '(form body))
  504. ;;; Post news commands of Gnus group mode and summary mode
  505. (defun gnus-group-mail (&optional arg)
  506. "Start composing a mail.
  507. If ARG, use the group under the point to find a posting style.
  508. If ARG is 1, prompt for a group name to find the posting style."
  509. (interactive "P")
  510. ;; We can't `let' gnus-newsgroup-name here, since that leads
  511. ;; to local variables leaking.
  512. (let ((group gnus-newsgroup-name)
  513. ;; make sure last viewed article doesn't affect posting styles:
  514. (gnus-article-copy)
  515. (buffer (current-buffer)))
  516. (unwind-protect
  517. (progn
  518. (setq gnus-newsgroup-name
  519. (if arg
  520. (if (= 1 (prefix-numeric-value arg))
  521. (gnus-group-completing-read
  522. "Use posting style of group"
  523. nil (gnus-read-active-file-p))
  524. (gnus-group-group-name))
  525. ""))
  526. ;; #### see comment in gnus-setup-message -- drv
  527. (gnus-setup-message 'message (message-mail)))
  528. (with-current-buffer buffer
  529. (setq gnus-newsgroup-name group)))))
  530. (defun gnus-group-news (&optional arg)
  531. "Start composing a news.
  532. If ARG, post to group under point.
  533. If ARG is 1, prompt for group name to post to.
  534. This function prepares a news even when using mail groups. This is useful
  535. for posting messages to mail groups without actually sending them over the
  536. network. The corresponding back end must have a 'request-post method."
  537. (interactive "P")
  538. ;; We can't `let' gnus-newsgroup-name here, since that leads
  539. ;; to local variables leaking.
  540. (let ((group gnus-newsgroup-name)
  541. ;; make sure last viewed article doesn't affect posting styles:
  542. (gnus-article-copy)
  543. (buffer (current-buffer)))
  544. (unwind-protect
  545. (progn
  546. (setq gnus-newsgroup-name
  547. (if arg
  548. (if (= 1 (prefix-numeric-value arg))
  549. (gnus-group-completing-read "Use group"
  550. nil
  551. (gnus-read-active-file-p))
  552. (gnus-group-group-name))
  553. ""))
  554. ;; #### see comment in gnus-setup-message -- drv
  555. (gnus-setup-message 'message
  556. (message-news (gnus-group-real-name gnus-newsgroup-name))))
  557. (with-current-buffer buffer
  558. (setq gnus-newsgroup-name group)))))
  559. (defun gnus-group-post-news (&optional arg)
  560. "Start composing a message (a news by default).
  561. If ARG, post to group under point. If ARG is 1, prompt for group name.
  562. Depending on the selected group, the message might be either a mail or
  563. a news."
  564. (interactive "P")
  565. ;; Bind this variable here to make message mode hooks work ok.
  566. (let ((gnus-newsgroup-name
  567. (if arg
  568. (if (= 1 (prefix-numeric-value arg))
  569. (gnus-group-completing-read "Newsgroup" nil
  570. (gnus-read-active-file-p))
  571. (or (gnus-group-group-name) ""))
  572. ""))
  573. ;; make sure last viewed article doesn't affect posting styles:
  574. (gnus-article-copy))
  575. (gnus-post-news 'post gnus-newsgroup-name nil nil nil nil
  576. (string= gnus-newsgroup-name ""))))
  577. (defun gnus-summary-mail-other-window (&optional arg)
  578. "Start composing a mail in another window.
  579. Use the posting of the current group by default.
  580. If ARG, don't do that. If ARG is 1, prompt for group name to find the
  581. posting style."
  582. (interactive "P")
  583. ;; We can't `let' gnus-newsgroup-name here, since that leads
  584. ;; to local variables leaking.
  585. (let ((group gnus-newsgroup-name)
  586. ;; make sure last viewed article doesn't affect posting styles:
  587. (gnus-article-copy)
  588. (buffer (current-buffer)))
  589. (unwind-protect
  590. (progn
  591. (setq gnus-newsgroup-name
  592. (if arg
  593. (if (= 1 (prefix-numeric-value arg))
  594. (gnus-group-completing-read "Use group"
  595. nil
  596. (gnus-read-active-file-p))
  597. "")
  598. gnus-newsgroup-name))
  599. ;; #### see comment in gnus-setup-message -- drv
  600. (gnus-setup-message 'message (message-mail)))
  601. (with-current-buffer buffer
  602. (setq gnus-newsgroup-name group)))))
  603. (defun gnus-summary-news-other-window (&optional arg)
  604. "Start composing a news in another window.
  605. Post to the current group by default.
  606. If ARG, don't do that. If ARG is 1, prompt for group name to post to.
  607. This function prepares a news even when using mail groups. This is useful
  608. for posting messages to mail groups without actually sending them over the
  609. network. The corresponding back end must have a 'request-post method."
  610. (interactive "P")
  611. ;; We can't `let' gnus-newsgroup-name here, since that leads
  612. ;; to local variables leaking.
  613. (let ((group gnus-newsgroup-name)
  614. ;; make sure last viewed article doesn't affect posting styles:
  615. (gnus-article-copy)
  616. (buffer (current-buffer)))
  617. (unwind-protect
  618. (progn
  619. (setq gnus-newsgroup-name
  620. (if arg
  621. (if (= 1 (prefix-numeric-value arg))
  622. (gnus-group-completing-read "Use group"
  623. nil
  624. (gnus-read-active-file-p))
  625. "")
  626. gnus-newsgroup-name))
  627. ;; #### see comment in gnus-setup-message -- drv
  628. (gnus-setup-message 'message
  629. (progn
  630. (message-news (gnus-group-real-name gnus-newsgroup-name))
  631. (set (make-local-variable 'gnus-discouraged-post-methods)
  632. (remove
  633. (car (gnus-find-method-for-group gnus-newsgroup-name))
  634. gnus-discouraged-post-methods)))))
  635. (with-current-buffer buffer
  636. (setq gnus-newsgroup-name group)))))
  637. (defun gnus-summary-post-news (&optional arg)
  638. "Start composing a message. Post to the current group by default.
  639. If ARG, don't do that. If ARG is 1, prompt for a group name to post to.
  640. Depending on the selected group, the message might be either a mail or
  641. a news."
  642. (interactive "P")
  643. ;; Bind this variable here to make message mode hooks work ok.
  644. (let ((gnus-newsgroup-name
  645. (if arg
  646. (if (= 1 (prefix-numeric-value arg))
  647. (gnus-group-completing-read "Newsgroup" nil
  648. (gnus-read-active-file-p))
  649. "")
  650. gnus-newsgroup-name))
  651. ;; make sure last viewed article doesn't affect posting styles:
  652. (gnus-article-copy))
  653. (gnus-post-news 'post gnus-newsgroup-name)))
  654. (defun gnus-summary-followup (yank &optional force-news)
  655. "Compose a followup to an article.
  656. If prefix argument YANK is non-nil, the original article is yanked
  657. automatically.
  658. YANK is a list of elements, where the car of each element is the
  659. article number, and the cdr is the string to be yanked."
  660. (interactive
  661. (list (and current-prefix-arg
  662. (gnus-summary-work-articles 1))))
  663. (when yank
  664. (gnus-summary-goto-subject
  665. (if (listp (car yank))
  666. (caar yank)
  667. (car yank))))
  668. (save-window-excursion
  669. (gnus-summary-select-article))
  670. (let ((headers (gnus-summary-article-header (gnus-summary-article-number)))
  671. (gnus-newsgroup-name gnus-newsgroup-name))
  672. ;; Send a followup.
  673. (gnus-post-news nil gnus-newsgroup-name
  674. headers gnus-article-buffer
  675. yank nil force-news)
  676. (gnus-summary-handle-replysign)))
  677. (defun gnus-summary-followup-with-original (n &optional force-news)
  678. "Compose a followup to an article and include the original article.
  679. The text in the region will be yanked. If the region isn't
  680. active, the entire article will be yanked."
  681. (interactive "P")
  682. (gnus-summary-followup (gnus-summary-work-articles n) force-news))
  683. (defun gnus-summary-followup-to-mail (&optional arg)
  684. "Followup to the current mail message via news."
  685. (interactive
  686. (list (and current-prefix-arg
  687. (gnus-summary-work-articles 1))))
  688. (gnus-summary-followup arg t))
  689. (defun gnus-summary-followup-to-mail-with-original (&optional arg)
  690. "Followup to the current mail message via news."
  691. (interactive "P")
  692. (gnus-summary-followup (gnus-summary-work-articles arg) t))
  693. (defun gnus-inews-yank-articles (articles)
  694. (let (beg article yank-string)
  695. (message-goto-body)
  696. (while (setq article (pop articles))
  697. (when (listp article)
  698. (setq yank-string (nth 1 article)
  699. article (nth 0 article)))
  700. (save-window-excursion
  701. (set-buffer gnus-summary-buffer)
  702. (gnus-summary-select-article nil nil nil article)
  703. (gnus-summary-remove-process-mark article))
  704. (gnus-copy-article-buffer nil yank-string)
  705. (let ((message-reply-buffer gnus-article-copy)
  706. (message-reply-headers
  707. ;; The headers are decoded.
  708. (with-current-buffer gnus-article-copy
  709. (save-restriction
  710. (nnheader-narrow-to-headers)
  711. (nnheader-parse-naked-head)))))
  712. (message-yank-original)
  713. (message-exchange-point-and-mark)
  714. (setq beg (or beg (mark t))))
  715. (when articles
  716. (insert "\n")))
  717. (push-mark)
  718. (goto-char beg)))
  719. (defun gnus-summary-cancel-article (&optional n symp)
  720. "Cancel an article you posted.
  721. Uses the process-prefix convention. If given the symbolic
  722. prefix `a', cancel using the standard posting method; if not
  723. post using the current select method."
  724. (interactive (gnus-interactive "P\ny"))
  725. (let ((message-post-method
  726. `(lambda (arg)
  727. (gnus-post-method (eq ',symp 'a) ,gnus-newsgroup-name))))
  728. (dolist (article (gnus-summary-work-articles n))
  729. (when (gnus-summary-select-article t nil nil article)
  730. (when (gnus-eval-in-buffer-window gnus-original-article-buffer
  731. (message-cancel-news))
  732. (gnus-summary-mark-as-read article gnus-canceled-mark)
  733. (gnus-cache-remove-article 1))
  734. (gnus-article-hide-headers-if-wanted))
  735. (gnus-summary-remove-process-mark article))))
  736. (defun gnus-summary-supersede-article ()
  737. "Compose an article that will supersede a previous article.
  738. This is done simply by taking the old article and adding a Supersedes
  739. header line with the old Message-ID."
  740. (interactive)
  741. (let ((article (gnus-summary-article-number))
  742. (mail-parse-charset gnus-newsgroup-charset))
  743. (gnus-setup-message 'reply-yank
  744. (gnus-summary-select-article t)
  745. (set-buffer gnus-original-article-buffer)
  746. (message-supersede)
  747. (push
  748. `((lambda ()
  749. (when (gnus-buffer-exists-p ,gnus-summary-buffer)
  750. (with-current-buffer ,gnus-summary-buffer
  751. (gnus-cache-possibly-remove-article ,article nil nil nil t)
  752. (gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
  753. message-send-actions)
  754. ;; Add Gcc header.
  755. (gnus-inews-insert-gcc))))
  756. (defun gnus-copy-article-buffer (&optional article-buffer yank-string)
  757. ;; make a copy of the article buffer with all text properties removed
  758. ;; this copy is in the buffer gnus-article-copy.
  759. ;; if ARTICLE-BUFFER is nil, gnus-article-buffer is used
  760. ;; this buffer should be passed to all mail/news reply/post routines.
  761. (setq gnus-article-copy (gnus-get-buffer-create " *gnus article copy*"))
  762. (with-current-buffer gnus-article-copy
  763. (mm-enable-multibyte))
  764. (let ((article-buffer (or article-buffer gnus-article-buffer))
  765. end beg)
  766. (if (not (and (get-buffer article-buffer)
  767. (gnus-buffer-exists-p article-buffer)))
  768. (error "Can't find any article buffer")
  769. (with-current-buffer article-buffer
  770. (let ((gnus-newsgroup-charset (or gnus-article-charset
  771. gnus-newsgroup-charset))
  772. (gnus-newsgroup-ignored-charsets
  773. (or gnus-article-ignored-charsets
  774. gnus-newsgroup-ignored-charsets)))
  775. (save-restriction
  776. ;; Copy over the (displayed) article buffer, delete
  777. ;; hidden text and remove text properties.
  778. (widen)
  779. (copy-to-buffer gnus-article-copy (point-min) (point-max))
  780. (set-buffer gnus-article-copy)
  781. (when yank-string
  782. (message-goto-body)
  783. (delete-region (point) (point-max))
  784. (insert yank-string))
  785. (gnus-article-delete-text-of-type 'annotation)
  786. (gnus-article-delete-text-of-type 'multipart)
  787. (gnus-remove-text-with-property 'gnus-prev)
  788. (gnus-remove-text-with-property 'gnus-next)
  789. (gnus-remove-text-with-property 'gnus-decoration)
  790. (insert
  791. (prog1
  792. (buffer-substring-no-properties (point-min) (point-max))
  793. (erase-buffer)))
  794. ;; Find the original headers.
  795. (set-buffer gnus-original-article-buffer)
  796. (goto-char (point-min))
  797. (while (looking-at message-unix-mail-delimiter)
  798. (forward-line 1))
  799. (let ((mail-header-separator ""))
  800. (setq beg (point)
  801. end (or (message-goto-body)
  802. ;; There may be just a header.
  803. (point-max))))
  804. ;; Delete the headers from the displayed articles.
  805. (set-buffer gnus-article-copy)
  806. (let ((mail-header-separator ""))
  807. (delete-region (goto-char (point-min))
  808. (or (message-goto-body) (point-max))))
  809. ;; Insert the original article headers.
  810. (insert-buffer-substring gnus-original-article-buffer beg end)
  811. ;; Decode charsets.
  812. (let ((gnus-article-decode-hook
  813. (delq 'article-decode-charset
  814. (copy-sequence gnus-article-decode-hook)))
  815. (rfc2047-quote-decoded-words-containing-tspecials t))
  816. (run-hooks 'gnus-article-decode-hook)))))
  817. gnus-article-copy)))
  818. (defun gnus-post-news (post &optional group header article-buffer yank subject
  819. force-news)
  820. (when article-buffer
  821. (gnus-copy-article-buffer))
  822. (let ((gnus-article-reply (and article-buffer (gnus-summary-article-number)))
  823. (gnus-article-yanked-articles yank)
  824. (add-to-list gnus-add-to-list))
  825. (gnus-setup-message (cond (yank 'reply-yank)
  826. (article-buffer 'reply)
  827. (t 'message))
  828. (let* ((group (or group gnus-newsgroup-name))
  829. (charset (gnus-group-name-charset nil group))
  830. (pgroup group)
  831. to-address to-group mailing-list to-list
  832. newsgroup-p)
  833. (when group
  834. (setq to-address (gnus-parameter-to-address group)
  835. to-group (gnus-group-find-parameter group 'to-group)
  836. to-list (gnus-parameter-to-list group)
  837. newsgroup-p (gnus-group-find-parameter group 'newsgroup)
  838. mailing-list (when gnus-mailing-list-groups
  839. (string-match gnus-mailing-list-groups group))
  840. group (gnus-group-name-decode (gnus-group-real-name group)
  841. charset)))
  842. (if (or (and to-group
  843. (gnus-news-group-p to-group))
  844. newsgroup-p
  845. force-news
  846. (and (gnus-news-group-p
  847. (or pgroup gnus-newsgroup-name)
  848. (or header gnus-current-article))
  849. (not mailing-list)
  850. (not to-list)
  851. (not to-address)))
  852. ;; This is news.
  853. (if post
  854. (message-news
  855. (or to-group
  856. (and (not (gnus-virtual-group-p pgroup)) group)))
  857. (set-buffer gnus-article-copy)
  858. (gnus-msg-treat-broken-reply-to)
  859. (message-followup (if (or newsgroup-p force-news)
  860. (if (save-restriction
  861. (article-narrow-to-head)
  862. (message-fetch-field "newsgroups"))
  863. nil
  864. "")
  865. to-group)))
  866. ;; The is mail.
  867. (if post
  868. (progn
  869. (message-mail (or to-address to-list))
  870. ;; Arrange for mail groups that have no `to-address' to
  871. ;; get that when the user sends off the mail.
  872. (when (and (not to-list)
  873. (not to-address)
  874. add-to-list)
  875. (push (list 'gnus-inews-add-to-address pgroup)
  876. message-send-actions)))
  877. (set-buffer gnus-article-copy)
  878. (gnus-msg-treat-broken-reply-to)
  879. (message-wide-reply to-address)))
  880. (when yank
  881. (gnus-inews-yank-articles yank))))))
  882. (defun gnus-msg-treat-broken-reply-to (&optional force)
  883. "Remove the Reply-to header if broken-reply-to."
  884. (when (or force
  885. (gnus-group-find-parameter
  886. gnus-newsgroup-name 'broken-reply-to))
  887. (save-restriction
  888. (message-narrow-to-head)
  889. (message-remove-header "reply-to"))))
  890. (defun gnus-post-method (arg group &optional silent)
  891. "Return the posting method based on GROUP and ARG.
  892. If SILENT, don't prompt the user."
  893. (let ((gnus-post-method (or (gnus-parameter-post-method group)
  894. gnus-post-method))
  895. (group-method (gnus-find-method-for-group group)))
  896. (cond
  897. ;; If the group-method is nil (which shouldn't happen) we use
  898. ;; the default method.
  899. ((null group-method)
  900. (or (and (listp gnus-post-method) ;If not current/native/nil
  901. (not (listp (car gnus-post-method))) ; and not a list of methods
  902. gnus-post-method) ;then use it.
  903. gnus-select-method
  904. message-post-method))
  905. ;; We want the inverse of the default
  906. ((and arg (not (eq arg 0)))
  907. (if (eq gnus-post-method 'current)
  908. gnus-select-method
  909. group-method))
  910. ;; We query the user for a post method.
  911. ((or arg
  912. (and (listp gnus-post-method)
  913. (listp (car gnus-post-method))))
  914. (let* ((methods
  915. ;; Collect all methods we know about.
  916. (append
  917. (when (listp gnus-post-method)
  918. (if (listp (car gnus-post-method))
  919. gnus-post-method
  920. (list gnus-post-method)))
  921. gnus-secondary-select-methods
  922. (mapcar 'cdr gnus-server-alist)
  923. (mapcar 'car gnus-opened-servers)
  924. (list gnus-select-method)
  925. (list group-method)))
  926. method-alist post-methods method)
  927. ;; Weed out all mail methods.
  928. (while methods
  929. (setq method (gnus-server-get-method "" (pop methods)))
  930. (when (and (or (gnus-method-option-p method 'post)
  931. (gnus-method-option-p method 'post-mail))
  932. (not (member method post-methods)))
  933. (push method post-methods)))
  934. ;; Create a name-method alist.
  935. (setq method-alist
  936. (mapcar
  937. (lambda (m)
  938. (if (equal (cadr m) "")
  939. (list (symbol-name (car m)) m)
  940. (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)))
  941. post-methods))
  942. ;; Query the user.
  943. (cadr
  944. (assoc
  945. (setq gnus-last-posting-server
  946. (if (and silent
  947. gnus-last-posting-server)
  948. ;; Just use the last value.
  949. gnus-last-posting-server
  950. (gnus-completing-read
  951. "Posting method" (mapcar 'car method-alist) t
  952. (cons (or gnus-last-posting-server "") 0))))
  953. method-alist))))
  954. ;; Override normal method.
  955. ((and (eq gnus-post-method 'current)
  956. (not (memq (car group-method) gnus-discouraged-post-methods))
  957. (gnus-get-function group-method 'request-post t))
  958. (assert (not arg))
  959. group-method)
  960. ;; Use gnus-post-method.
  961. ((listp gnus-post-method) ;A method...
  962. (assert (not (listp (car gnus-post-method)))) ;... not a list of methods.
  963. gnus-post-method)
  964. ;; Use the normal select method (nil or native).
  965. (t gnus-select-method))))
  966. (defun gnus-extended-version ()
  967. "Stringified Gnus version and Emacs version.
  968. See the variable `gnus-user-agent'."
  969. (interactive)
  970. (if (stringp gnus-user-agent)
  971. gnus-user-agent
  972. ;; `gnus-user-agent' is a list:
  973. (let* ((float-output-format nil)
  974. (gnus-v
  975. (when (memq 'gnus gnus-user-agent)
  976. (concat "Gnus/"
  977. (prin1-to-string (gnus-continuum-version gnus-version) t)
  978. " (" gnus-version ")")))
  979. (emacs-v (gnus-emacs-version)))
  980. (concat gnus-v (when (and gnus-v emacs-v) " ")
  981. emacs-v))))
  982. ;;;
  983. ;;; Gnus Mail Functions
  984. ;;;
  985. ;;; Mail reply commands of Gnus summary mode
  986. (defun gnus-summary-reply (&optional yank wide very-wide)
  987. "Start composing a mail reply to the current message.
  988. If prefix argument YANK is non-nil, the original article is yanked
  989. automatically.
  990. If WIDE, make a wide reply.
  991. If VERY-WIDE, make a very wide reply."
  992. (interactive
  993. (list (and current-prefix-arg
  994. (gnus-summary-work-articles 1))))
  995. ;; Allow user to require confirmation before replying by mail to the
  996. ;; author of a news article (or mail message).
  997. (when (or (not (or (gnus-news-group-p gnus-newsgroup-name)
  998. gnus-confirm-treat-mail-like-news))
  999. (not (cond ((stringp gnus-confirm-mail-reply-to-news)
  1000. (string-match gnus-confirm-mail-reply-to-news
  1001. gnus-newsgroup-name))
  1002. ((functionp gnus-confirm-mail-reply-to-news)
  1003. (funcall gnus-confirm-mail-reply-to-news
  1004. gnus-newsgroup-name))
  1005. (t gnus-confirm-mail-reply-to-news)))
  1006. (if (or wide very-wide)
  1007. t ;; Ignore gnus-confirm-mail-reply-to-news for wide and very
  1008. ;; wide replies.
  1009. (y-or-n-p "Really reply by mail to article author? ")))
  1010. (let* ((article
  1011. (if (listp (car yank))
  1012. (caar yank)
  1013. (car yank)))
  1014. (gnus-article-reply (or article (gnus-summary-article-number)))
  1015. (gnus-article-yanked-articles yank)
  1016. (headers ""))
  1017. ;; Stripping headers should be specified with mail-yank-ignored-headers.
  1018. (when yank
  1019. (gnus-summary-goto-subject article))
  1020. (gnus-setup-message (if yank 'reply-yank 'reply)
  1021. (if (not very-wide)
  1022. (gnus-summary-select-article)
  1023. (dolist (article very-wide)
  1024. (gnus-summary-select-article nil nil nil article)
  1025. (with-current-buffer (gnus-copy-article-buffer)
  1026. (gnus-msg-treat-broken-reply-to)
  1027. (save-restriction
  1028. (message-narrow-to-head)
  1029. (setq headers (concat headers (buffer-string)))))))
  1030. (set-buffer (gnus-copy-article-buffer))
  1031. (gnus-msg-treat-broken-reply-to gnus-msg-force-broken-reply-to)
  1032. (save-restriction
  1033. (message-narrow-to-head)
  1034. (when very-wide
  1035. (erase-buffer)
  1036. (insert headers))
  1037. (goto-char (point-max)))
  1038. (mml-quote-region (point) (point-max))
  1039. (message-reply nil wide)
  1040. (when yank
  1041. (gnus-inews-yank-articles yank))
  1042. (gnus-summary-handle-replysign)))))
  1043. (defun gnus-summary-handle-replysign ()
  1044. "Check the various replysign variables and take action accordingly."
  1045. (when (or gnus-message-replysign gnus-message-replyencrypt)
  1046. (let (signed encrypted)
  1047. (with-current-buffer gnus-article-buffer
  1048. (setq signed (memq 'signed gnus-article-wash-types))
  1049. (setq encrypted (memq 'encrypted gnus-article-wash-types)))
  1050. (cond ((and gnus-message-replyencrypt encrypted)
  1051. (mml-secure-message mml-default-encrypt-method
  1052. (if gnus-message-replysignencrypted
  1053. 'signencrypt
  1054. 'encrypt)))
  1055. ((and gnus-message-replysign signed)
  1056. (mml-secure-message mml-default-sign-method 'sign))))))
  1057. (defun gnus-summary-reply-with-original (n &optional wide)
  1058. "Start composing a reply mail to the current message.
  1059. The original article will be yanked."
  1060. (interactive "P")
  1061. (gnus-summary-reply (gnus-summary-work-articles n) wide))
  1062. (defun gnus-summary-reply-to-list-with-original (n &optional wide)
  1063. "Start composing a reply mail to the current message.
  1064. The reply goes only to the mailing list.
  1065. The original article will be yanked."
  1066. (interactive "P")
  1067. (let ((message-reply-to-function
  1068. (lambda nil
  1069. `((To . ,(gnus-mailing-list-followup-to))))))
  1070. (gnus-summary-reply (gnus-summary-work-articles n) wide)))
  1071. (defun gnus-summary-reply-broken-reply-to (&optional yank wide very-wide)
  1072. "Like `gnus-summary-reply' except removing reply-to field.
  1073. If prefix argument YANK is non-nil, the original article is yanked
  1074. automatically.
  1075. If WIDE, make a wide reply.
  1076. If VERY-WIDE, make a very wide reply."
  1077. (interactive
  1078. (list (and current-prefix-arg
  1079. (gnus-summary-work-articles 1))))
  1080. (let ((gnus-msg-force-broken-reply-to t))
  1081. (gnus-summary-reply yank wide very-wide)))
  1082. (defun gnus-summary-reply-broken-reply-to-with-original (n &optional wide)
  1083. "Like `gnus-summary-reply-with-original' except removing reply-to field.
  1084. The original article will be yanked."
  1085. (interactive "P")
  1086. (gnus-summary-reply-broken-reply-to (gnus-summary-work-articles n) wide))
  1087. (defun gnus-summary-wide-reply (&optional yank)
  1088. "Start composing a wide reply mail to the current message.
  1089. If prefix argument YANK is non-nil, the original article is yanked
  1090. automatically."
  1091. (interactive
  1092. (list (and current-prefix-arg
  1093. (gnus-summary-work-articles 1))))
  1094. (gnus-summary-reply yank t))
  1095. (defun gnus-summary-wide-reply-with-original (n)
  1096. "Start composing a wide reply mail to the current message.
  1097. The original article will be yanked.
  1098. Uses the process/prefix convention."
  1099. (interactive "P")
  1100. (gnus-summary-reply-with-original n t))
  1101. (defun gnus-summary-very-wide-reply (&optional yank)
  1102. "Start composing a very wide reply mail to the current message.
  1103. If prefix argument YANK is non-nil, the original article is yanked
  1104. automatically."
  1105. (interactive
  1106. (list (and current-prefix-arg
  1107. (gnus-summary-work-articles 1))))
  1108. (gnus-summary-reply yank t (gnus-summary-work-articles yank)))
  1109. (defun gnus-summary-very-wide-reply-with-original (n)
  1110. "Start composing a very wide reply mail to the current message.
  1111. The original article will be yanked."
  1112. (interactive "P")
  1113. (gnus-summary-reply
  1114. (gnus-summary-work-articles n) t (gnus-summary-work-articles n)))
  1115. (defun gnus-summary-mail-forward (&optional arg post)
  1116. "Forward the current message(s) to another user.
  1117. If process marks exist, forward all marked messages;
  1118. if ARG is nil, see `message-forward-as-mime' and `message-forward-show-mml';
  1119. if ARG is 1, decode the message and forward directly inline;
  1120. if ARG is 2, forward message as an rfc822 MIME section;
  1121. if ARG is 3, decode message and forward as an rfc822 MIME section;
  1122. if ARG is 4, forward message directly inline;
  1123. otherwise, use flipped `message-forward-as-mime'.
  1124. If POST, post instead of mail.
  1125. For the \"inline\" alternatives, also see the variable
  1126. `message-forward-ignored-headers'."
  1127. (interactive "P")
  1128. (if (cdr (gnus-summary-work-articles nil))
  1129. ;; Process marks are given.
  1130. (gnus-uu-digest-mail-forward nil post)
  1131. ;; No process marks.
  1132. (let ((message-forward-as-mime message-forward-as-mime)
  1133. (message-forward-show-mml message-forward-show-mml))
  1134. (cond
  1135. ((null arg))
  1136. ((eq arg 1)
  1137. (setq message-forward-as-mime nil
  1138. message-forward-show-mml t))
  1139. ((eq arg 2)
  1140. (setq message-forward-as-mime t
  1141. message-forward-show-mml nil))
  1142. ((eq arg 3)
  1143. (setq message-forward-as-mime t
  1144. message-forward-show-mml t))
  1145. ((eq arg 4)
  1146. (setq message-forward-as-mime nil
  1147. message-forward-show-mml nil))
  1148. (t
  1149. (setq message-forward-as-mime (not message-forward-as-mime))))
  1150. (let* ((gnus-article-reply (gnus-summary-article-number))
  1151. (gnus-article-yanked-articles (list gnus-article-reply)))
  1152. (gnus-setup-message 'forward
  1153. (gnus-summary-select-article)
  1154. (let ((mail-parse-charset
  1155. (or (and (gnus-buffer-live-p gnus-article-buffer)
  1156. (with-current-buffer gnus-article-buffer
  1157. gnus-article-charset))
  1158. gnus-newsgroup-charset))
  1159. (mail-parse-ignored-charsets
  1160. gnus-newsgroup-ignored-charsets))
  1161. (set-buffer gnus-original-article-buffer)
  1162. (message-forward post)))))))
  1163. (defun gnus-summary-resend-message (address n)
  1164. "Resend the current article to ADDRESS."
  1165. (interactive
  1166. (list (message-read-from-minibuffer
  1167. "Resend message(s) to: "
  1168. (when (and gnus-summary-resend-default-address
  1169. (gnus-buffer-live-p gnus-original-article-buffer))
  1170. ;; If some other article is currently selected, the
  1171. ;; initial-contents is wrong. Whatever, it is just the
  1172. ;; initial-contents.
  1173. (with-current-buffer gnus-original-article-buffer
  1174. (nnmail-fetch-field "to"))))
  1175. current-prefix-arg))
  1176. (dolist (article (gnus-summary-work-articles n))
  1177. (gnus-summary-select-article nil nil nil article)
  1178. (with-current-buffer gnus-original-article-buffer
  1179. (let ((gnus-gcc-externalize-attachments nil))
  1180. (message-resend address)))
  1181. (gnus-summary-mark-article-as-forwarded article)))
  1182. ;; From: Matthieu Moy <Matthieu.Moy@imag.fr>
  1183. (defun gnus-summary-resend-message-edit ()
  1184. "Resend an article that has already been sent.
  1185. A new buffer will be created to allow the user to modify body and
  1186. contents of the message, and then, everything will happen as when
  1187. composing a new message."
  1188. (interactive)
  1189. (let ((mail-parse-charset gnus-newsgroup-charset))
  1190. (gnus-setup-message 'reply-yank
  1191. (gnus-summary-select-article t)
  1192. (set-buffer gnus-original-article-buffer)
  1193. (let ((cur (current-buffer))
  1194. (to (message-fetch-field "to")))
  1195. ;; Get a normal message buffer.
  1196. (message-pop-to-buffer (message-buffer-name "Resend" to))
  1197. (insert-buffer-substring cur)
  1198. (mime-to-mml)
  1199. (message-narrow-to-head-1)
  1200. ;; Gnus will generate a new one when sending.
  1201. (message-remove-header "Message-ID")
  1202. ;; Remove unwanted headers.
  1203. (message-remove-header message-ignored-resent-headers t)
  1204. (goto-char (point-max))
  1205. (insert mail-header-separator)
  1206. ;; Add Gcc header.
  1207. (gnus-inews-insert-gcc)
  1208. (goto-char (point-min))
  1209. (when (re-search-forward "^To:\\|^Newsgroups:" nil 'move)
  1210. (forward-char 1))
  1211. (widen)))))
  1212. (defun gnus-summary-post-forward (&optional arg)
  1213. "Forward the current article to a newsgroup.
  1214. See `gnus-summary-mail-forward' for ARG."
  1215. (interactive "P")
  1216. (gnus-summary-mail-forward arg t))
  1217. (defun gnus-summary-mail-crosspost-complaint (n)
  1218. "Send a complaint about crossposting to the current article(s)."
  1219. (interactive "P")
  1220. (dolist (article (gnus-summary-work-articles n))
  1221. (set-buffer gnus-summary-buffer)
  1222. (gnus-summary-goto-subject article)
  1223. (let ((group (gnus-group-real-name gnus-newsgroup-name))
  1224. newsgroups followup-to)
  1225. (gnus-summary-select-article)
  1226. (set-buffer gnus-original-article-buffer)
  1227. (if (and (<= (length (message-tokenize-header
  1228. (setq newsgroups
  1229. (mail-fetch-field "newsgroups"))
  1230. ", "))
  1231. 1)
  1232. (or (not (setq followup-to (mail-fetch-field "followup-to")))
  1233. (not (member group (message-tokenize-header
  1234. followup-to ", ")))))
  1235. (if followup-to
  1236. (gnus-message 1 "Followup-to restricted")
  1237. (gnus-message 1 "Not a crossposted article"))
  1238. (set-buffer gnus-summary-buffer)
  1239. (gnus-summary-reply-with-original 1)
  1240. (set-buffer gnus-message-buffer)
  1241. (message-goto-body)
  1242. (insert (format gnus-crosspost-complaint newsgroups group))
  1243. (message-goto-subject)
  1244. (re-search-forward " *$")
  1245. (replace-match " (crosspost notification)" t t)
  1246. (gnus-deactivate-mark)
  1247. (when (gnus-y-or-n-p "Send this complaint? ")
  1248. (message-send-and-exit))))))
  1249. (defun gnus-mail-parse-comma-list ()
  1250. (let (accumulated
  1251. beg)
  1252. (skip-chars-forward " ")
  1253. (while (not (eobp))
  1254. (setq beg (point))
  1255. (skip-chars-forward "^,")
  1256. (while (zerop
  1257. (save-excursion
  1258. (save-restriction
  1259. (let ((i 0))
  1260. (narrow-to-region beg (point))
  1261. (goto-char beg)
  1262. (logand (progn
  1263. (while (search-forward "\"" nil t)
  1264. (incf i))
  1265. (if (zerop i) 2 i))
  1266. 2)))))
  1267. (skip-chars-forward ",")
  1268. (skip-chars-forward "^,"))
  1269. (skip-chars-backward " ")
  1270. (push (buffer-substring beg (point))
  1271. accumulated)
  1272. (skip-chars-forward "^,")
  1273. (skip-chars-forward ", "))
  1274. accumulated))
  1275. (defun gnus-inews-add-to-address (group)
  1276. (let ((to-address (mail-fetch-field "to")))
  1277. (when (and to-address
  1278. (gnus-alive-p))
  1279. ;; This mail group doesn't have a `to-list', so we add one
  1280. ;; here. Magic!
  1281. (when (gnus-y-or-n-p
  1282. (format "Do you want to add this as `to-list': %s? " to-address))
  1283. (gnus-group-add-parameter group (cons 'to-list to-address))))))
  1284. (defun gnus-put-message ()
  1285. "Put the current message in some group and return to Gnus."
  1286. (interactive)
  1287. (let ((reply gnus-article-reply)
  1288. (winconf gnus-prev-winconf)
  1289. (group gnus-newsgroup-name))
  1290. (unless (and group
  1291. (not (gnus-group-read-only-p group)))
  1292. (setq group (read-string "Put in group: " nil (gnus-writable-groups))))
  1293. (when (gnus-group-entry group)
  1294. (error "No such group: %s" group))
  1295. (save-excursion
  1296. (save-restriction
  1297. (widen)
  1298. (message-narrow-to-headers)
  1299. (let ((gnus-deletable-headers nil))
  1300. (message-generate-headers
  1301. (if (message-news-p)
  1302. message-required-news-headers
  1303. message-required-mail-headers)))
  1304. (goto-char (point-max))
  1305. (if (string-match " " group)
  1306. (insert "Gcc: \"" group "\"\n")
  1307. (insert "Gcc: " group "\n"))
  1308. (widen)))
  1309. (gnus-inews-do-gcc)
  1310. (when (and (get-buffer gnus-group-buffer)
  1311. (gnus-buffer-exists-p (car-safe reply))
  1312. (cdr reply))
  1313. (set-buffer (car reply))
  1314. (gnus-summary-mark-article-as-replied (cdr reply)))
  1315. (when winconf
  1316. (set-window-configuration winconf))))
  1317. (defun gnus-article-mail (yank)
  1318. "Send a reply to the address near point.
  1319. If YANK is non-nil, include the original article."
  1320. (interactive "P")
  1321. (let ((address
  1322. (buffer-substring
  1323. (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point)))
  1324. (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point))))))
  1325. (when address
  1326. (gnus-msg-mail address)
  1327. (when yank
  1328. (gnus-inews-yank-articles (list (cdr gnus-article-current)))))))
  1329. (defvar nntp-server-type)
  1330. (defun gnus-bug ()
  1331. "Send a bug report to the Gnus maintainers."
  1332. (interactive)
  1333. (unless (gnus-alive-p)
  1334. (error "Gnus has been shut down"))
  1335. (gnus-setup-message (if (message-mail-user-agent) 'message 'bug)
  1336. (unless (message-mail-user-agent)
  1337. (when gnus-bug-create-help-buffer
  1338. (switch-to-buffer "*Gnus Help Bug*")
  1339. (erase-buffer)
  1340. (insert gnus-bug-message)
  1341. (goto-char (point-min)))
  1342. (message-pop-to-buffer "*Gnus Bug*"))
  1343. (let ((message-this-is-mail t))
  1344. (message-setup `((To . ,gnus-maintainer)
  1345. (Subject . "")
  1346. (X-Debbugs-Package
  1347. . ,(format "%s" gnus-bug-package))
  1348. (X-Debbugs-Version
  1349. . ,(format "%s" (gnus-continuum-version))))))
  1350. (when gnus-bug-create-help-buffer
  1351. (push `(gnus-bug-kill-buffer) message-send-actions))
  1352. (goto-char (point-min))
  1353. (message-goto-body)
  1354. (insert "\n\n\n\n\n")
  1355. (insert (gnus-version) "\n"
  1356. (emacs-version) "\n")
  1357. (when (and (boundp 'nntp-server-type)
  1358. (stringp nntp-server-type))
  1359. (insert nntp-server-type))
  1360. (goto-char (point-min))
  1361. (search-forward "Subject: " nil t)
  1362. (message "")))
  1363. (defun gnus-bug-kill-buffer ()
  1364. (when (get-buffer "*Gnus Help Bug*")
  1365. (kill-buffer "*Gnus Help Bug*")))
  1366. (defun gnus-summary-yank-message (buffer n)
  1367. "Yank the current article into a composed message."
  1368. (interactive
  1369. (list (gnus-completing-read "Buffer" (message-buffers) t)
  1370. current-prefix-arg))
  1371. (gnus-summary-iterate n
  1372. (let ((gnus-inhibit-treatment t))
  1373. (gnus-summary-select-article))
  1374. (with-current-buffer buffer
  1375. (message-yank-buffer gnus-article-buffer))))
  1376. ;;; Treatment of rejected articles.
  1377. ;;; Bounced mail.
  1378. (defun gnus-summary-resend-bounced-mail (&optional fetch)
  1379. "Re-mail the current message.
  1380. This only makes sense if the current message is a bounce message that
  1381. contains some mail you have written which has been bounced back to
  1382. you.
  1383. If FETCH, try to fetch the article that this is a reply to, if indeed
  1384. this is a reply."
  1385. (interactive "P")
  1386. (gnus-summary-select-article t)
  1387. (let (summary-buffer parent)
  1388. (if fetch
  1389. (progn
  1390. (setq summary-buffer (current-buffer))
  1391. (set-buffer gnus-original-article-buffer)
  1392. (article-goto-body)
  1393. (when (re-search-forward "^References:\n?" nil t)
  1394. (while (memq (char-after) '(?\t ? ))
  1395. (forward-line 1))
  1396. (skip-chars-backward "\t\n ")
  1397. (setq parent
  1398. (gnus-parent-id (buffer-substring (match-end 0) (point))))))
  1399. (set-buffer gnus-original-article-buffer))
  1400. (gnus-setup-message 'compose-bounce
  1401. (message-bounce)
  1402. ;; Add Gcc header.
  1403. (gnus-inews-insert-gcc)
  1404. ;; If there are references, we fetch the article we answered to.
  1405. (when parent
  1406. (with-current-buffer summary-buffer
  1407. (gnus-summary-refer-article parent)
  1408. (gnus-summary-show-all-headers))))))
  1409. ;;; Gcc handling.
  1410. (defun gnus-inews-group-method (group)
  1411. (cond
  1412. ;; If the group doesn't exist, we assume
  1413. ;; it's an archive group...
  1414. ((and (null (gnus-get-info group))
  1415. (eq (car (gnus-server-to-method gnus-message-archive-method))
  1416. (car (gnus-server-to-method (gnus-group-method group)))))
  1417. gnus-message-archive-method)
  1418. ;; Use the method.
  1419. ((gnus-info-method (gnus-get-info group))
  1420. (gnus-info-method (gnus-get-info group)))
  1421. ;; Find the method.
  1422. (t (gnus-server-to-method (gnus-group-method group)))))
  1423. ;; Do Gcc handling, which copied the message over to some group.
  1424. (defun gnus-inews-do-gcc (&optional gcc)
  1425. (interactive)
  1426. (save-excursion
  1427. (save-restriction
  1428. (message-narrow-to-headers)
  1429. (let ((gcc (or gcc (mail-fetch-field "gcc" nil t)))
  1430. (cur (current-buffer))
  1431. groups group method group-art options
  1432. mml-externalize-attachments)
  1433. (when gcc
  1434. (message-remove-header "gcc")
  1435. (widen)
  1436. (setq groups (message-unquote-tokens
  1437. (message-tokenize-header gcc " ,")))
  1438. ;; Copy the article over to some group(s).
  1439. (while (setq group (pop groups))
  1440. (setq method (gnus-inews-group-method group)
  1441. group (mm-encode-coding-string
  1442. group
  1443. (gnus-group-name-charset method group)))
  1444. (unless (gnus-check-server method)
  1445. (error "Can't open server %s" (if (stringp method) method
  1446. (car method))))
  1447. (unless (gnus-request-group group t method)
  1448. (gnus-request-create-group group method))
  1449. (setq mml-externalize-attachments
  1450. (if (stringp gnus-gcc-externalize-attachments)
  1451. (string-match gnus-gcc-externalize-attachments group)
  1452. gnus-gcc-externalize-attachments))
  1453. (save-excursion
  1454. (nnheader-set-temp-buffer " *acc*")
  1455. (setq message-options (with-current-buffer cur message-options))
  1456. (insert-buffer-substring cur)
  1457. (message-encode-message-body)
  1458. (save-restriction
  1459. (message-narrow-to-headers)
  1460. (let* ((mail-parse-charset message-default-charset)
  1461. (newsgroups-field (save-restriction
  1462. (message-narrow-to-headers-or-head)
  1463. (message-fetch-field "Newsgroups")))
  1464. (followup-field (save-restriction
  1465. (message-narrow-to-headers-or-head)
  1466. (message-fetch-field "Followup-To")))
  1467. ;; BUG: We really need to get the charset for
  1468. ;; each name in the Newsgroups and Followup-To
  1469. ;; lines to allow crossposting between group
  1470. ;; names with incompatible character sets.
  1471. ;; -- Per Abrahamsen <abraham@dina.kvl.dk> 2001-10-08.
  1472. (group-field-charset
  1473. (gnus-group-name-charset
  1474. method (or newsgroups-field "")))
  1475. (followup-field-charset
  1476. (gnus-group-name-charset
  1477. method (or followup-field "")))
  1478. (rfc2047-header-encoding-alist
  1479. (append
  1480. (when group-field-charset
  1481. (list (cons "Newsgroups" group-field-charset)))
  1482. (when followup-field-charset
  1483. (list (cons "Followup-To" followup-field-charset)))
  1484. rfc2047-header-encoding-alist)))
  1485. (mail-encode-encoded-word-buffer)))
  1486. (goto-char (point-min))
  1487. (when (re-search-forward
  1488. (concat "^" (regexp-quote mail-header-separator) "$")
  1489. nil t)
  1490. (replace-match "" t t ))
  1491. (when (or (not (gnus-check-backend-function
  1492. 'request-accept-article group))
  1493. (not (setq group-art
  1494. (gnus-request-accept-article
  1495. group method t t))))
  1496. (gnus-message 1 "Couldn't store article in group %s: %s"
  1497. group (gnus-status-message method)))
  1498. (when (stringp method)
  1499. (setq method (gnus-server-to-method method)))
  1500. (when (and (listp method)
  1501. (gnus-native-method-p method))
  1502. (setq group (gnus-group-short-name group)))
  1503. (when (and group-art
  1504. ;; FIXME: Should gcc-mark-as-read work when
  1505. ;; Gnus is not running?
  1506. (gnus-alive-p)
  1507. (or gnus-gcc-mark-as-read
  1508. (and
  1509. (boundp 'gnus-inews-mark-gcc-as-read)
  1510. (symbol-value 'gnus-inews-mark-gcc-as-read))))
  1511. (gnus-group-mark-article-read group (cdr group-art)))
  1512. (setq options message-options)
  1513. (with-current-buffer cur (setq message-options options))
  1514. (kill-buffer (current-buffer)))))))))
  1515. (defun gnus-inews-insert-gcc (&optional group)
  1516. "Insert the Gcc to say where the article is to be archived."
  1517. (let* ((group (or group gnus-newsgroup-name))
  1518. (group (when group (gnus-group-decoded-name group)))
  1519. (var (or gnus-outgoing-message-group gnus-message-archive-group))
  1520. (gcc-self-val
  1521. (and group (gnus-group-find-parameter group 'gcc-self)))
  1522. result
  1523. (groups
  1524. (cond
  1525. ((null gnus-message-archive-method)
  1526. ;; Ignore.
  1527. nil)
  1528. ((stringp var)
  1529. ;; Just a single group.
  1530. (list var))
  1531. ((null var)
  1532. ;; We don't want this.
  1533. nil)
  1534. ((and (listp var) (stringp (car var)))
  1535. ;; A list of groups.
  1536. var)
  1537. ((functionp var)
  1538. ;; A function.
  1539. (funcall var group))
  1540. (group
  1541. ;; An alist of regexps/functions/forms.
  1542. (while (and var
  1543. (not
  1544. (setq result
  1545. (cond
  1546. ((and group
  1547. (stringp (caar var)))
  1548. ;; Regexp.
  1549. (when (string-match (caar var) group)
  1550. (cdar var)))
  1551. ((and group
  1552. (functionp (car var)))
  1553. ;; Function.
  1554. (funcall (car var) group))
  1555. (t
  1556. (eval (car var)))))))
  1557. (setq var (cdr var)))
  1558. result)))
  1559. name)
  1560. (when (or groups gcc-self-val)
  1561. (when (stringp groups)
  1562. (setq groups (list groups)))
  1563. (save-excursion
  1564. (save-restriction
  1565. (message-narrow-to-headers)
  1566. (goto-char (point-max))
  1567. (insert "Gcc: ")
  1568. (if gcc-self-val
  1569. ;; Use the `gcc-self' param value instead.
  1570. (progn
  1571. (insert
  1572. (if (stringp gcc-self-val)
  1573. (if (string-match " " gcc-self-val)
  1574. (concat "\"" gcc-self-val "\"")
  1575. gcc-self-val)
  1576. ;; In nndoc groups, we use the parent group name
  1577. ;; instead of the current group.
  1578. (let ((group (or (gnus-group-find-parameter
  1579. gnus-newsgroup-name 'parent-group)
  1580. group)))
  1581. (if (string-match " " group)
  1582. (concat "\"" group "\"")
  1583. group))))
  1584. (if (not (eq gcc-self-val 'none))
  1585. (insert "\n")
  1586. (gnus-delete-line)))
  1587. ;; Use the list of groups.
  1588. (while (setq name (pop groups))
  1589. (let ((str (if (string-match ":" name)
  1590. name
  1591. (gnus-group-prefixed-name
  1592. name gnus-message-archive-method))))
  1593. (insert (if (string-match " " str)
  1594. (concat "\"" str "\"")
  1595. str)))
  1596. (when groups
  1597. (insert " ")))
  1598. (insert "\n")))))))
  1599. (defun gnus-mailing-list-followup-to ()
  1600. "Look at the headers in the current buffer and return a Mail-Followup-To address."
  1601. (let ((x-been-there (gnus-fetch-original-field "x-beenthere"))
  1602. (list-post (gnus-fetch-original-field "list-post")))
  1603. (when (and list-post
  1604. (string-match "mailto:\\([^>]+\\)" list-post))
  1605. (setq list-post (match-string 1 list-post)))
  1606. (or list-post
  1607. x-been-there)))
  1608. ;;; Posting styles.
  1609. (defun gnus-configure-posting-styles (&optional group-name)
  1610. "Configure posting styles according to `gnus-posting-styles'."
  1611. (unless gnus-inhibit-posting-styles
  1612. (let ((group (or group-name gnus-newsgroup-name ""))
  1613. (styles (if (gnus-buffer-live-p gnus-summary-buffer)
  1614. (with-current-buffer gnus-summary-buffer
  1615. gnus-posting-styles)
  1616. gnus-posting-styles))
  1617. style match attribute value v results
  1618. filep name address element)
  1619. ;; If the group has a posting-style parameter, add it at the end with a
  1620. ;; regexp matching everything, to be sure it takes precedence over all
  1621. ;; the others.
  1622. (when gnus-newsgroup-name
  1623. (let ((tmp-style (gnus-group-find-parameter group 'posting-style t)))
  1624. (when tmp-style
  1625. (setq styles (append styles (list (cons ".*" tmp-style)))))))
  1626. ;; Go through all styles and look for matches.
  1627. (dolist (style styles)
  1628. (setq match (pop style))
  1629. (goto-char (point-min))
  1630. (when (cond
  1631. ((stringp match)
  1632. ;; Regexp string match on the group name.
  1633. (string-match match group))
  1634. ((eq match 'header)
  1635. ;; Obsolete format of header match.
  1636. (and (gnus-buffer-live-p gnus-article-copy)
  1637. (with-current-buffer gnus-article-copy
  1638. (save-restriction
  1639. (nnheader-narrow-to-headers)
  1640. (let ((header (message-fetch-field (pop style))))
  1641. (and header
  1642. (string-match (pop style) header)))))))
  1643. ((or (symbolp match)
  1644. (functionp match))
  1645. (cond
  1646. ((functionp match)
  1647. ;; Function to be called.
  1648. (funcall match))
  1649. ((boundp match)
  1650. ;; Variable to be checked.
  1651. (symbol-value match))))
  1652. ((listp match)
  1653. (cond
  1654. ((eq (car match) 'header)
  1655. ;; New format of header match.
  1656. (and (gnus-buffer-live-p gnus-article-copy)
  1657. (with-current-buffer gnus-article-copy
  1658. (save-restriction
  1659. (nnheader-narrow-to-headers)
  1660. (let ((header (message-fetch-field (nth 1 match))))
  1661. (and header
  1662. (string-match (nth 2 match) header)))))))
  1663. (t
  1664. ;; This is a form to be evalled.
  1665. (eval match)))))
  1666. ;; We have a match, so we set the variables.
  1667. (dolist (attribute style)
  1668. (setq element (pop attribute)
  1669. filep nil)
  1670. (setq value
  1671. (cond
  1672. ((eq (car attribute) :file)
  1673. (setq filep t)
  1674. (cadr attribute))
  1675. ((eq (car attribute) :value)
  1676. (cadr attribute))
  1677. (t
  1678. (car attribute))))
  1679. ;; We get the value.
  1680. (setq v
  1681. (cond
  1682. ((stringp value)
  1683. (if (and (stringp match)
  1684. (gnus-string-match-p "\\\\[&[:digit:]]" value)
  1685. (match-beginning 1))
  1686. (gnus-match-substitute-replacement value nil nil group)
  1687. value))
  1688. ((or (symbolp value)
  1689. (functionp value))
  1690. (cond ((functionp value)
  1691. (funcall value))
  1692. ((boundp value)
  1693. (symbol-value value))))
  1694. ((listp value)
  1695. (eval value))))
  1696. ;; Translate obsolescent value.
  1697. (cond
  1698. ((eq element 'signature-file)
  1699. (setq element 'signature
  1700. filep t))
  1701. ((eq element 'x-face-file)
  1702. (setq element 'x-face
  1703. filep t)))
  1704. ;; Post-processing for the signature posting-style:
  1705. (and (eq element 'signature) filep
  1706. message-signature-directory
  1707. ;; don't actually use the signature directory
  1708. ;; if message-signature-file contains a path.
  1709. (not (file-name-directory v))
  1710. (setq v (nnheader-concat message-signature-directory v)))
  1711. ;; Get the contents of file elems.
  1712. (when (and filep v)
  1713. (setq v (with-temp-buffer
  1714. (insert-file-contents v)
  1715. (buffer-substring
  1716. (point-min)
  1717. (progn
  1718. (goto-char (point-max))
  1719. (if (zerop (skip-chars-backward "\n"))
  1720. (point)
  1721. (1+ (point))))))))
  1722. (setq results (delq (assoc element results) results))
  1723. (push (cons element v) results))))
  1724. ;; Now we have all the styles, so we insert them.
  1725. (setq name (assq 'name results)
  1726. address (assq 'address results))
  1727. (setq results (delq name (delq address results)))
  1728. (gnus-make-local-hook 'message-setup-hook)
  1729. (setq results (sort results (lambda (x y)
  1730. (string-lessp (car x) (car y)))))
  1731. (dolist (result results)
  1732. (add-hook 'message-setup-hook
  1733. (cond
  1734. ((eq 'eval (car result))
  1735. 'ignore)
  1736. ((eq 'body (car result))
  1737. `(lambda ()
  1738. (save-excursion
  1739. (message-goto-body)
  1740. (insert ,(cdr result)))))
  1741. ((eq 'signature (car result))
  1742. (set (make-local-variable 'message-signature) nil)
  1743. (set (make-local-variable 'message-signature-file) nil)
  1744. (if (not (cdr result))
  1745. 'ignore
  1746. `(lambda ()
  1747. (save-excursion
  1748. (let ((message-signature ,(cdr result)))
  1749. (when message-signature
  1750. (message-insert-signature)))))))
  1751. (t
  1752. (let ((header
  1753. (if (symbolp (car result))
  1754. (capitalize (symbol-name (car result)))
  1755. (car result))))
  1756. `(lambda ()
  1757. (save-excursion
  1758. (message-remove-header ,header)
  1759. (let ((value ,(cdr result)))
  1760. (when value
  1761. (message-goto-eoh)
  1762. (insert ,header ": " value)
  1763. (unless (bolp)
  1764. (insert "\n")))))))))
  1765. nil 'local))
  1766. (when (or name address)
  1767. (add-hook 'message-setup-hook
  1768. `(lambda ()
  1769. (set (make-local-variable 'user-mail-address)
  1770. ,(or (cdr address) user-mail-address))
  1771. (let ((user-full-name ,(or (cdr name) (user-full-name)))
  1772. (user-mail-address
  1773. ,(or (cdr address) user-mail-address)))
  1774. (save-excursion
  1775. (message-remove-header "From")
  1776. (message-goto-eoh)
  1777. (insert "From: " (message-make-from) "\n"))))
  1778. nil 'local)))))
  1779. ;;; Allow redefinition of functions.
  1780. (gnus-ems-redefine)
  1781. (provide 'gnus-msg)
  1782. ;;; gnus-msg.el ends here