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

* Re: [PATCH] Improve Gnus sieve integration
  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
  1 sibling, 0 replies; 5+ messages in thread
From: Simon Josefsson @ 2007-10-03 10:57 UTC (permalink / raw)
  To: Daniel Pittman; +Cc: ding

Daniel Pittman <daniel@rimspace.net> writes:

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

Cool!

The documentation needs to be modified, though, or possibly your code
could be aligned to match the current documentation to avoid backwards
compatibility problems.  The current manual says:

`D g'
     Regenerate a Sieve script from the `sieve' group parameters and
     put you into the `gnus-sieve-file' without saving it.

`D u'
     Regenerates the Gnus managed part of `gnus-sieve-file' using the
     `sieve' group parameters, save the file and upload it to the
     server using the `sieveshell' program.

Maybe your after-save-hook stuff could be replaced by having a new
command that can be invoked in the sieve buffer, to upload the file?
Then people can use D g as before, and have a new option of easily
uploading it via managesieve, or use D u as before too.

Alternatively, the after-save-hook could ask whether the user wants to
upload the file too?  Then both D g and D u would work as documented,
and users would have no surprises and a better experience.  The prompt
could be yes/no/always where always saved a customization of a variable
to remove the prompt.

Just some ideas.

/Simon



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

* Re: [PATCH] Improve Gnus sieve integration
  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
  1 sibling, 1 reply; 5+ messages in thread
From: Simon Josefsson @ 2007-10-03 10:59 UTC (permalink / raw)
  To: Daniel Pittman; +Cc: ding

I just realized that some of what you want to do, and what I described,
can already be done: Just 'D g' and then use C-c RET to upload it via
managesieve.  It doesn't fill out the server name automatically though.

Maybe there is some overlap in existing functionality here, although I'm
sure the user experience could be improved.



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

* Re: [PATCH] Improve Gnus sieve integration
  2007-10-03 10:59 ` Simon Josefsson
@ 2007-10-03 14:17   ` Daniel Pittman
  2007-10-04  7:40     ` Simon Josefsson
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Pittman @ 2007-10-03 14:17 UTC (permalink / raw)
  To: ding

Simon Josefsson <simon@josefsson.org> writes:

> I just realized that some of what you want to do, and what I
> described, can already be done: Just 'D g' and then use C-c RET to
> upload it via managesieve.  It doesn't fill out the server name
> automatically though.
>
> Maybe there is some overlap in existing functionality here, although
> I'm sure the user experience could be improved.

Ah.  I wasn't aware of the existing functionality and, frankly, if it is
present then the Gnus changes are probably not that useful.

I will look at what you reference and see how things go...

        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




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

* Re: [PATCH] Improve Gnus sieve integration
  2007-10-03 14:17   ` Daniel Pittman
@ 2007-10-04  7:40     ` Simon Josefsson
  0 siblings, 0 replies; 5+ messages in thread
From: Simon Josefsson @ 2007-10-04  7:40 UTC (permalink / raw)
  To: Daniel Pittman; +Cc: ding

Daniel Pittman <daniel@rimspace.net> writes:

> Simon Josefsson <simon@josefsson.org> writes:
>
>> I just realized that some of what you want to do, and what I
>> described, can already be done: Just 'D g' and then use C-c RET to
>> upload it via managesieve.  It doesn't fill out the server name
>> automatically though.
>>
>> Maybe there is some overlap in existing functionality here, although
>> I'm sure the user experience could be improved.
>
> Ah.  I wasn't aware of the existing functionality and, frankly, if it is
> present then the Gnus changes are probably not that useful.
>
> I will look at what you reference and see how things go...

Having it find the sieve server automatically would be nice though,
right now I type it manually each time.  And an option to ask you
whether to do it all when you save the file would be quite nice.



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