gnus-msg.el 70 KB

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