annotate lisp/gnus/canlock.el @ 82966:28d9e552d178

Merge some changes from Emacs/trunk: 2004-08-22 Reiner Steib <Reiner.Steib@gmx.de> * gnus-mlspl.el (gnus-group-split-update): Fix docstring. 2004-08-22 Stefan Monnier <monnier@iro.umontreal.ca> * gnus-art.el: Use inhibit-read-only instead of buffer-read-only. (gnus-narrow-to-page): Don't assume point-min == 1. (gnus-article-edit-mode): Derive from message-mode. * gnus-score.el (gnus-score-find-bnews): Simplify and don't assume point-min == 1. * imap.el (imap-parse-address-list, imap-parse-body-ext): Disable incorrect use of `assert'. [Emacs/trunk 2004-03-22] * message.el (message-mode): Set comment-start-skip. [Emacs/trunk 2004-03-04] 2004-08-22 Sam Steingold <sds@gnu.org> * pop3.el (pop3-leave-mail-on-server): New user variable. (pop3-movemail): Delete mail only when it is nil. [Emacs/trunk 2003-06-11]
author Reiner Steib <Reiner.Steib@gmx.de>
date Sun, 22 Aug 2004 19:35:29 +0000
parents 0fde48feb604
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
82951
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
1 ;;; canlock.el --- functions for Cancel-Lock feature
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
2
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
3 ;; Copyright (C) 1998, 1999, 2001, 2002, 2003 Free Software Foundation, Inc.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
4
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
5 ;; Author: Katsumi Yamaoka <yamaoka@jpl.org>
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
6 ;; Keywords: news, cancel-lock, hmac, sha1, rfc2104
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
7
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
8 ;; This program is free software; you can redistribute it and/or modify
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
9 ;; it under the terms of the GNU General Public License as published by
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
10 ;; the Free Software Foundation; either version 2, or (at your option)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
11 ;; any later version.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
12
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
13 ;; This program is distributed in the hope that it will be useful,
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
16 ;; GNU General Public License for more details.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
17
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
18 ;; You should have received a copy of the GNU General Public License
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
19 ;; along with this program; see the file COPYING. If not, write to the
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
20 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
21 ;; Boston, MA 02111-1307, USA.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
22
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
23 ;;; Commentary:
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
24
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
25 ;; Canlock is a library for generating and verifying Cancel-Lock and/or
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
26 ;; Cancel-Key header in news articles. This is used to protect articles
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
27 ;; from rogue cancel, supersede or replace attacks. The method is based
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
28 ;; on draft-ietf-usefor-cancel-lock-01.txt which was released on November
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
29 ;; 3rd 1998. For instance, you can add Cancel-Lock (and possibly Cancel-
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
30 ;; Key) header in a news article by using a hook which will be evaluated
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
31 ;; just before sending an article as follows:
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
32 ;;
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
33 ;; (add-hook '*e**a*e-header-hook 'canlock-insert-header t)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
34 ;;
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
35 ;; Verifying Cancel-Lock is mainly a function of news servers, however,
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
36 ;; you can verify your own article using the command `canlock-verify' in
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
37 ;; the (raw) article buffer. You will be prompted for the password for
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
38 ;; each time if the option `canlock-password' or `canlock-password-for-
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
39 ;; verify' is nil. Note that setting these options is a bit unsafe.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
40
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
41 ;;; Code:
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
42
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
43 (eval-when-compile
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
44 (require 'cl))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
45
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
46 (autoload 'sha1-binary "sha1-el")
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
47 (autoload 'base64-encode-string "base64")
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
48 (autoload 'mail-fetch-field "mail-utils")
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
49 (defvar mail-header-separator)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
50
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
51 (defgroup canlock nil
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
52 "The Cancel-Lock feature."
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
53 :group 'applications)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
54
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
55 (defcustom canlock-sha1-function 'sha1-binary
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
56 "Function to call to make a SHA-1 message digest."
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
57 :type '(radio (function-item sha1-binary)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
58 (function-item canlock-sha1-with-openssl)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
59 (function :tag "Other"))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
60 :group 'canlock)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
61
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
62 (defcustom canlock-sha1-function-for-verify canlock-sha1-function
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
63 "Function to call to make a SHA-1 message digest for verifying."
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
64 :type '(radio (function-item sha1-binary)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
65 (function-item canlock-sha1-with-openssl)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
66 (function :tag "Other"))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
67 :group 'canlock)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
68
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
69 (defcustom canlock-openssl-program "openssl"
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
70 "Name of OpenSSL program."
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
71 :type 'string
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
72 :group 'canlock)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
73
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
74 (defcustom canlock-openssl-args '("sha1")
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
75 "Arguments passed to the OpenSSL program."
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
76 :type 'sexp
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
77 :group 'canlock)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
78
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
79 (defcustom canlock-ignore-errors nil
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
80 "If non-nil, ignore any error signals."
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
81 :type 'boolean
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
82 :group 'canlock)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
83
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
84 (defcustom canlock-password nil
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
85 "Password to use when signing a Cancel-Lock or a Cancel-Key header."
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
86 :type '(radio (const :format "Not specified " nil)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
87 (string :tag "Password" :size 0))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
88 :group 'canlock)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
89
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
90 (defcustom canlock-password-for-verify canlock-password
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
91 "Password to use when verifying a Cancel-Lock or a Cancel-Key header."
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
92 :type '(radio (const :format "Not specified " nil)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
93 (string :tag "Password" :size 0))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
94 :group 'canlock)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
95
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
96 (defcustom canlock-force-insert-header nil
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
97 "If non-nil, insert a Cancel-Lock or a Cancel-Key header even if the
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
98 buffer does not look like a news message."
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
99 :type 'boolean
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
100 :group 'canlock)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
101
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
102 (defun canlock-sha1-with-openssl (message)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
103 "Make a SHA-1 digest of MESSAGE using OpenSSL."
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
104 (let (default-enable-multibyte-characters)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
105 (with-temp-buffer
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
106 (let ((coding-system-for-read 'binary)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
107 (coding-system-for-write 'binary)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
108 selective-display
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
109 (case-fold-search t))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
110 (insert message)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
111 (apply 'call-process-region (point-min) (point-max)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
112 canlock-openssl-program t t nil canlock-openssl-args)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
113 (goto-char (point-min))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
114 (insert "\"")
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
115 (while (re-search-forward "\\([0-9a-f][0-9a-f]\\)" nil t)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
116 (replace-match "\\\\x\\1"))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
117 (insert "\"")
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
118 (goto-char (point-min))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
119 (read (current-buffer))))))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
120
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
121 (eval-when-compile
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
122 (defmacro canlock-string-as-unibyte (string)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
123 "Return a unibyte string with the same individual bytes as STRING."
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
124 (if (fboundp 'string-as-unibyte)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
125 (list 'string-as-unibyte string)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
126 string)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
127
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
128 (defun canlock-sha1 (message)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
129 "Make a SHA-1 digest of MESSAGE as a unibyte string of length 20 bytes."
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
130 (canlock-string-as-unibyte (funcall canlock-sha1-function message)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
131
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
132 (defun canlock-make-cancel-key (message-id password)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
133 "Make a Cancel-Key header."
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
134 (when (> (length password) 20)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
135 (setq password (canlock-sha1 password)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
136 (setq password (concat password (make-string (- 64 (length password)) 0)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
137 (let ((ipad (mapconcat (lambda (byte)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
138 (char-to-string (logxor 54 byte)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
139 password ""))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
140 (opad (mapconcat (lambda (byte)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
141 (char-to-string (logxor 92 byte)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
142 password "")))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
143 (base64-encode-string
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
144 (canlock-sha1
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
145 (concat opad
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
146 (canlock-sha1
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
147 (concat ipad (canlock-string-as-unibyte message-id))))))))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
148
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
149 (defun canlock-narrow-to-header ()
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
150 "Narrow the buffer to the head of the message."
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
151 (let (case-fold-search)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
152 (narrow-to-region
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
153 (goto-char (point-min))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
154 (goto-char (if (re-search-forward
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
155 (format "^$\\|^%s$"
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
156 (regexp-quote mail-header-separator))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
157 nil t)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
158 (match-beginning 0)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
159 (point-max))))))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
160
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
161 (defun canlock-delete-headers ()
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
162 "Delete Cancel-Key or Cancel-Lock headers in the narrowed buffer."
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
163 (let ((case-fold-search t))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
164 (goto-char (point-min))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
165 (while (re-search-forward "^Cancel-\\(Key\\|Lock\\):" nil t)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
166 (delete-region (match-beginning 0)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
167 (if (re-search-forward "^[^\t ]" nil t)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
168 (goto-char (match-beginning 0))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
169 (point-max))))))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
170
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
171 (defun canlock-fetch-fields (&optional key)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
172 "Return a list of the values of Cancel-Lock header.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
173 If KEY is non-nil, look for a Cancel-Key header instead. The buffer
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
174 is expected to be narrowed to just the headers of the message."
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
175 (let ((field (mail-fetch-field (if key "Cancel-Key" "Cancel-Lock")))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
176 fields rest
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
177 (case-fold-search t))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
178 (when field
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
179 (setq fields (split-string field "[\t\n\r ,]+"))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
180 (while fields
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
181 (when (string-match "^sha1:" (setq field (pop fields)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
182 (push (substring field 5) rest)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
183 (nreverse rest))))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
184
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
185 (defun canlock-fetch-id-for-key ()
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
186 "Return a Message-ID in Cancel, Supersedes or Replaces header.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
187 The buffer is expected to be narrowed to just the headers of the
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
188 message."
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
189 (or (let ((cancel (mail-fetch-field "Control")))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
190 (and cancel
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
191 (string-match "^cancel[\t ]+\\(<[^\t\n @<>]+@[^\t\n @<>]+>\\)"
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
192 cancel)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
193 (match-string 1 cancel)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
194 (mail-fetch-field "Supersedes")
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
195 (mail-fetch-field "Replaces")))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
196
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
197 ;;;###autoload
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
198 (defun canlock-insert-header (&optional id-for-key id-for-lock password)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
199 "Insert a Cancel-Key and/or a Cancel-Lock header if possible."
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
200 (let (news control key-for-key key-for-lock)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
201 (save-excursion
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
202 (save-restriction
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
203 (canlock-narrow-to-header)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
204 (when (setq news (or canlock-force-insert-header
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
205 (mail-fetch-field "Newsgroups")))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
206 (unless id-for-key
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
207 (setq id-for-key (canlock-fetch-id-for-key)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
208 (if (and (setq control (mail-fetch-field "Control"))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
209 (string-match
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
210 "^cancel[\t ]+\\(<[^\t\n @<>]+@[^\t\n @<>]+>\\)"
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
211 control))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
212 (setq id-for-lock nil)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
213 (unless id-for-lock
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
214 (setq id-for-lock (mail-fetch-field "Message-ID"))))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
215 (canlock-delete-headers)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
216 (goto-char (point-max))))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
217 (when news
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
218 (if (not (or id-for-key id-for-lock))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
219 (message "There are no Message-ID(s)")
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
220 (unless password
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
221 (setq password (or canlock-password
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
222 (read-passwd
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
223 "Password for Canlock: "))))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
224 (if (or (not (stringp password)) (zerop (length password)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
225 (message "Password for Canlock is bad")
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
226 (setq key-for-key (when id-for-key
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
227 (canlock-make-cancel-key
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
228 id-for-key password))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
229 key-for-lock (when id-for-lock
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
230 (canlock-make-cancel-key
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
231 id-for-lock password)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
232 (if (not (or key-for-key key-for-lock))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
233 (message "Couldn't insert Canlock header")
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
234 (when key-for-key
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
235 (insert "Cancel-Key: sha1:" key-for-key "\n"))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
236 (when key-for-lock
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
237 (insert "Cancel-Lock: sha1:"
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
238 (base64-encode-string (canlock-sha1 key-for-lock))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
239 "\n")))))))))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
240
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
241 ;;;###autoload
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
242 (defun canlock-verify (&optional buffer)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
243 "Verify Cancel-Lock or Cancel-Key in BUFFER.
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
244 If BUFFER is nil, the current buffer is assumed. Signal an error if
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
245 it fails. You can modify the behavior of this function to return non-
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
246 nil instead of to signal an error by setting the option
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
247 `canlock-ignore-errors' to non-nil."
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
248 (interactive)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
249 (let ((canlock-sha1-function (or canlock-sha1-function-for-verify
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
250 canlock-sha1-function))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
251 keys locks errmsg id-for-key id-for-lock password
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
252 key-for-key key-for-lock match)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
253 (save-excursion
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
254 (when buffer
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
255 (set-buffer buffer))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
256 (save-restriction
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
257 (widen)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
258 (canlock-narrow-to-header)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
259 (setq keys (canlock-fetch-fields 'key)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
260 locks (canlock-fetch-fields))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
261 (if (not (or keys locks))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
262 (setq errmsg
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
263 "There are neither Cancel-Lock nor Cancel-Key headers")
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
264 (setq id-for-key (canlock-fetch-id-for-key)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
265 id-for-lock (mail-fetch-field "Message-ID"))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
266 (or id-for-key id-for-lock
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
267 (setq errmsg "There are no Message-ID(s)")))))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
268
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
269 (if errmsg
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
270 (if canlock-ignore-errors
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
271 errmsg
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
272 (error "%s" errmsg))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
273
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
274 (setq password (or canlock-password-for-verify
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
275 (read-passwd "Password for Canlock: ")))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
276 (if (or (not (stringp password)) (zerop (length password)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
277 (progn
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
278 (setq errmsg "Password for Canlock is bad")
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
279 (if canlock-ignore-errors
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
280 errmsg
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
281 (error "%s" errmsg)))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
282
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
283 (when keys
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
284 (when id-for-key
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
285 (setq key-for-key (canlock-make-cancel-key id-for-key password))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
286 (while (and keys (not match))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
287 (setq match (string-equal key-for-key (pop keys)))))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
288 (setq keys (if match "good" "bad")))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
289 (setq match nil)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
290
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
291 (when locks
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
292 (when id-for-lock
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
293 (setq key-for-lock
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
294 (base64-encode-string
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
295 (canlock-sha1 (canlock-make-cancel-key id-for-lock
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
296 password))))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
297 (when (and locks (not match))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
298 (setq match (string-equal key-for-lock (pop locks)))))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
299 (setq locks (if match "good" "bad")))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
300
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
301 (prog1
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
302 (when (member "bad" (list keys locks))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
303 "bad")
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
304 (cond ((and keys locks)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
305 (message "Cancel-Key is %s, Cancel-Lock is %s" keys locks))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
306 (locks
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
307 (message "Cancel-Lock is %s" locks))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
308 (keys
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
309 (message "Cancel-Key is %s" keys))))))))
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
310
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
311 (provide 'canlock)
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
312
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
313 ;;; arch-tag: 033c4f09-b9f1-459d-bd0d-254430283f78
0fde48feb604 Import Gnus 5.10 from the v5_10 branch of the Gnus repository.
Andreas Schwab <schwab@suse.de>
parents:
diff changeset
314 ;;; canlock.el ends here