Gnus development mailing list
 help / color / mirror / Atom feed
* [PATCH] Improve Gnus sieve integration
@ 2007-09-30 13:36 Daniel Pittman
  2007-10-03 10:57 ` Simon Josefsson
  2007-10-03 10:59 ` Simon Josefsson
  0 siblings, 2 replies; 5+ messages in thread
From: Daniel Pittman @ 2007-09-30 13:36 UTC (permalink / raw)
  To: ding

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

G'day.  At the moment the integration between the Gnus Sieve generation
code and managesieve servers is pretty terrible -- the only mechanism to
update your Sieve script is to run a shell command, despite there being
a nice and general managesieve implementation.

The attached patch changes this: it extends the support to be able to
use managesieve to upload the generated Sieve script to a managesieve
server as well as to upload through running a shell command.

This also modifies the default upload behaviour: it doesn't just upload
the script automatically, it gives you a chance to review and modify the
script before you save and, then, send it to the server.

I believe this is a significant improvement over the current activity.

I have previously signed papers for Gnus so there should be no real
problem with the current changes in that regard.


The current patch probably isn't completely polished so I would welcome
any feedback or testing that might help clean it up and get it ready for
inclusion in Gnus.

Regards,
        Daniel
-- 
Daniel Pittman <daniel@cybersource.com.au>           Phone: 03 9621 2377
Level 4, 10 Queen St, Melbourne             Web: http://www.cyber.com.au
Cybersource: Australia's Leading Linux and Open Source Solutions Company


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: nicer-sieve.patch --]
[-- Type: text/x-diff, Size: 2963 bytes --]

diff --git a/gnus/nicer-sieve/gnus-sieve.el b/gnus/nicer-sieve/gnus-sieve.el
index 0e6c500..4ea10e2 100644
--- a/gnus/nicer-sieve/gnus-sieve.el
+++ b/gnus/nicer-sieve/gnus-sieve.el
@@ -70,15 +70,26 @@ For example: \"nnimap:mailbox\""
   :type 'boolean
   :group 'gnus-sieve)
 
-(defcustom gnus-sieve-update-shell-command "echo put %f | sieveshell %s"
-  "Shell command to execute after updating your Sieve script.  The following
-formatting characters are recognized:
+(defcustom gnus-sieve-update-method "echo put %f | sieveshell %s"
+  "The method used to update your Sieve script on the server.  This can
+be using the internal managesieve support or by executing a shell command.
+
+If the value is a string it is treated as a shell command to run; The
+following formatting characters are recognized:
 
 %f    Script's file name (gnus-sieve-file)
 %s    Server name (from gnus-sieve-select-method)"
-  :type 'string
+  :type '(choice (const  :tag "Use managesieve" 'managesieve)
+		 (string :tag "Shell command"))
   :group 'gnus-sieve)
 
+(define-obsolete-variable-alias 'gnus-sieve-update-shell-command
+  'gnus-sieve-update-method)
+
+(defcustom gnus-sieve-update-hostname nil
+  "The hostname to use when uploading via managesieve.  If not set the
+hostname is guessed from the Sieve select method.")
+
 ;;;###autoload
 (defun gnus-sieve-update ()
   "Update the Sieve script in gnus-sieve-file, by replacing the region
@@ -88,13 +99,33 @@ execute gnus-sieve-update-shell-command.
 See the documentation for these variables and functions for details."
   (interactive)
   (gnus-sieve-generate)
-  (save-buffer)
-  (shell-command
-   (format-spec gnus-sieve-update-shell-command
-		(format-spec-make ?f gnus-sieve-file
-				  ?s (or (cadr (gnus-server-get-method
-						nil gnus-sieve-select-method))
-					 "")))))
+  (set (make-local-variable 'gnus-sieve-server)
+       (or gnus-sieve-update-hostname
+	   (cadr (gnus-server-get-method
+		  nil gnus-sieve-select-method))
+	   (error "Unable to determine hostname for upload of Sieve script.")))
+  (add-hook 'after-save-hook
+	    (lambda () (call-interactively #'gnus-sieve-upload))
+	    t t)
+  (message "Your Sieve script will be uploaded to the server when you save."))
+
+
+(defun gnus-sieve-upload ()
+  "Upload the current buffer to a sieve server on save.  This is called
+from the `after-save-hook' in a buffer prepared by the `gnus-sieve-update'
+method."
+  (interactive)
+  (if (eq gnus-sieve-update-method 'managesieve)
+      (let ((server (sieve-manage-open gnus-sieve-server)))
+	(sieve-manage-authenticate nil nil server)
+	(sieve-manage-putscript (buffer-name) (buffer-string) server)
+	(sieve-manage-close server))
+    (shell-command
+     (format-spec gnus-sieve-update-shell-command
+		  (format-spec-make ?f gnus-sieve-file
+				    ?s (or (cadr (gnus-server-get-method
+						  nil gnus-sieve-select-method))
+					   ""))))))
 
 ;;;###autoload
 (defun gnus-sieve-generate ()

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

end of thread, other threads:[~2007-10-04  7:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-30 13:36 [PATCH] Improve Gnus sieve integration Daniel Pittman
2007-10-03 10:57 ` Simon Josefsson
2007-10-03 10:59 ` Simon Josefsson
2007-10-03 14:17   ` Daniel Pittman
2007-10-04  7:40     ` Simon Josefsson

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).