Gnus development mailing list
 help / color / mirror / Atom feed
* [PATCH] make sign/encrypt operate on the whole message
@ 2002-01-19  7:38 Josh Huber
  2002-01-19  8:05 ` Josh Huber
  2002-01-20  0:01 ` Lars Magne Ingebrigtsen
  0 siblings, 2 replies; 7+ messages in thread
From: Josh Huber @ 2002-01-19  7:38 UTC (permalink / raw)


...regardless of parts.

What this does is insert a <!secure method=(pgp|pgpmime|smime
mode=(sign|encrypt)> at the top of a message buffer.

When the mml parsing code sees this "meta-meta" tag, it replaces it
with either a part or a multipart tag -- depending on whether or not
there are other parts specified in the document.

I'm sure there are bugs!  What do you think of the idea?  I think it's
good, but is there a better place to implement it?

I've only tested pgpmime, btw...with both signing and encrypting
messages with & without attachments.

my simple tests pass.

Comments?

gnus Patch (cvs -q diff -u):

Index: lisp/mml-sec.el
===================================================================
RCS file: /usr/local/cvsroot/gnus/lisp/mml-sec.el,v
retrieving revision 1.8
diff -u -r1.8 mml-sec.el
--- lisp/mml-sec.el	2001/11/12 21:33:12	1.8
+++ lisp/mml-sec.el	2002/01/19 07:39:34
@@ -127,6 +127,61 @@
   (interactive)
   (mml-secure-part "smime"))
 
+;; defuns that add the proper <#secure ...> tag to the top of the message body
+(defun mml-secure-message (method &optional sign)
+  (let ((mode (if sign "sign" "encrypt"))
+	insert-loc)
+    (mml-unsecure-message)
+    (save-excursion
+      (goto-char (point-max))
+      (cond ((re-search-backward
+	      (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
+	     (goto-char (setq insert-loc (match-end 0)))
+	     (unless (looking-at "<#secure")
+	       (mml-insert-tag
+		'secure 'method method 'mode mode)))
+	    (t (error
+		"The message is corrupted. No mail header separator"))))
+    (when (eql insert-loc (point))
+      (forward-line 1))))
+
+(defun mml-unsecure-message ()
+  (interactive)
+  (save-excursion
+    (goto-char (point-max))
+    (when (re-search-backward "^<#secure.*>\n" nil t)
+      (kill-region (match-beginning 0) (match-end 0)))))
+
+(defun mml-secure-message-sign-smime ()
+  "Add MML tag to encrypt/sign the entire message."
+  (interactive)
+  (mml-secure-message "smime" 'sign))
+
+(defun mml-secure-message-sign-pgp ()
+  "Add MML tag to encrypt/sign the entire message."
+  (interactive)
+  (mml-secure-message "pgp" 'sign))
+
+(defun mml-secure-message-sign-pgpmime ()
+  "Add MML tag to encrypt/sign the entire message."
+  (interactive)
+  (mml-secure-message "pgpmime" 'sign))
+
+(defun mml-secure-message-encrypt-smime ()
+  "Add MML tag to encrypt/sign the entire message."
+  (interactive)
+  (mml-secure-message "smime"))
+
+(defun mml-secure-message-encrypt-pgp ()
+  "Add MML tag to encrypt/sign the entire message."
+  (interactive)
+  (mml-secure-message "pgp"))
+
+(defun mml-secure-message-encrypt-pgpmime ()
+  "Add MML tag to encrypt/sign the entire message."
+  (interactive)
+  (mml-secure-message "pgpmime"))
+
 (provide 'mml-sec)
 
 ;;; mml-sec.el ends here
Index: lisp/mml.el
===================================================================
RCS file: /usr/local/cvsroot/gnus/lisp/mml.el,v
retrieving revision 6.47
diff -u -r6.47 mml.el
--- lisp/mml.el	2002/01/12 00:55:06	6.47
+++ lisp/mml.el	2002/01/19 07:39:35
@@ -143,6 +143,34 @@
     (while (and (not (eobp))
 		(not (looking-at "



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] make sign/encrypt operate on the whole message
  2002-01-19  7:38 [PATCH] make sign/encrypt operate on the whole message Josh Huber
@ 2002-01-19  8:05 ` Josh Huber
  2002-01-20  0:02   ` Lars Magne Ingebrigtsen
  2002-01-20  0:01 ` Lars Magne Ingebrigtsen
  1 sibling, 1 reply; 7+ messages in thread
From: Josh Huber @ 2002-01-19  8:05 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 159 bytes --]

Josh Huber <huber@alum.wpi.edu> writes:
[snip]

Well, I'm confused -- I wonder why 1/2 of my diff was missing?

It's attached to this message.

-- 
Josh Huber

[-- Attachment #2: gnus-secure-part.diff --]
[-- Type: text/plain, Size: 5429 bytes --]

Index: lisp/mml-sec.el
===================================================================
RCS file: /usr/local/cvsroot/gnus/lisp/mml-sec.el,v
retrieving revision 1.8
diff -u -r1.8 mml-sec.el
--- lisp/mml-sec.el	2001/11/12 21:33:12	1.8
+++ lisp/mml-sec.el	2002/01/19 08:07:04
@@ -127,6 +127,61 @@
   (interactive)
   (mml-secure-part "smime"))
 
+;; defuns that add the proper <#secure ...> tag to the top of the message body
+(defun mml-secure-message (method &optional sign)
+  (let ((mode (if sign "sign" "encrypt"))
+	insert-loc)
+    (mml-unsecure-message)
+    (save-excursion
+      (goto-char (point-max))
+      (cond ((re-search-backward
+	      (concat "^" (regexp-quote mail-header-separator) "\n") nil t)
+	     (goto-char (setq insert-loc (match-end 0)))
+	     (unless (looking-at "<#secure")
+	       (mml-insert-tag
+		'secure 'method method 'mode mode)))
+	    (t (error
+		"The message is corrupted. No mail header separator"))))
+    (when (eql insert-loc (point))
+      (forward-line 1))))
+
+(defun mml-unsecure-message ()
+  (interactive)
+  (save-excursion
+    (goto-char (point-max))
+    (when (re-search-backward "^<#secure.*>\n" nil t)
+      (kill-region (match-beginning 0) (match-end 0)))))
+
+(defun mml-secure-message-sign-smime ()
+  "Add MML tag to encrypt/sign the entire message."
+  (interactive)
+  (mml-secure-message "smime" 'sign))
+
+(defun mml-secure-message-sign-pgp ()
+  "Add MML tag to encrypt/sign the entire message."
+  (interactive)
+  (mml-secure-message "pgp" 'sign))
+
+(defun mml-secure-message-sign-pgpmime ()
+  "Add MML tag to encrypt/sign the entire message."
+  (interactive)
+  (mml-secure-message "pgpmime" 'sign))
+
+(defun mml-secure-message-encrypt-smime ()
+  "Add MML tag to encrypt/sign the entire message."
+  (interactive)
+  (mml-secure-message "smime"))
+
+(defun mml-secure-message-encrypt-pgp ()
+  "Add MML tag to encrypt/sign the entire message."
+  (interactive)
+  (mml-secure-message "pgp"))
+
+(defun mml-secure-message-encrypt-pgpmime ()
+  "Add MML tag to encrypt/sign the entire message."
+  (interactive)
+  (mml-secure-message "pgpmime"))
+
 (provide 'mml-sec)
 
 ;;; mml-sec.el ends here
Index: lisp/mml.el
===================================================================
RCS file: /usr/local/cvsroot/gnus/lisp/mml.el,v
retrieving revision 6.47
diff -u -r6.47 mml.el
--- lisp/mml.el	2002/01/12 00:55:06	6.47
+++ lisp/mml.el	2002/01/19 08:07:05
@@ -143,6 +143,34 @@
     (while (and (not (eobp))
 		(not (looking-at "<#/multipart")))
       (cond
+       ((looking-at "<#secure")
+	;; The secure part is essentially a meta-meta tag, which
+	;; expands to either a part tag if there are no other parts in
+	;; the document or a multipart tag if there are other parts
+	;; included in the message
+	(let* (secure-mode
+	       (taginfo (mml-read-tag))
+	       (recipient (cdr (assq 'recipient taginfo))))
+	  (save-excursion
+	    (if
+		(re-search-forward
+		 "^<#\\(/\\)?\\(multipart\\|part\\|external\\|mml\\)." nil t)
+		(setq secure-mode "multipart")
+	      (setq secure-mode "part")))
+	  (save-excursion
+	    (goto-char (point-min))
+	    (re-search-forward "<#secure.*>"))
+	  (delete-region (match-beginning 0) (match-end 0))
+	  (forward-char -1)
+	  (mml-insert-tag secure-mode
+			  (cdr (assq 'mode taginfo))
+			  (cdr (assq 'method taginfo))
+			  (and recipient 'recipient)
+			  recipient))
+	(delete-backward-char 1)
+	;; restart the parse
+	(goto-char (point-min)))
+
        ((looking-at "<#multipart")
 	(push (nconc (mml-read-tag) (mml-parse-1)) struct))
        ((looking-at "<#external")
@@ -750,12 +778,12 @@
 	(encrypt (make-sparse-keymap))
 	(map (make-sparse-keymap))
 	(main (make-sparse-keymap)))
-    (define-key sign "p" 'mml-secure-sign-pgpmime)
-    (define-key sign "o" 'mml-secure-sign-pgp)
-    (define-key sign "s" 'mml-secure-sign-smime)
-    (define-key encrypt "p" 'mml-secure-encrypt-pgpmime)
-    (define-key encrypt "o" 'mml-secure-encrypt-pgp)
-    (define-key encrypt "s" 'mml-secure-encrypt-smime)
+    (define-key sign "p" 'mml-secure-message-sign-pgpmime)
+    (define-key sign "o" 'mml-secure-message-sign-pgp)
+    (define-key sign "s" 'mml-secure-message-sign-smime)
+    (define-key encrypt "p" 'mml-secure-message-encrypt-pgpmime)
+    (define-key encrypt "o" 'mml-secure-message-encrypt-pgp)
+    (define-key encrypt "s" 'mml-secure-message-encrypt-smime)
     (define-key map "f" 'mml-attach-file)
     (define-key map "b" 'mml-attach-buffer)
     (define-key map "e" 'mml-attach-external)
@@ -782,12 +810,12 @@
     ["Attach External" mml-attach-external t]
     ["Insert Part" mml-insert-part t]
     ["Insert Multipart" mml-insert-multipart t]
-    ["PGP/MIME Sign" mml-secure-sign-pgpmime t]
-    ["PGP/MIME Encrypt" mml-secure-encrypt-pgpmime t]
-    ["PGP Sign" mml-secure-sign-pgp t]
-    ["PGP Encrypt" mml-secure-encrypt-pgp t]
-    ["S/MIME Sign" mml-secure-sign-smime t]
-    ["S/MIME Encrypt" mml-secure-encrypt-smime t]
+    ["PGP/MIME Sign" mml-secure-message-sign-pgpmime t]
+    ["PGP/MIME Encrypt" mml-secure-message-encrypt-pgpmime t]
+    ["PGP Sign" mml-secure-message-sign-pgp t]
+    ["PGP Encrypt" mml-secure-message-encrypt-pgp t]
+    ["S/MIME Sign" mml-secure-message-sign-smime t]
+    ["S/MIME Encrypt" mml-secure-message-encrypt-smime t]
     ;;["Narrow" mml-narrow-to-part t]
     ["Quote MML" mml-quote-region t]
     ["Validate MML" mml-validate t]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] make sign/encrypt operate on the whole message
  2002-01-19  7:38 [PATCH] make sign/encrypt operate on the whole message Josh Huber
  2002-01-19  8:05 ` Josh Huber
@ 2002-01-20  0:01 ` Lars Magne Ingebrigtsen
  1 sibling, 0 replies; 7+ messages in thread
From: Lars Magne Ingebrigtsen @ 2002-01-20  0:01 UTC (permalink / raw)


Josh Huber <huber@alum.wpi.edu> writes:

> Comments?

Sounds like a good idea to me.

-- 
(domestic pets only, the antidote for overdose, milk.)
   larsi@gnus.org * Lars Magne Ingebrigtsen



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] make sign/encrypt operate on the whole message
  2002-01-19  8:05 ` Josh Huber
@ 2002-01-20  0:02   ` Lars Magne Ingebrigtsen
  2002-01-22 16:34     ` Josh Huber
  0 siblings, 1 reply; 7+ messages in thread
From: Lars Magne Ingebrigtsen @ 2002-01-20  0:02 UTC (permalink / raw)


Josh Huber <huber@alum.wpi.edu> writes:

> Well, I'm confused -- I wonder why 1/2 of my diff was missing?

Message probably interpreted some of the tags in the diff as, er, tags
and chopped stuff up a bit.

-- 
(domestic pets only, the antidote for overdose, milk.)
   larsi@gnus.org * Lars Magne Ingebrigtsen



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] make sign/encrypt operate on the whole message
  2002-01-20  0:02   ` Lars Magne Ingebrigtsen
@ 2002-01-22 16:34     ` Josh Huber
  2002-01-22 22:36       ` Simon Josefsson
  0 siblings, 1 reply; 7+ messages in thread
From: Josh Huber @ 2002-01-22 16:34 UTC (permalink / raw)


Lars Magne Ingebrigtsen <larsi@gnus.org> writes:

> Message probably interpreted some of the tags in the diff as, er,
> tags and chopped stuff up a bit.

Yes, you're probably right.  Should have quoted the mml.

Unless someone objects, I'm going to clean up the code and commit it.

ttyl,

-- 
Josh Huber



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] make sign/encrypt operate on the whole message
  2002-01-22 16:34     ` Josh Huber
@ 2002-01-22 22:36       ` Simon Josefsson
  2002-01-22 22:59         ` Josh Huber
  0 siblings, 1 reply; 7+ messages in thread
From: Simon Josefsson @ 2002-01-22 22:36 UTC (permalink / raw)


Josh Huber <huber@alum.wpi.edu> writes:

> Lars Magne Ingebrigtsen <larsi@gnus.org> writes:
>
>> Message probably interpreted some of the tags in the diff as, er,
>> tags and chopped stuff up a bit.
>
> Yes, you're probably right.  Should have quoted the mml.
>
> Unless someone objects, I'm going to clean up the code and commit it.

Thanks.  Comments: It seems to use `recipient' instead of
`recipients', so specifying a recipient doesn't work.  Maybe it should
be possible to abbrev these things, so that recip=foo@bar.com would be
sufficient.  Also, the manual is out of date wrt to these commands
now.  Maybe the `recipients' stuff could be documented as well. :-)




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] make sign/encrypt operate on the whole message
  2002-01-22 22:36       ` Simon Josefsson
@ 2002-01-22 22:59         ` Josh Huber
  0 siblings, 0 replies; 7+ messages in thread
From: Josh Huber @ 2002-01-22 22:59 UTC (permalink / raw)


Simon Josefsson <jas@extundo.com> writes:

> Thanks.  Comments: It seems to use `recipient' instead of
> `recipients', so specifying a recipient doesn't work.  Maybe it
> should be possible to abbrev these things, so that recip=foo@bar.com
> would be sufficient.  Also, the manual is out of date wrt to these
> commands now.  Maybe the `recipients' stuff could be documented as
> well. :-)

It's funny you mentioned that, since I was just updating the
message.texi documentation about the secure tag, trying to look for
documentation on the recipient option.  (which wasn't there ;)

I added a little blurb about the recipients option, and changed my new
code to use that option. (correct spelling :)

ttyl,

-- 
Josh Huber



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2002-01-22 22:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-19  7:38 [PATCH] make sign/encrypt operate on the whole message Josh Huber
2002-01-19  8:05 ` Josh Huber
2002-01-20  0:02   ` Lars Magne Ingebrigtsen
2002-01-22 16:34     ` Josh Huber
2002-01-22 22:36       ` Simon Josefsson
2002-01-22 22:59         ` Josh Huber
2002-01-20  0:01 ` Lars Magne Ingebrigtsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).