+;;;###autoload
+(defun mail-check-payment (&optional arg)
+ "Look for a valid X-Payment: or X-Hashcash: header.
+Prefix arg sets default accept amount temporarily."
+ (interactive "P")
+ (let ((hashcash-default-accept-payment (if arg (prefix-numeric-value arg)
+ hashcash-default-accept-payment))
+ (version (hashcash-version (hashcash-generate-payment "x" 1))))
+ (save-excursion
+ (goto-char (point-min))
+ (search-forward "\n\n")
+ (beginning-of-line)
+ (let ((end (point))
+ (ok nil))
+ (goto-char (point-min))
+ (while (and (not ok) (search-forward "X-Payment: hashcash " end t))
+ (let ((value (split-string
+ (buffer-substring (point) (hashcash-point-at-eol))
+ " ")))
+ (when (equal (car value) (number-to-string version))
+ (setq ok (hashcash-verify-payment (cadr value))))))
+ (goto-char (point-min))
+ (while (and (not ok) (search-forward "X-Hashcash: " end t))
+ (setq ok (hashcash-verify-payment
+ (buffer-substring (point) (hashcash-point-at-eol)))))
+ (when ok
+ (message "Payment valid"))
+ ok))))