nngateway.el 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. ;;; nngateway.el --- posting news via mail gateways
  2. ;; Copyright (C) 1996-2012 Free Software Foundation, Inc.
  3. ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
  4. ;; Keywords: news, mail
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;;; Code:
  18. (eval-when-compile (require 'cl))
  19. (require 'nnoo)
  20. (require 'message)
  21. (nnoo-declare nngateway)
  22. (defvoo nngateway-address nil
  23. "Address of the mail-to-news gateway.")
  24. (defvoo nngateway-header-transformation 'nngateway-simple-header-transformation
  25. "Function to be called to rewrite the news headers into mail headers.
  26. It is called narrowed to the headers to be transformed with one
  27. parameter -- the gateway address.")
  28. ;;; Interface functions
  29. (nnoo-define-basics nngateway)
  30. (deffoo nngateway-open-server (server &optional defs)
  31. (if (nngateway-server-opened server)
  32. t
  33. (unless (assq 'nngateway-address defs)
  34. (setq defs (append defs (list (list 'nngateway-address server)))))
  35. (nnoo-change-server 'nngateway server defs)))
  36. (deffoo nngateway-request-post (&optional server)
  37. (when (or (nngateway-server-opened server)
  38. (nngateway-open-server server))
  39. ;; Rewrite the header.
  40. (let ((buf (current-buffer)))
  41. (with-temp-buffer
  42. (insert-buffer-substring buf)
  43. (message-narrow-to-head)
  44. (funcall nngateway-header-transformation nngateway-address)
  45. (goto-char (point-max))
  46. (insert mail-header-separator "\n")
  47. (widen)
  48. (let (message-required-mail-headers)
  49. (funcall (or message-send-mail-real-function
  50. message-send-mail-function)))
  51. t))))
  52. ;;; Internal functions
  53. (defun nngateway-simple-header-transformation (gateway)
  54. "Transform the headers to use GATEWAY."
  55. (let ((newsgroups (mail-fetch-field "newsgroups")))
  56. (message-remove-header "to")
  57. (message-remove-header "cc")
  58. (goto-char (point-min))
  59. (insert "To: " (nnheader-replace-chars-in-string newsgroups ?. ?-)
  60. "@" gateway "\n")))
  61. (defun nngateway-mail2news-header-transformation (gateway)
  62. "Transform the headers for sending to a mail2news gateway."
  63. (message-remove-header "to")
  64. (message-remove-header "cc")
  65. (goto-char (point-min))
  66. (insert "To: " gateway "\n"))
  67. (nnoo-define-skeleton nngateway)
  68. (provide 'nngateway)
  69. ;;; nngateway.el ends here