Fix doc.
[gnus] / lisp / hashcash.el
index d4d556a..9bcf449 100644 (file)
@@ -1,6 +1,6 @@
 ;;; hashcash.el --- Add hashcash payments to email
 
-;; Copyright (C) 2003, 2004, 2005 Free Software Foundation
+;; Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009  Free Software Foundation
 
 ;; Written by: Paul Foley <mycroft@actrix.gen.nz> (1997-2002)
 ;; Maintainer: Paul Foley <mycroft@actrix.gen.nz>
@@ -8,20 +8,18 @@
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
 
 ;;; Code:
 
+(eval-and-compile
+  (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
+
+(eval-when-compile (require 'cl))      ; for case
+
 (defgroup hashcash nil
   "Hashcash configuration."
   :group 'mail)
@@ -112,13 +115,15 @@ For example, you may want to set this to '(\"-Z2\") to reduce header length."
 (require 'mail-utils)
 
 (eval-and-compile
- (if (fboundp 'point-at-bol)
-     (defalias 'hashcash-point-at-bol 'point-at-bol)
-   (defalias 'hashcash-point-at-bol 'line-beginning-position))
+  (unless (fboundp 'declare-function) (defmacro declare-function (&rest r)))
 
- (if (fboundp 'point-at-eol)
-     (defalias 'hashcash-point-at-eol 'point-at-eol)
-   (defalias 'hashcash-point-at-eol 'line-end-position)))
+  (if (fboundp 'point-at-bol)
+      (defalias 'hashcash-point-at-bol 'point-at-bol)
+    (defalias 'hashcash-point-at-bol 'line-beginning-position))
+
+  (if (fboundp 'point-at-eol)
+      (defalias 'hashcash-point-at-eol 'point-at-eol)
+    (defalias 'hashcash-point-at-eol 'line-end-position)))
 
 (defun hashcash-strip-quoted-names (addr)
   (setq addr (mail-strip-quoted-names addr))
@@ -126,6 +131,11 @@ For example, you may want to set this to '(\"-Z2\") to reduce header length."
       (concat (match-string 1 addr) (match-string 2 addr))
     addr))
 
+(declare-function  message-narrow-to-headers-or-head "message" ())
+(declare-function  message-fetch-field "message" (header &optional not-all))
+(declare-function  message-goto-eoh "message" ())
+(declare-function  message-narrow-to-headers "message" ())
+
 (defun hashcash-token-substring ()
   (save-excursion
     (let ((token ""))
@@ -164,7 +174,8 @@ For example, you may want to set this to '(\"-Z2\") to reduce header length."
 (defun hashcash-generate-payment-async (str val callback)
   "Generate a hashcash payment by finding a VAL-bit collison on STR.
 Return immediately.  Call CALLBACK with process and result when ready."
-  (if (> val 0)
+  (if (and (> val 0)
+          hashcash-path)
       (let ((process (apply 'start-process "hashcash" nil
                            hashcash-path "-m" "-q"
                            "-b" (number-to-string val) str
@@ -174,7 +185,7 @@ Return immediately.  Call CALLBACK with process and result when ready."
                                      hashcash-process-alist))
        (set-process-filter process `(lambda (process output)
                                       (funcall ,callback process output))))
-    (funcall callback nil)))
+    (funcall callback nil nil)))
 
 (defun hashcash-check-payment (token str val)
   "Check the validity of a hashcash payment."
@@ -238,15 +249,16 @@ Only start calculation.  Results are inserted when ready."
        (hashcash-insert-payment-async-2 ,(current-buffer) process payment)))))
 
 (defun hashcash-insert-payment-async-2 (buffer process pay)
-  (with-current-buffer buffer
-    (save-excursion
-      (save-restriction
-       (setq hashcash-process-alist (delq
-                                     (assq process hashcash-process-alist)
-                                     hashcash-process-alist))
-       (message-goto-eoh)
-       (when pay
-         (insert-before-markers "X-Hashcash: " pay))))))
+  (when (buffer-live-p buffer)
+    (with-current-buffer buffer
+      (save-excursion
+       (save-restriction
+         (setq hashcash-process-alist (delq
+                                       (assq process hashcash-process-alist)
+                                       hashcash-process-alist))
+         (message-goto-eoh)
+         (when pay
+           (insert-before-markers "X-Hashcash: " pay)))))))
 
 (defun hashcash-cancel-async (&optional buffer)
   "Delete any hashcash processes associated with BUFFER.
@@ -323,10 +335,10 @@ Set ASYNC to t to start asynchronous calculation.  (See
          (when (and hashcash-in-news ng)
            (setq addrlist (nconc addrlist (split-string ng ",[ \t\n]*")))))
        (when addrlist
-         (mapcar (if async
-                     #'hashcash-insert-payment-async
-                   #'hashcash-insert-payment)
-                 addrlist))))) ; mapc
+         (mapc (if async
+                   #'hashcash-insert-payment-async
+                 #'hashcash-insert-payment)
+               addrlist)))))
   t)
 
 ;;;###autoload
@@ -365,4 +377,4 @@ Prefix arg sets default accept amount temporarily."
 
 (provide 'hashcash)
 
-;;; arch-tag: 0e7fe983-a124-4392-9788-0dbcbd2c4d62
+;; arch-tag: 0e7fe983-a124-4392-9788-0dbcbd2c4d62