emacs/lisp/net/sieve-manage.el

621 lines
22 KiB
EmacsLisp
Raw Normal View History

;;; sieve-manage.el --- Implementation of the managesieve protocol in elisp -*- lexical-binding:t -*-
2005-08-06 19:51:42 +00:00
2022-01-01 02:45:51 -05:00
;; Copyright (C) 2001-2022 Free Software Foundation, Inc.
;; Author: Simon Josefsson <simon@josefsson.org>
;; Albert Krewinkel <tarleb@moltkeplatz.de>
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; This library provides an elisp API for the managesieve network
;; protocol.
;;
;; It uses the SASL library for authentication, which means it
;; supports DIGEST-MD5, CRAM-MD5, SCRAM-MD5, NTLM, PLAIN and LOGIN
;; methods. STARTTLS is not well tested, but should be easy to get to
;; work if someone wants.
;;
;; The API should be fairly obvious for anyone familiar with the
;; managesieve protocol, interface functions include:
;;
;; `sieve-manage-open'
;; open connection to managesieve server, returning a buffer to be
;; used by all other API functions.
;;
;; `sieve-manage-opened'
;; check if a server is open or not
;;
;; `sieve-manage-close'
;; close a server connection.
;;
;; `sieve-manage-listscripts'
;; `sieve-manage-deletescript'
;; `sieve-manage-getscript'
;; performs managesieve protocol actions
;;
;; and that's it. Example of a managesieve session in *scratch*:
;;
;; (with-current-buffer (sieve-manage-open "mail.example.com")
;; (sieve-manage-authenticate)
;; (sieve-manage-listscripts))
;;
;; => ((active . "main") "vacation")
;;
;; References:
;;
;; draft-martin-managesieve-02.txt,
;; "A Protocol for Remotely Managing Sieve Scripts",
;; by Tim Martin.
;;
;; Release history:
;;
;; 2001-10-31 Committed to Oort Gnus.
;; 2002-07-27 Added DELETESCRIPT. Suggested by Ned Ludd.
;; 2002-08-03 Use SASL library.
;; 2013-06-05 Enabled STARTTLS support, fixed bit rot.
;;; Code:
(if (locate-library "password-cache")
(require 'password-cache)
(require 'password))
(eval-when-compile (require 'cl-lib))
(require 'sasl)
(autoload 'sasl-find-mechanism "sasl")
Merge changes made in Gnus trunk. auth.texi (Overview, Help for users, Help for developers): Update docs. (Help for users): Talk about spaces. sieve-manage.el: Autoload `auth-source-search'. (sieve-sasl-auth): Use it. nnimap.el: Autoload `auth-source-forget+'. (nnimap-open-connection-1): Use it if the connection fails. auth-source.el: Require `password-cache'. (auth-source-hide-passwords, auth-source-cache): Remove and mark obsolete. (auth-source-magic): Marker for `password-cache' keys. (auth-source-do-cache): Update docstring. (auth-source-search): Use and check cache. (auth-source-forget-all-cached, auth-source-remember) (auth-source-recall, auth-source-forget, auth-source-forget+) (auth-source-specmatchp): Caching support functions. (auth-source-forget-user-or-password, auth-source-forget-all-cached): Remove and obsolete. (auth-source-user-or-password): Remove caching to further discourage using it. Always hide passwords. password-cache.el (password-cache-remove): Accept secrets that are not strings. mail-source.el: Autoload `auth-source-search'. (mail-source-keyword-map): Note order matters. (mail-source-set-1): Get all the mail-source source values and defaults and search auth-source on those if needed. This can all probably be simplified. nnimap.el: Autoload `auth-source-search'. (nnimap-credentials): Use it. (nnimap-open-connection-1): Ask for the virtual server and physical address in one shot. nntp.el: Autoload `auth-source-search'. (nntp-send-authinfo): Use it. Note TODO. auth-source.el (auth-source-secrets-search, auth-source-user-or-password): Use `append' instead of `nconc'. (auth-source-user-or-password): Build return list better and protect against nil :secret. auth-source.el (top): Require 'eieio unconditionally. Autoload `secrets-get-attributes' instead of `secrets-get-attribute'. (auth-source-secrets-search): Limit search when `max' is greater than number of results. auth-source.el (auth-source-secrets-search): Add examples. auth-source.el (auth-sources): Allow for simpler defaults for Secrets API with a string "secrets:collection-name" and with 'default. (auth-source-backend-parse): Parse "secrets:collection-name" and 'default. Recurse on parses instead of repeating code. Use the Secrets API is the source is not nil and 'ignore otherwise. Emit a message when ignoring a source. (auth-source-search): List ignored search keys at the top level. (auth-source-netrc-create): Use `case' instead of `cond'. (auth-source-secrets-search): Created with TODOs. (auth-source-secrets-create): Created with TODOs. (auth-source-retrieve, auth-source-create, auth-source-delete) (auth-source-protocol-defaults, auth-source-user-or-password-imap) (auth-source-user-or-password-pop3, auth-source-user-or-password-ssh) (auth-source-user-or-password-sftp) (auth-source-user-or-password-smtp): Removed. (auth-source-user-or-password): Deprecated and modified to be a wrapper around `auth-source-search'. Not tested thoroughly. auth-source.el: Bring in assoc and eioeio libraries. (secrets-enabled): New variable to track the status of the Secrets API. (auth-source-backend): New EIOEIO class to represent a backend. (auth-source-creation-defaults): New variable to set prompt defaults during token creation (see the `auth-source-search' docstring for details). (auth-sources): Simplify to allow a simple string as a netrc backend spec. (auth-source-backend-parse): Parse a backend from an `auth-sources' spec. (auth-source-backend-parse-parameters): Fill in the backend parameters. (auth-source-search): Main auth-source API entry point. (auth-source-delete): Wrapper around `auth-source-search' for deletion. (auth-source-search-collection): Helper function for searching. (auth-source-netrc-parse, auth-source-netrc-normalize) (auth-source-netrc-search, auth-source-netrc-create): Netrc backend. Supports search, create, and delete. (auth-source-secrets-search, auth-source-secrets-create): Secrets API backend stubs. (auth-source-user-or-password): Call `auth-source-search' but it's not ready yet.
2011-02-13 00:25:29 +00:00
(autoload 'auth-source-search "auth-source")
(autoload 'auth-info-password "auth-source")
;; User customizable variables:
(defgroup sieve-manage nil
"Low-level Managesieve protocol issues."
:group 'mail
:prefix "sieve-")
(defcustom sieve-manage-log "*sieve-manage-log*"
"Name of buffer for managesieve session trace."
:type 'string)
(defcustom sieve-manage-server-eol "\r\n"
"The EOL string sent from the server."
:type 'string)
(defcustom sieve-manage-client-eol "\r\n"
"The EOL string we send to the server."
:type 'string)
(defcustom sieve-manage-authenticators '(digest-md5
cram-md5
scram-md5
ntlm
plain
login)
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-324 Merge from gnus--rel--5.10 Patches applied: * gnus--rel--5.10 (patch 70) - Update from CVS 2005-05-17 Katsumi Yamaoka <yamaoka@jpl.org> * lisp/gnus/canlock.el (canlock): Change the parent group to news. * lisp/gnus/deuglify.el (gnus-outlook-deuglify): Add :group. * lisp/gnus/dig.el (dig): Add :group. * lisp/gnus/gnus-art.el (gnus-inhibit-mime-unbuttonizing): Add :group. * lisp/gnus/gnus-cite.el (gnus-cite-attribution-face): Add :group. (gnus-cite-face-1, gnus-cite-face-2, gnus-cite-face-3): Ditto. (gnus-cite-face-4, gnus-cite-face-5, gnus-cite-face-6): Ditto. (gnus-cite-face-7, gnus-cite-face-8, gnus-cite-face-9): Ditto. (gnus-cite-face-10, gnus-cite-face-11): Ditto. * lisp/gnus/gnus-diary.el (gnus-diary): Add :group. * lisp/gnus/gnus.el (gnus-group-news-1-face): Add :group. (gnus-group-news-1-empty-face): Ditto. (gnus-group-news-2-face, gnus-group-news-2-empty-face): Ditto. (gnus-group-news-3-face, gnus-group-news-3-empty-face): Ditto. (gnus-group-news-4-face, gnus-group-news-4-empty-face): Ditto. (gnus-group-news-5-face, gnus-group-news-5-empty-face): Ditto. (gnus-group-news-6-face, gnus-group-news-6-empty-face): Ditto. (gnus-group-news-low-face, gnus-group-news-low-empty-face): Ditto. (gnus-group-mail-1-face, gnus-group-mail-1-empty-face): Ditto. (gnus-group-mail-2-face, gnus-group-mail-2-empty-face): Ditto. (gnus-group-mail-3-face, gnus-group-mail-3-empty-face): Ditto. (gnus-group-mail-low-face, gnus-group-mail-low-empty-face): Ditto. (gnus-summary-selected-face, gnus-summary-cancelled-face): Ditto. (gnus-summary-high-ticked-face): Ditto. (gnus-summary-low-ticked-face): Ditto. (gnus-summary-normal-ticked-face): Ditto. (gnus-summary-high-ancient-face): Ditto. (gnus-summary-low-ancient-face): Ditto. (gnus-summary-normal-ancient-face): Ditto. (gnus-summary-high-undownloaded-face): Ditto. (gnus-summary-low-undownloaded-face): Ditto. (gnus-summary-normal-undownloaded-face): Ditto. (gnus-summary-high-unread-face): Ditto. (gnus-summary-low-unread-face): Ditto. (gnus-summary-normal-unread-face): Ditto. (gnus-summary-high-read-face, gnus-summary-low-read-face): Diito (gnus-summary-normal-read-face, gnus-splash-face): Ditto. * lisp/gnus/message.el (message-minibuffer-local-map): Add :group. * lisp/gnus/sieve-manage.el (sieve-manage-log): Add :group. (sieve-manage-default-user): Diito. (sieve-manage-server-eol, sieve-manage-client-eol): Ditto. (sieve-manage-streams, sieve-manage-stream-alist): Ditto. (sieve-manage-authenticators): Ditto. (sieve-manage-authenticator-alist): Ditto (sieve-manage-default-port): Ditto. * lisp/gnus/sieve-mode.el (sieve-control-commands-face): Add :group. (sieve-action-commands-face): Ditto. (sieve-test-commands-face): Ditto. (sieve-tagged-arguments-face): Ditto. * lisp/gnus/smime.el (smime): Add :group. * lisp/gnus/spam-report.el (spam-report): Add :group. * lisp/gnus/spam.el (spam, spam-face): Add :group.
2005-05-26 15:03:29 +00:00
"Priority of authenticators to consider when authenticating to server."
;; FIXME Improve this. It's not `set'.
;; It's like (repeat (choice (const ...))), where each choice can
;; only appear once.
:type '(repeat symbol))
(defcustom sieve-manage-authenticator-alist
'((cram-md5 sieve-manage-cram-md5-p sieve-manage-cram-md5-auth)
(digest-md5 sieve-manage-digest-md5-p sieve-manage-digest-md5-auth)
(scram-md5 sieve-manage-scram-md5-p sieve-manage-scram-md5-auth)
(ntlm sieve-manage-ntlm-p sieve-manage-ntlm-auth)
(plain sieve-manage-plain-p sieve-manage-plain-auth)
(login sieve-manage-login-p sieve-manage-login-auth))
"Definition of authenticators.
\(NAME CHECK AUTHENTICATE)
NAME names the authenticator. CHECK is a function returning non-nil if
the server support the authenticator and AUTHENTICATE is a function
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-324 Merge from gnus--rel--5.10 Patches applied: * gnus--rel--5.10 (patch 70) - Update from CVS 2005-05-17 Katsumi Yamaoka <yamaoka@jpl.org> * lisp/gnus/canlock.el (canlock): Change the parent group to news. * lisp/gnus/deuglify.el (gnus-outlook-deuglify): Add :group. * lisp/gnus/dig.el (dig): Add :group. * lisp/gnus/gnus-art.el (gnus-inhibit-mime-unbuttonizing): Add :group. * lisp/gnus/gnus-cite.el (gnus-cite-attribution-face): Add :group. (gnus-cite-face-1, gnus-cite-face-2, gnus-cite-face-3): Ditto. (gnus-cite-face-4, gnus-cite-face-5, gnus-cite-face-6): Ditto. (gnus-cite-face-7, gnus-cite-face-8, gnus-cite-face-9): Ditto. (gnus-cite-face-10, gnus-cite-face-11): Ditto. * lisp/gnus/gnus-diary.el (gnus-diary): Add :group. * lisp/gnus/gnus.el (gnus-group-news-1-face): Add :group. (gnus-group-news-1-empty-face): Ditto. (gnus-group-news-2-face, gnus-group-news-2-empty-face): Ditto. (gnus-group-news-3-face, gnus-group-news-3-empty-face): Ditto. (gnus-group-news-4-face, gnus-group-news-4-empty-face): Ditto. (gnus-group-news-5-face, gnus-group-news-5-empty-face): Ditto. (gnus-group-news-6-face, gnus-group-news-6-empty-face): Ditto. (gnus-group-news-low-face, gnus-group-news-low-empty-face): Ditto. (gnus-group-mail-1-face, gnus-group-mail-1-empty-face): Ditto. (gnus-group-mail-2-face, gnus-group-mail-2-empty-face): Ditto. (gnus-group-mail-3-face, gnus-group-mail-3-empty-face): Ditto. (gnus-group-mail-low-face, gnus-group-mail-low-empty-face): Ditto. (gnus-summary-selected-face, gnus-summary-cancelled-face): Ditto. (gnus-summary-high-ticked-face): Ditto. (gnus-summary-low-ticked-face): Ditto. (gnus-summary-normal-ticked-face): Ditto. (gnus-summary-high-ancient-face): Ditto. (gnus-summary-low-ancient-face): Ditto. (gnus-summary-normal-ancient-face): Ditto. (gnus-summary-high-undownloaded-face): Ditto. (gnus-summary-low-undownloaded-face): Ditto. (gnus-summary-normal-undownloaded-face): Ditto. (gnus-summary-high-unread-face): Ditto. (gnus-summary-low-unread-face): Ditto. (gnus-summary-normal-unread-face): Ditto. (gnus-summary-high-read-face, gnus-summary-low-read-face): Diito (gnus-summary-normal-read-face, gnus-splash-face): Ditto. * lisp/gnus/message.el (message-minibuffer-local-map): Add :group. * lisp/gnus/sieve-manage.el (sieve-manage-log): Add :group. (sieve-manage-default-user): Diito. (sieve-manage-server-eol, sieve-manage-client-eol): Ditto. (sieve-manage-streams, sieve-manage-stream-alist): Ditto. (sieve-manage-authenticators): Ditto. (sieve-manage-authenticator-alist): Ditto (sieve-manage-default-port): Ditto. * lisp/gnus/sieve-mode.el (sieve-control-commands-face): Add :group. (sieve-action-commands-face): Ditto. (sieve-test-commands-face): Ditto. (sieve-tagged-arguments-face): Ditto. * lisp/gnus/smime.el (smime): Add :group. * lisp/gnus/spam-report.el (spam-report): Add :group. * lisp/gnus/spam.el (spam, spam-face): Add :group.
2005-05-26 15:03:29 +00:00
for doing the actual authentication."
:type '(repeat (list (symbol :tag "Name") (function :tag "Check function")
(function :tag "Authentication function"))))
(defcustom sieve-manage-default-port "sieve"
"Default port number or service name for managesieve protocol."
Make some defcustom types more restrictive * lisp/abbrev.el (abbrev-suggest-hint-threshold): * lisp/bookmark.el (bookmark-bmenu-file-column) (bookmark-menu-length): * lisp/buff-menu.el (Buffer-menu-size-width) (Buffer-menu-mode-width): * lisp/calendar/calendar.el (calendar-week-start-day) (calendar-intermonth-spacing, calendar-column-width) (calendar-day-digit-width): * lisp/calc/calc.el (calc-undo-length): * lisp/calendar/timeclock.el (timeclock-workday): * lisp/comint.el (comint-buffer-maximum-size) (comint-input-ring-size): * lisp/doc-view.el (doc-view-resolution, doc-view-image-width): * lisp/emacs-lisp/bytecomp.el (byte-compile-docstring-max-column): * lisp/emacs-lisp/comp.el (native-comp-debug) (native-comp-verbose, native-comp-async-jobs-number): * lisp/emacs-lisp/package.el (package-name-column-width) (package-version-column-width, package-status-column-width) (package-archive-column-width): * lisp/eshell/esh-mode.el (eshell-buffer-maximum-lines): * lisp/frame.el (blink-cursor-blinks): * lisp/info.el (Info-breadcrumbs-depth): * lisp/jit-lock.el (jit-lock-chunk-size): * lisp/kmacro.el (kmacro-ring-max): * lisp/menu-bar.el (yank-menu-length, yank-menu-max-items): * lisp/midnight.el (clean-buffer-list-delay-general) (clean-buffer-list-delay-special): * lisp/net/dictionary.el (dictionary-port) (dictionary-proxy-port): * lisp/net/ldap.el (ldap-default-port): * lisp/net/pop3.el (pop3-port, pop3-stream-length): * lisp/net/rcirc.el (rcirc-default-port): * lisp/net/sieve-manage.el (sieve-manage-default-port): * lisp/play/spook.el (spook-phrase-default-count): * lisp/play/tetris.el (tetris-buffer-width) (tetris-buffer-height, tetris-width, tetris-height) (tetris-top-left-x, tetris-top-left-y): * lisp/profiler.el (profiler-sampling-interval): * lisp/progmodes/sql.el (sql-port): * lisp/recentf.el (recentf-max-menu-items): * lisp/strokes.el (strokes-grid-resolution): * lisp/tab-bar.el (tab-bar-tab-name-truncated-max): * lisp/term/xterm.el (xterm-max-cut-length): * lisp/time.el (display-time-interval, world-clock-timer-second): * lisp/url/url-cache.el (url-cache-expire-time): * lisp/url/url-cookie.el (url-cookie-save-interval): * lisp/url/url-history.el (url-history-save-interval): * lisp/url/url-queue.el (url-queue-parallel-processes) (url-queue-timeout): * lisp/url/url-vars.el (url-max-password-attempts) (url-max-redirections): * lisp/vc/emerge.el (emerge-min-visible-lines): * lisp/vc/vc.el (vc-log-show-limit): * lisp/window.el (window-min-height, window-min-width): * lisp/winner.el (winner-ring-size): Use :type natnum. * lisp/savehist.el (savehist-file-modes): Fix setting to nil value and use :type natnum.
2022-07-05 16:26:45 +02:00
:type '(choice natnum string)
:version "24.4")
(defcustom sieve-manage-default-stream 'network
"Default stream type to use for `sieve-manage'."
Add missing :version tags to new defgroups and defcustoms * window.el (window-sides-slots): * tool-bar.el (tool-bar-position): * term/xterm.el (xterm-extra-capabilities): * ses.el (ses-self-reference-early-detection): * progmodes/verilog-mode.el (verilog-auto-declare-nettype) (verilog-auto-wire-type) (verilog-auto-delete-trailing-whitespace) (verilog-auto-reset-blocking-in-non, verilog-auto-inst-sort) (verilog-auto-tieoff-declaration): * progmodes/sql.el (sql-login-hook, sql-ansi-statement-starters) (sql-oracle-statement-starters, sql-oracle-scan-on): * progmodes/prolog.el (prolog-align-comments-flag) (prolog-indent-mline-comments-flag, prolog-object-end-to-0-flag) (prolog-left-indent-regexp, prolog-paren-indent-p) (prolog-paren-indent, prolog-parse-mode, prolog-keywords) (prolog-types, prolog-mode-specificators) (prolog-determinism-specificators, prolog-directives) (prolog-electric-newline-flag, prolog-hungry-delete-key-flag) (prolog-electric-dot-flag) (prolog-electric-dot-full-predicate-template) (prolog-electric-underscore-flag, prolog-electric-tab-flag) (prolog-electric-if-then-else-flag, prolog-electric-colon-flag) (prolog-electric-dash-flag, prolog-old-sicstus-keys-flag) (prolog-program-switches, prolog-prompt-regexp) (prolog-debug-on-string, prolog-debug-off-string) (prolog-trace-on-string, prolog-trace-off-string) (prolog-zip-on-string, prolog-zip-off-string) (prolog-use-standard-consult-compile-method-flag) (prolog-use-prolog-tokenizer-flag, prolog-imenu-flag) (prolog-imenu-max-lines, prolog-info-predicate-index) (prolog-underscore-wordchar-flag, prolog-use-sicstus-sd) (prolog-char-quote-workaround): * progmodes/cc-vars.el (c-defun-tactic): * net/tramp.el (tramp-encoding-command-interactive) (tramp-local-end-of-line): * net/soap-client.el (soap-client): * net/netrc.el (netrc-file): * net/gnutls.el (gnutls): * minibuffer.el (completion-category-overrides) (completion-cycle-threshold) (completion-pcm-complete-word-inserts-delimiters): * man.el (Man-name-local-regexp): * mail/feedmail.el (feedmail-display-full-frame): * international/characters.el (glyphless-char-display-control): * eshell/em-ls.el (eshell-ls-date-format): * emacs-lisp/cl-indent.el (lisp-lambda-list-keyword-alignment) (lisp-lambda-list-keyword-parameter-indentation) (lisp-lambda-list-keyword-parameter-alignment): * doc-view.el (doc-view-image-width, doc-view-unoconv-program): * dired-x.el (dired-omit-verbose): * cus-theme.el (custom-theme-allow-multiple-selections): * calc/calc.el (calc-highlight-selections-with-faces) (calc-lu-field-reference, calc-lu-power-reference) (calc-note-threshold): * battery.el (battery-mode-line-limit): * arc-mode.el (archive-7z-extract, archive-7z-expunge) (archive-7z-update): * allout.el (allout-prefixed-keybindings) (allout-unprefixed-keybindings) (allout-inhibit-auto-fill-on-headline) (allout-flattened-numbering-abbreviation): * allout-widgets.el (allout-widgets-auto-activation) (allout-widgets-icons-dark-subdir) (allout-widgets-icons-light-subdir, allout-widgets-icon-types) (allout-widgets-theme-dark-background) (allout-widgets-theme-light-background) (allout-widgets-item-image-properties-emacs) (allout-widgets-item-image-properties-xemacs) (allout-widgets-run-unit-tests-on-load) (allout-widgets-time-decoration-activity) (allout-widgets-hook-error-post-time) (allout-widgets-track-decoration): * gnus/sieve-manage.el (sieve-manage-default-stream): * gnus/shr.el (shr): * gnus/nnir.el (nnir-ignored-newsgroups, nnir-summary-line-format) (nnir-retrieve-headers-override-function) (nnir-imap-default-search-key, nnir-notmuch-program) (nnir-notmuch-additional-switches, nnir-notmuch-remove-prefix) (nnir-method-default-engines): * gnus/message.el (message-cite-reply-position): * gnus/gssapi.el (gssapi-program): * gnus/gravatar.el (gravatar): * gnus/gnus-sum.el (gnus-refer-thread-use-nnir): * gnus/gnus-registry.el (gnus-registry-unfollowed-addresses) (gnus-registry-max-pruned-entries): * gnus/gnus-picon.el (gnus-picon-inhibit-top-level-domains): * gnus/gnus-int.el (gnus-after-set-mark-hook) (gnus-before-update-mark-hook): * gnus/gnus-async.el (gnus-async-post-fetch-function): * gnus/auth-source.el (auth-source-cache-expiry): Add missing :version tags to new defcustoms and defgroups.
2012-02-11 14:13:29 -08:00
:version "24.1"
:type 'symbol)
(defcustom sieve-manage-ignore-starttls nil
"Ignore STARTTLS even if STARTTLS capability is provided."
Update parameter :version to 26.1 in several defcustom Following defcustom where added or modified for 25.2 release. In fact all these changes belong to 26.1 release. * lisp/battery.el (battery-linux-sysfs-regexp) * lisp/comint.el (comint-password-prompt-regexp) * lisp/dired.el (dired-always-read-filesystem) * lisp/image.el (image-scaling-factor) * lisp/ibuf-ext.el (ibuffer-never-search-content-name) (ibuffer-never-search-content-mode) * lisp/mouse.el (mouse-select-region-move-to-beginning) * lisp/net/net-utils.el (iwconfig-program, iwconfig-program-options) (netstat-program, route-program, route-program-options) * lisp/net/sieve-manage.el (sieve-manage-default-stream) * lisp/progmodes/grep.el (grep-save-buffers) * lisp/vc/add-log.el (change-log-directory-files) * lisp/url/url-vars.el (url-user-agent) * lisp/vc/vc-hg.el (vc-hg-symbolic-revision-styles) (vc-hg-use-file-version-for-mode-line-version) (vc-hg-parse-hg-data-structures) * lisp/wdired.el (wdired-create-parent-directories) * lisp/faces.el (homoglyph, nobreak-hyphen, read-multiple-choice-face) * lisp/gnus/gnus-art.el (gnus-article-encrypt-protocol) (gnus-button-url-regexp) * lisp/window.el (switch-to-buffer-preserve-window-point) * lisp/ibuffer.el (ibuffer-formats, ibuffer-locked-char) (ibuffer-locked-buffer) * lisp/textmodes/flyspell.el (flyspell-sort-corrections-function) * lisp/emacs-lisp/edebug.el (edebug-sit-on-break) * lisp/gnus/message.el (message-user-fqdn) * lisp/simple.el (shell-command-dont-erase-buffer) (extended-command-suggest-shorter) * lisp/net/shr.el (shr-use-fonts) * lisp/files.el (mounted-file-systems, kill-emacs-query-functions)
2016-11-17 00:39:43 +09:00
:version "26.1"
:type 'boolean)
;; Internal variables:
(defconst sieve-manage-local-variables '(sieve-manage-server
sieve-manage-port
sieve-manage-auth
sieve-manage-stream
sieve-manage-process
sieve-manage-client-eol
sieve-manage-server-eol
sieve-manage-capability))
(defconst sieve-manage-coding-system-for-read 'binary)
(defconst sieve-manage-coding-system-for-write 'binary)
(defvar sieve-manage-stream nil)
(defvar sieve-manage-auth nil)
(defvar sieve-manage-server nil)
(defvar sieve-manage-port nil)
(defvar sieve-manage-state 'closed
"Managesieve state.
Valid states are `closed', `initial', `nonauth', and `auth'.")
(defvar sieve-manage-process nil)
(defvar sieve-manage-capability nil)
;; Internal utility functions
Fix (mostly multibyte) issues in sieve-manage.el (Bug#54154) The managesieve protocol (s. RFC5804) requires support for (a sightly restricted variant of) UTF-8 in script content and script names. This commit fixes/improves the handling of multibyte characters. In addition, `sieve-manage-getscript' now properly handles NO responses from the server instead of inflooping. There are also some logging improvements. * lisp/net/sieve-manage.el (sieve-manage--append-to-log): (sieve-manage--message): (sieve-manage--error): (sieve-manage-encode): (sieve-manage-decode): (sieve-manage-no-p): New functions. (sieve-manage-make-process-buffer): Switch process buffer to unibyte. (sieve-manage-open-server): Add `:coding 'raw-text-unix` to `open-network-stream' call. Use unix EOLs in order to keep matching CRLF (aka "\r\n") intact. (sieve-manage-send): Make sure that UTF-8 multibyte characters are properly encoded before sending data to the server. (sieve-manage-getscript): (sieve-manage-putscript): Use the changes above to fix down/uploading scripts containing UTF-8 multibyte characters. (sieve-manage-listscripts): (sieve-manage-havespace) (sieve-manage-getscript) (sieve-manage-putscript): (sieve-manage-deletescript): (sieve-manage-setactive): Use the changes above to fix handling of script names which contain UTF-8 multibyte characters. (sieve-manage-parse-string): (sieve-manage-getscript): Add handling of server responses with type NO. Abort `sieve-manage-getscript' and show error message in message area. (sieve-manage-erase): (sieve-manage-drop-next-answer): (sieve-manage-parse-crlf): Return erased/dropped data (instead of nil). (sieve-sasl-auth): (sieve-manage-getscript): (sieve-manage-erase): (sieve-manage-open-server): (sieve-manage-open): (sieve-manage-send): Improve logging.
2022-02-28 11:08:07 +01:00
(defun sieve-manage--append-to-log (&rest args)
"Append ARGS to sieve-manage log buffer.
ARGS can be a string or a list of strings.
The buffer to use for logging is specifified via
`sieve-manage-log'. If it is nil, logging is disabled."
(when sieve-manage-log
(with-current-buffer (or (get-buffer sieve-manage-log)
(with-current-buffer
(get-buffer-create sieve-manage-log)
(set-buffer-multibyte nil)
(buffer-disable-undo)))
(goto-char (point-max))
(apply #'insert args))))
(defun sieve-manage--message (format-string &rest args)
"Wrapper around `message' which also logs to sieve manage log.
See `sieve-manage--append-to-log'."
(let ((ret (apply #'message
(concat "sieve-manage: " format-string)
args)))
(sieve-manage--append-to-log ret "\n")
ret))
(defun sieve-manage--error (format-string &rest args)
"Wrapper around `error' which also logs to sieve manage log.
See `sieve-manage--append-to-log'."
(let ((msg (apply #'format
(concat "sieve-manage/ERROR: " format-string)
args)))
(sieve-manage--append-to-log msg "\n")
(error msg)))
(defun sieve-manage-encode (utf8-string)
"Convert UTF8-STRING to managesieve protocol octets."
(encode-coding-string utf8-string 'raw-text t))
(defun sieve-manage-decode (octets &optional buffer)
"Convert managesieve protocol OCTETS to utf-8 string.
If optional BUFFER is non-nil, insert decoded string into BUFFER."
(when octets
;; eol type unix is required to preserve "\r\n"
(decode-coding-string octets 'utf-8-unix t buffer)))
(defun sieve-manage-make-process-buffer ()
(with-current-buffer
(generate-new-buffer (format " *sieve %s:%s*"
sieve-manage-server
sieve-manage-port))
(mapc #'make-local-variable sieve-manage-local-variables)
Fix (mostly multibyte) issues in sieve-manage.el (Bug#54154) The managesieve protocol (s. RFC5804) requires support for (a sightly restricted variant of) UTF-8 in script content and script names. This commit fixes/improves the handling of multibyte characters. In addition, `sieve-manage-getscript' now properly handles NO responses from the server instead of inflooping. There are also some logging improvements. * lisp/net/sieve-manage.el (sieve-manage--append-to-log): (sieve-manage--message): (sieve-manage--error): (sieve-manage-encode): (sieve-manage-decode): (sieve-manage-no-p): New functions. (sieve-manage-make-process-buffer): Switch process buffer to unibyte. (sieve-manage-open-server): Add `:coding 'raw-text-unix` to `open-network-stream' call. Use unix EOLs in order to keep matching CRLF (aka "\r\n") intact. (sieve-manage-send): Make sure that UTF-8 multibyte characters are properly encoded before sending data to the server. (sieve-manage-getscript): (sieve-manage-putscript): Use the changes above to fix down/uploading scripts containing UTF-8 multibyte characters. (sieve-manage-listscripts): (sieve-manage-havespace) (sieve-manage-getscript) (sieve-manage-putscript): (sieve-manage-deletescript): (sieve-manage-setactive): Use the changes above to fix handling of script names which contain UTF-8 multibyte characters. (sieve-manage-parse-string): (sieve-manage-getscript): Add handling of server responses with type NO. Abort `sieve-manage-getscript' and show error message in message area. (sieve-manage-erase): (sieve-manage-drop-next-answer): (sieve-manage-parse-crlf): Return erased/dropped data (instead of nil). (sieve-sasl-auth): (sieve-manage-getscript): (sieve-manage-erase): (sieve-manage-open-server): (sieve-manage-open): (sieve-manage-send): Improve logging.
2022-02-28 11:08:07 +01:00
(set-buffer-multibyte nil)
(setq-local after-change-functions nil)
(buffer-disable-undo)
(current-buffer)))
(defun sieve-manage-erase (&optional p buffer)
Fix (mostly multibyte) issues in sieve-manage.el (Bug#54154) The managesieve protocol (s. RFC5804) requires support for (a sightly restricted variant of) UTF-8 in script content and script names. This commit fixes/improves the handling of multibyte characters. In addition, `sieve-manage-getscript' now properly handles NO responses from the server instead of inflooping. There are also some logging improvements. * lisp/net/sieve-manage.el (sieve-manage--append-to-log): (sieve-manage--message): (sieve-manage--error): (sieve-manage-encode): (sieve-manage-decode): (sieve-manage-no-p): New functions. (sieve-manage-make-process-buffer): Switch process buffer to unibyte. (sieve-manage-open-server): Add `:coding 'raw-text-unix` to `open-network-stream' call. Use unix EOLs in order to keep matching CRLF (aka "\r\n") intact. (sieve-manage-send): Make sure that UTF-8 multibyte characters are properly encoded before sending data to the server. (sieve-manage-getscript): (sieve-manage-putscript): Use the changes above to fix down/uploading scripts containing UTF-8 multibyte characters. (sieve-manage-listscripts): (sieve-manage-havespace) (sieve-manage-getscript) (sieve-manage-putscript): (sieve-manage-deletescript): (sieve-manage-setactive): Use the changes above to fix handling of script names which contain UTF-8 multibyte characters. (sieve-manage-parse-string): (sieve-manage-getscript): Add handling of server responses with type NO. Abort `sieve-manage-getscript' and show error message in message area. (sieve-manage-erase): (sieve-manage-drop-next-answer): (sieve-manage-parse-crlf): Return erased/dropped data (instead of nil). (sieve-sasl-auth): (sieve-manage-getscript): (sieve-manage-erase): (sieve-manage-open-server): (sieve-manage-open): (sieve-manage-send): Improve logging.
2022-02-28 11:08:07 +01:00
(with-current-buffer (or buffer (current-buffer))
(let* ((start (point-min))
(end (or p (point-max)))
(logdata (buffer-substring-no-properties start end)))
(sieve-manage--append-to-log logdata)
(delete-region start end)
logdata)))
(defun sieve-manage-open-server (server port &optional stream buffer)
"Open network connection to SERVER on PORT.
Return the buffer associated with the connection."
(with-current-buffer buffer
(sieve-manage-erase)
(setq sieve-manage-state 'initial)
(pcase-let ((`(,proc . ,props)
(open-network-stream
"SIEVE" buffer server port
:type stream
Fix (mostly multibyte) issues in sieve-manage.el (Bug#54154) The managesieve protocol (s. RFC5804) requires support for (a sightly restricted variant of) UTF-8 in script content and script names. This commit fixes/improves the handling of multibyte characters. In addition, `sieve-manage-getscript' now properly handles NO responses from the server instead of inflooping. There are also some logging improvements. * lisp/net/sieve-manage.el (sieve-manage--append-to-log): (sieve-manage--message): (sieve-manage--error): (sieve-manage-encode): (sieve-manage-decode): (sieve-manage-no-p): New functions. (sieve-manage-make-process-buffer): Switch process buffer to unibyte. (sieve-manage-open-server): Add `:coding 'raw-text-unix` to `open-network-stream' call. Use unix EOLs in order to keep matching CRLF (aka "\r\n") intact. (sieve-manage-send): Make sure that UTF-8 multibyte characters are properly encoded before sending data to the server. (sieve-manage-getscript): (sieve-manage-putscript): Use the changes above to fix down/uploading scripts containing UTF-8 multibyte characters. (sieve-manage-listscripts): (sieve-manage-havespace) (sieve-manage-getscript) (sieve-manage-putscript): (sieve-manage-deletescript): (sieve-manage-setactive): Use the changes above to fix handling of script names which contain UTF-8 multibyte characters. (sieve-manage-parse-string): (sieve-manage-getscript): Add handling of server responses with type NO. Abort `sieve-manage-getscript' and show error message in message area. (sieve-manage-erase): (sieve-manage-drop-next-answer): (sieve-manage-parse-crlf): Return erased/dropped data (instead of nil). (sieve-sasl-auth): (sieve-manage-getscript): (sieve-manage-erase): (sieve-manage-open-server): (sieve-manage-open): (sieve-manage-send): Improve logging.
2022-02-28 11:08:07 +01:00
;; eol type unix is required to preserve "\r\n"
:coding 'raw-text-unix
:capability-command "CAPABILITY\r\n"
:end-of-command "^\\(OK\\|NO\\).*\n"
:success "^OK.*\n"
:return-list t
:starttls-function
(lambda (capabilities)
(when (and (not sieve-manage-ignore-starttls)
(string-match "\\bSTARTTLS\\b" capabilities))
"STARTTLS\r\n")))))
(setq sieve-manage-process proc)
(setq sieve-manage-capability
(sieve-manage-parse-capability (plist-get props :capabilities)))
;; Ignore new capabilities issues after successful STARTTLS
(when (or sieve-manage-ignore-starttls
(and (memq stream '(nil network starttls))
(eq (plist-get props :type) 'tls)))
(sieve-manage-drop-next-answer))
(current-buffer))))
;; Authenticators
(defun sieve-sasl-auth (buffer mech)
"Login to server using the SASL MECH method."
Fix (mostly multibyte) issues in sieve-manage.el (Bug#54154) The managesieve protocol (s. RFC5804) requires support for (a sightly restricted variant of) UTF-8 in script content and script names. This commit fixes/improves the handling of multibyte characters. In addition, `sieve-manage-getscript' now properly handles NO responses from the server instead of inflooping. There are also some logging improvements. * lisp/net/sieve-manage.el (sieve-manage--append-to-log): (sieve-manage--message): (sieve-manage--error): (sieve-manage-encode): (sieve-manage-decode): (sieve-manage-no-p): New functions. (sieve-manage-make-process-buffer): Switch process buffer to unibyte. (sieve-manage-open-server): Add `:coding 'raw-text-unix` to `open-network-stream' call. Use unix EOLs in order to keep matching CRLF (aka "\r\n") intact. (sieve-manage-send): Make sure that UTF-8 multibyte characters are properly encoded before sending data to the server. (sieve-manage-getscript): (sieve-manage-putscript): Use the changes above to fix down/uploading scripts containing UTF-8 multibyte characters. (sieve-manage-listscripts): (sieve-manage-havespace) (sieve-manage-getscript) (sieve-manage-putscript): (sieve-manage-deletescript): (sieve-manage-setactive): Use the changes above to fix handling of script names which contain UTF-8 multibyte characters. (sieve-manage-parse-string): (sieve-manage-getscript): Add handling of server responses with type NO. Abort `sieve-manage-getscript' and show error message in message area. (sieve-manage-erase): (sieve-manage-drop-next-answer): (sieve-manage-parse-crlf): Return erased/dropped data (instead of nil). (sieve-sasl-auth): (sieve-manage-getscript): (sieve-manage-erase): (sieve-manage-open-server): (sieve-manage-open): (sieve-manage-send): Improve logging.
2022-02-28 11:08:07 +01:00
(sieve-manage--message "Authenticating using %s..." mech)
2010-10-06 13:13:11 +00:00
(with-current-buffer buffer
Merge changes made in Gnus trunk. auth.texi (Overview, Help for users, Help for developers): Update docs. (Help for users): Talk about spaces. sieve-manage.el: Autoload `auth-source-search'. (sieve-sasl-auth): Use it. nnimap.el: Autoload `auth-source-forget+'. (nnimap-open-connection-1): Use it if the connection fails. auth-source.el: Require `password-cache'. (auth-source-hide-passwords, auth-source-cache): Remove and mark obsolete. (auth-source-magic): Marker for `password-cache' keys. (auth-source-do-cache): Update docstring. (auth-source-search): Use and check cache. (auth-source-forget-all-cached, auth-source-remember) (auth-source-recall, auth-source-forget, auth-source-forget+) (auth-source-specmatchp): Caching support functions. (auth-source-forget-user-or-password, auth-source-forget-all-cached): Remove and obsolete. (auth-source-user-or-password): Remove caching to further discourage using it. Always hide passwords. password-cache.el (password-cache-remove): Accept secrets that are not strings. mail-source.el: Autoload `auth-source-search'. (mail-source-keyword-map): Note order matters. (mail-source-set-1): Get all the mail-source source values and defaults and search auth-source on those if needed. This can all probably be simplified. nnimap.el: Autoload `auth-source-search'. (nnimap-credentials): Use it. (nnimap-open-connection-1): Ask for the virtual server and physical address in one shot. nntp.el: Autoload `auth-source-search'. (nntp-send-authinfo): Use it. Note TODO. auth-source.el (auth-source-secrets-search, auth-source-user-or-password): Use `append' instead of `nconc'. (auth-source-user-or-password): Build return list better and protect against nil :secret. auth-source.el (top): Require 'eieio unconditionally. Autoload `secrets-get-attributes' instead of `secrets-get-attribute'. (auth-source-secrets-search): Limit search when `max' is greater than number of results. auth-source.el (auth-source-secrets-search): Add examples. auth-source.el (auth-sources): Allow for simpler defaults for Secrets API with a string "secrets:collection-name" and with 'default. (auth-source-backend-parse): Parse "secrets:collection-name" and 'default. Recurse on parses instead of repeating code. Use the Secrets API is the source is not nil and 'ignore otherwise. Emit a message when ignoring a source. (auth-source-search): List ignored search keys at the top level. (auth-source-netrc-create): Use `case' instead of `cond'. (auth-source-secrets-search): Created with TODOs. (auth-source-secrets-create): Created with TODOs. (auth-source-retrieve, auth-source-create, auth-source-delete) (auth-source-protocol-defaults, auth-source-user-or-password-imap) (auth-source-user-or-password-pop3, auth-source-user-or-password-ssh) (auth-source-user-or-password-sftp) (auth-source-user-or-password-smtp): Removed. (auth-source-user-or-password): Deprecated and modified to be a wrapper around `auth-source-search'. Not tested thoroughly. auth-source.el: Bring in assoc and eioeio libraries. (secrets-enabled): New variable to track the status of the Secrets API. (auth-source-backend): New EIOEIO class to represent a backend. (auth-source-creation-defaults): New variable to set prompt defaults during token creation (see the `auth-source-search' docstring for details). (auth-sources): Simplify to allow a simple string as a netrc backend spec. (auth-source-backend-parse): Parse a backend from an `auth-sources' spec. (auth-source-backend-parse-parameters): Fill in the backend parameters. (auth-source-search): Main auth-source API entry point. (auth-source-delete): Wrapper around `auth-source-search' for deletion. (auth-source-search-collection): Helper function for searching. (auth-source-netrc-parse, auth-source-netrc-normalize) (auth-source-netrc-search, auth-source-netrc-create): Netrc backend. Supports search, create, and delete. (auth-source-secrets-search, auth-source-secrets-create): Secrets API backend stubs. (auth-source-user-or-password): Call `auth-source-search' but it's not ready yet.
2011-02-13 00:25:29 +00:00
(let* ((auth-info (auth-source-search :host sieve-manage-server
:port "sieve"
:max 1
:create t))
(user-name (or (plist-get (nth 0 auth-info) :user) ""))
(user-password (or (auth-info-password (nth 0 auth-info)) ""))
2010-10-06 13:13:11 +00:00
(client (sasl-make-client (sasl-find-mechanism (list mech))
Merge changes made in Gnus trunk. auth.texi (Overview, Help for users, Help for developers): Update docs. (Help for users): Talk about spaces. sieve-manage.el: Autoload `auth-source-search'. (sieve-sasl-auth): Use it. nnimap.el: Autoload `auth-source-forget+'. (nnimap-open-connection-1): Use it if the connection fails. auth-source.el: Require `password-cache'. (auth-source-hide-passwords, auth-source-cache): Remove and mark obsolete. (auth-source-magic): Marker for `password-cache' keys. (auth-source-do-cache): Update docstring. (auth-source-search): Use and check cache. (auth-source-forget-all-cached, auth-source-remember) (auth-source-recall, auth-source-forget, auth-source-forget+) (auth-source-specmatchp): Caching support functions. (auth-source-forget-user-or-password, auth-source-forget-all-cached): Remove and obsolete. (auth-source-user-or-password): Remove caching to further discourage using it. Always hide passwords. password-cache.el (password-cache-remove): Accept secrets that are not strings. mail-source.el: Autoload `auth-source-search'. (mail-source-keyword-map): Note order matters. (mail-source-set-1): Get all the mail-source source values and defaults and search auth-source on those if needed. This can all probably be simplified. nnimap.el: Autoload `auth-source-search'. (nnimap-credentials): Use it. (nnimap-open-connection-1): Ask for the virtual server and physical address in one shot. nntp.el: Autoload `auth-source-search'. (nntp-send-authinfo): Use it. Note TODO. auth-source.el (auth-source-secrets-search, auth-source-user-or-password): Use `append' instead of `nconc'. (auth-source-user-or-password): Build return list better and protect against nil :secret. auth-source.el (top): Require 'eieio unconditionally. Autoload `secrets-get-attributes' instead of `secrets-get-attribute'. (auth-source-secrets-search): Limit search when `max' is greater than number of results. auth-source.el (auth-source-secrets-search): Add examples. auth-source.el (auth-sources): Allow for simpler defaults for Secrets API with a string "secrets:collection-name" and with 'default. (auth-source-backend-parse): Parse "secrets:collection-name" and 'default. Recurse on parses instead of repeating code. Use the Secrets API is the source is not nil and 'ignore otherwise. Emit a message when ignoring a source. (auth-source-search): List ignored search keys at the top level. (auth-source-netrc-create): Use `case' instead of `cond'. (auth-source-secrets-search): Created with TODOs. (auth-source-secrets-create): Created with TODOs. (auth-source-retrieve, auth-source-create, auth-source-delete) (auth-source-protocol-defaults, auth-source-user-or-password-imap) (auth-source-user-or-password-pop3, auth-source-user-or-password-ssh) (auth-source-user-or-password-sftp) (auth-source-user-or-password-smtp): Removed. (auth-source-user-or-password): Deprecated and modified to be a wrapper around `auth-source-search'. Not tested thoroughly. auth-source.el: Bring in assoc and eioeio libraries. (secrets-enabled): New variable to track the status of the Secrets API. (auth-source-backend): New EIOEIO class to represent a backend. (auth-source-creation-defaults): New variable to set prompt defaults during token creation (see the `auth-source-search' docstring for details). (auth-sources): Simplify to allow a simple string as a netrc backend spec. (auth-source-backend-parse): Parse a backend from an `auth-sources' spec. (auth-source-backend-parse-parameters): Fill in the backend parameters. (auth-source-search): Main auth-source API entry point. (auth-source-delete): Wrapper around `auth-source-search' for deletion. (auth-source-search-collection): Helper function for searching. (auth-source-netrc-parse, auth-source-netrc-normalize) (auth-source-netrc-search, auth-source-netrc-create): Netrc backend. Supports search, create, and delete. (auth-source-secrets-search, auth-source-secrets-create): Secrets API backend stubs. (auth-source-user-or-password): Call `auth-source-search' but it's not ready yet.
2011-02-13 00:25:29 +00:00
user-name "sieve" sieve-manage-server))
2010-10-06 13:13:11 +00:00
(sasl-read-passphrase
;; We *need* to copy the password, because sasl will modify it
;; somehow.
(lambda (_prompt) (copy-sequence user-password)))
2010-10-06 13:13:11 +00:00
(step (sasl-next-step client nil))
(_tag (sieve-manage-send
2010-10-06 13:13:11 +00:00
(concat
"AUTHENTICATE \""
mech
"\""
(and (sasl-step-data step)
(concat
" \""
(base64-encode-string
(sasl-step-data step)
'no-line-break)
"\"")))))
data rsp)
(catch 'done
(while t
(setq rsp nil)
(goto-char (point-min))
(while (null (or (progn
(setq rsp (sieve-manage-is-string))
(if (not (and rsp (looking-at
sieve-manage-server-eol)))
(setq rsp nil)
(goto-char (match-end 0))
rsp))
(setq rsp (sieve-manage-is-okno))))
(accept-process-output sieve-manage-process 1)
(goto-char (point-min)))
(sieve-manage-erase)
(when (sieve-manage-ok-p rsp)
(when (and (cadr rsp)
(string-match "^SASL \"\\([^\"]+\\)\"" (cadr rsp)))
(sasl-step-set-data
step (base64-decode-string (match-string 1 (cadr rsp)))))
(if (and (setq step (sasl-next-step client step))
(setq data (sasl-step-data step)))
;; We got data for server but it's finished
Fix (mostly multibyte) issues in sieve-manage.el (Bug#54154) The managesieve protocol (s. RFC5804) requires support for (a sightly restricted variant of) UTF-8 in script content and script names. This commit fixes/improves the handling of multibyte characters. In addition, `sieve-manage-getscript' now properly handles NO responses from the server instead of inflooping. There are also some logging improvements. * lisp/net/sieve-manage.el (sieve-manage--append-to-log): (sieve-manage--message): (sieve-manage--error): (sieve-manage-encode): (sieve-manage-decode): (sieve-manage-no-p): New functions. (sieve-manage-make-process-buffer): Switch process buffer to unibyte. (sieve-manage-open-server): Add `:coding 'raw-text-unix` to `open-network-stream' call. Use unix EOLs in order to keep matching CRLF (aka "\r\n") intact. (sieve-manage-send): Make sure that UTF-8 multibyte characters are properly encoded before sending data to the server. (sieve-manage-getscript): (sieve-manage-putscript): Use the changes above to fix down/uploading scripts containing UTF-8 multibyte characters. (sieve-manage-listscripts): (sieve-manage-havespace) (sieve-manage-getscript) (sieve-manage-putscript): (sieve-manage-deletescript): (sieve-manage-setactive): Use the changes above to fix handling of script names which contain UTF-8 multibyte characters. (sieve-manage-parse-string): (sieve-manage-getscript): Add handling of server responses with type NO. Abort `sieve-manage-getscript' and show error message in message area. (sieve-manage-erase): (sieve-manage-drop-next-answer): (sieve-manage-parse-crlf): Return erased/dropped data (instead of nil). (sieve-sasl-auth): (sieve-manage-getscript): (sieve-manage-erase): (sieve-manage-open-server): (sieve-manage-open): (sieve-manage-send): Improve logging.
2022-02-28 11:08:07 +01:00
(sieve-manage--error
"Server not ready for SASL data: %s" data)
2010-10-06 13:13:11 +00:00
;; The authentication process is finished.
Fix (mostly multibyte) issues in sieve-manage.el (Bug#54154) The managesieve protocol (s. RFC5804) requires support for (a sightly restricted variant of) UTF-8 in script content and script names. This commit fixes/improves the handling of multibyte characters. In addition, `sieve-manage-getscript' now properly handles NO responses from the server instead of inflooping. There are also some logging improvements. * lisp/net/sieve-manage.el (sieve-manage--append-to-log): (sieve-manage--message): (sieve-manage--error): (sieve-manage-encode): (sieve-manage-decode): (sieve-manage-no-p): New functions. (sieve-manage-make-process-buffer): Switch process buffer to unibyte. (sieve-manage-open-server): Add `:coding 'raw-text-unix` to `open-network-stream' call. Use unix EOLs in order to keep matching CRLF (aka "\r\n") intact. (sieve-manage-send): Make sure that UTF-8 multibyte characters are properly encoded before sending data to the server. (sieve-manage-getscript): (sieve-manage-putscript): Use the changes above to fix down/uploading scripts containing UTF-8 multibyte characters. (sieve-manage-listscripts): (sieve-manage-havespace) (sieve-manage-getscript) (sieve-manage-putscript): (sieve-manage-deletescript): (sieve-manage-setactive): Use the changes above to fix handling of script names which contain UTF-8 multibyte characters. (sieve-manage-parse-string): (sieve-manage-getscript): Add handling of server responses with type NO. Abort `sieve-manage-getscript' and show error message in message area. (sieve-manage-erase): (sieve-manage-drop-next-answer): (sieve-manage-parse-crlf): Return erased/dropped data (instead of nil). (sieve-sasl-auth): (sieve-manage-getscript): (sieve-manage-erase): (sieve-manage-open-server): (sieve-manage-open): (sieve-manage-send): Improve logging.
2022-02-28 11:08:07 +01:00
(sieve-manage--message "Logged in as %s using %s"
user-name mech)
2010-10-06 13:13:11 +00:00
(throw 'done t)))
(unless (stringp rsp)
Fix (mostly multibyte) issues in sieve-manage.el (Bug#54154) The managesieve protocol (s. RFC5804) requires support for (a sightly restricted variant of) UTF-8 in script content and script names. This commit fixes/improves the handling of multibyte characters. In addition, `sieve-manage-getscript' now properly handles NO responses from the server instead of inflooping. There are also some logging improvements. * lisp/net/sieve-manage.el (sieve-manage--append-to-log): (sieve-manage--message): (sieve-manage--error): (sieve-manage-encode): (sieve-manage-decode): (sieve-manage-no-p): New functions. (sieve-manage-make-process-buffer): Switch process buffer to unibyte. (sieve-manage-open-server): Add `:coding 'raw-text-unix` to `open-network-stream' call. Use unix EOLs in order to keep matching CRLF (aka "\r\n") intact. (sieve-manage-send): Make sure that UTF-8 multibyte characters are properly encoded before sending data to the server. (sieve-manage-getscript): (sieve-manage-putscript): Use the changes above to fix down/uploading scripts containing UTF-8 multibyte characters. (sieve-manage-listscripts): (sieve-manage-havespace) (sieve-manage-getscript) (sieve-manage-putscript): (sieve-manage-deletescript): (sieve-manage-setactive): Use the changes above to fix handling of script names which contain UTF-8 multibyte characters. (sieve-manage-parse-string): (sieve-manage-getscript): Add handling of server responses with type NO. Abort `sieve-manage-getscript' and show error message in message area. (sieve-manage-erase): (sieve-manage-drop-next-answer): (sieve-manage-parse-crlf): Return erased/dropped data (instead of nil). (sieve-sasl-auth): (sieve-manage-getscript): (sieve-manage-erase): (sieve-manage-open-server): (sieve-manage-open): (sieve-manage-send): Improve logging.
2022-02-28 11:08:07 +01:00
(sieve-manage--error
"Server aborted SASL authentication: %s" (caddr rsp)))
2010-10-06 13:13:11 +00:00
(sasl-step-set-data step (base64-decode-string rsp))
(setq step (sasl-next-step client step))
(sieve-manage-send
(if (sasl-step-data step)
(concat "\""
(base64-encode-string (sasl-step-data step)
'no-line-break)
"\"")
Fix (mostly multibyte) issues in sieve-manage.el (Bug#54154) The managesieve protocol (s. RFC5804) requires support for (a sightly restricted variant of) UTF-8 in script content and script names. This commit fixes/improves the handling of multibyte characters. In addition, `sieve-manage-getscript' now properly handles NO responses from the server instead of inflooping. There are also some logging improvements. * lisp/net/sieve-manage.el (sieve-manage--append-to-log): (sieve-manage--message): (sieve-manage--error): (sieve-manage-encode): (sieve-manage-decode): (sieve-manage-no-p): New functions. (sieve-manage-make-process-buffer): Switch process buffer to unibyte. (sieve-manage-open-server): Add `:coding 'raw-text-unix` to `open-network-stream' call. Use unix EOLs in order to keep matching CRLF (aka "\r\n") intact. (sieve-manage-send): Make sure that UTF-8 multibyte characters are properly encoded before sending data to the server. (sieve-manage-getscript): (sieve-manage-putscript): Use the changes above to fix down/uploading scripts containing UTF-8 multibyte characters. (sieve-manage-listscripts): (sieve-manage-havespace) (sieve-manage-getscript) (sieve-manage-putscript): (sieve-manage-deletescript): (sieve-manage-setactive): Use the changes above to fix handling of script names which contain UTF-8 multibyte characters. (sieve-manage-parse-string): (sieve-manage-getscript): Add handling of server responses with type NO. Abort `sieve-manage-getscript' and show error message in message area. (sieve-manage-erase): (sieve-manage-drop-next-answer): (sieve-manage-parse-crlf): Return erased/dropped data (instead of nil). (sieve-sasl-auth): (sieve-manage-getscript): (sieve-manage-erase): (sieve-manage-open-server): (sieve-manage-open): (sieve-manage-send): Improve logging.
2022-02-28 11:08:07 +01:00
"")))))))
(defun sieve-manage-cram-md5-p (buffer)
(sieve-manage-capability "SASL" "CRAM-MD5" buffer))
(defun sieve-manage-cram-md5-auth (buffer)
"Login to managesieve server using the CRAM-MD5 SASL method."
(sieve-sasl-auth buffer "CRAM-MD5"))
(defun sieve-manage-digest-md5-p (buffer)
(sieve-manage-capability "SASL" "DIGEST-MD5" buffer))
(defun sieve-manage-digest-md5-auth (buffer)
"Login to managesieve server using the DIGEST-MD5 SASL method."
(sieve-sasl-auth buffer "DIGEST-MD5"))
(defun sieve-manage-scram-md5-p (buffer)
(sieve-manage-capability "SASL" "SCRAM-MD5" buffer))
(defun sieve-manage-scram-md5-auth (buffer)
"Login to managesieve server using the SCRAM-MD5 SASL method."
(sieve-sasl-auth buffer "SCRAM-MD5"))
(defun sieve-manage-ntlm-p (buffer)
(sieve-manage-capability "SASL" "NTLM" buffer))
(defun sieve-manage-ntlm-auth (buffer)
"Login to managesieve server using the NTLM SASL method."
(sieve-sasl-auth buffer "NTLM"))
(defun sieve-manage-plain-p (buffer)
(sieve-manage-capability "SASL" "PLAIN" buffer))
(defun sieve-manage-plain-auth (buffer)
"Login to managesieve server using the PLAIN SASL method."
(sieve-sasl-auth buffer "PLAIN"))
(defun sieve-manage-login-p (buffer)
(sieve-manage-capability "SASL" "LOGIN" buffer))
(defun sieve-manage-login-auth (buffer)
"Login to managesieve server using the LOGIN SASL method."
(sieve-sasl-auth buffer "LOGIN"))
;; Managesieve API
(defun sieve-manage-open (server &optional port stream auth buffer)
"Open a network connection to a managesieve SERVER (string).
Optional argument PORT is port number (integer) on remote server.
Optional argument STREAM is any of `sieve-manage-streams' (a symbol).
Optional argument AUTH indicates authenticator to use, see
`sieve-manage-authenticators' for available authenticators.
If nil, chooses the best stream the server is capable of.
Optional argument BUFFER is buffer (buffer, or string naming buffer)
to work in."
(setq sieve-manage-port (or port sieve-manage-default-port))
(with-current-buffer (or buffer (sieve-manage-make-process-buffer))
(setq sieve-manage-server (or server
sieve-manage-server)
sieve-manage-stream (or stream
sieve-manage-stream
sieve-manage-default-stream)
sieve-manage-auth (or auth
sieve-manage-auth))
Fix (mostly multibyte) issues in sieve-manage.el (Bug#54154) The managesieve protocol (s. RFC5804) requires support for (a sightly restricted variant of) UTF-8 in script content and script names. This commit fixes/improves the handling of multibyte characters. In addition, `sieve-manage-getscript' now properly handles NO responses from the server instead of inflooping. There are also some logging improvements. * lisp/net/sieve-manage.el (sieve-manage--append-to-log): (sieve-manage--message): (sieve-manage--error): (sieve-manage-encode): (sieve-manage-decode): (sieve-manage-no-p): New functions. (sieve-manage-make-process-buffer): Switch process buffer to unibyte. (sieve-manage-open-server): Add `:coding 'raw-text-unix` to `open-network-stream' call. Use unix EOLs in order to keep matching CRLF (aka "\r\n") intact. (sieve-manage-send): Make sure that UTF-8 multibyte characters are properly encoded before sending data to the server. (sieve-manage-getscript): (sieve-manage-putscript): Use the changes above to fix down/uploading scripts containing UTF-8 multibyte characters. (sieve-manage-listscripts): (sieve-manage-havespace) (sieve-manage-getscript) (sieve-manage-putscript): (sieve-manage-deletescript): (sieve-manage-setactive): Use the changes above to fix handling of script names which contain UTF-8 multibyte characters. (sieve-manage-parse-string): (sieve-manage-getscript): Add handling of server responses with type NO. Abort `sieve-manage-getscript' and show error message in message area. (sieve-manage-erase): (sieve-manage-drop-next-answer): (sieve-manage-parse-crlf): Return erased/dropped data (instead of nil). (sieve-sasl-auth): (sieve-manage-getscript): (sieve-manage-erase): (sieve-manage-open-server): (sieve-manage-open): (sieve-manage-send): Improve logging.
2022-02-28 11:08:07 +01:00
(sieve-manage--message "Connecting to %s..." sieve-manage-server)
(sieve-manage-open-server sieve-manage-server
sieve-manage-port
sieve-manage-stream
(current-buffer))
(when (sieve-manage-opened (current-buffer))
;; Choose authenticator
(when (and (null sieve-manage-auth)
(not (eq sieve-manage-state 'auth)))
(cl-dolist (auth sieve-manage-authenticators)
(when (funcall (nth 1 (assq auth sieve-manage-authenticator-alist))
buffer)
(setq sieve-manage-auth auth)
(cl-return)))
(unless sieve-manage-auth
Fix (mostly multibyte) issues in sieve-manage.el (Bug#54154) The managesieve protocol (s. RFC5804) requires support for (a sightly restricted variant of) UTF-8 in script content and script names. This commit fixes/improves the handling of multibyte characters. In addition, `sieve-manage-getscript' now properly handles NO responses from the server instead of inflooping. There are also some logging improvements. * lisp/net/sieve-manage.el (sieve-manage--append-to-log): (sieve-manage--message): (sieve-manage--error): (sieve-manage-encode): (sieve-manage-decode): (sieve-manage-no-p): New functions. (sieve-manage-make-process-buffer): Switch process buffer to unibyte. (sieve-manage-open-server): Add `:coding 'raw-text-unix` to `open-network-stream' call. Use unix EOLs in order to keep matching CRLF (aka "\r\n") intact. (sieve-manage-send): Make sure that UTF-8 multibyte characters are properly encoded before sending data to the server. (sieve-manage-getscript): (sieve-manage-putscript): Use the changes above to fix down/uploading scripts containing UTF-8 multibyte characters. (sieve-manage-listscripts): (sieve-manage-havespace) (sieve-manage-getscript) (sieve-manage-putscript): (sieve-manage-deletescript): (sieve-manage-setactive): Use the changes above to fix handling of script names which contain UTF-8 multibyte characters. (sieve-manage-parse-string): (sieve-manage-getscript): Add handling of server responses with type NO. Abort `sieve-manage-getscript' and show error message in message area. (sieve-manage-erase): (sieve-manage-drop-next-answer): (sieve-manage-parse-crlf): Return erased/dropped data (instead of nil). (sieve-sasl-auth): (sieve-manage-getscript): (sieve-manage-erase): (sieve-manage-open-server): (sieve-manage-open): (sieve-manage-send): Improve logging.
2022-02-28 11:08:07 +01:00
(sieve-manage--error
"Couldn't figure out authenticator for server")))
(sieve-manage-erase)
(current-buffer))))
(defun sieve-manage-authenticate (&optional buffer)
"Authenticate on server in BUFFER.
Return `sieve-manage-state' value."
(with-current-buffer (or buffer (current-buffer))
(if (eq sieve-manage-state 'nonauth)
(when (funcall (nth 2 (assq sieve-manage-auth
sieve-manage-authenticator-alist))
(current-buffer))
(setq sieve-manage-state 'auth))
sieve-manage-state)))
(defun sieve-manage-opened (&optional buffer)
"Return non-nil if connection to managesieve server in BUFFER is open.
If BUFFER is nil then the current buffer is used."
(and (setq buffer (get-buffer (or buffer (current-buffer))))
(buffer-live-p buffer)
(with-current-buffer buffer
(and sieve-manage-process
(memq (process-status sieve-manage-process) '(open run))))))
(defun sieve-manage-close (&optional buffer)
"Close connection to managesieve server in BUFFER.
If BUFFER is nil, the current buffer is used."
(with-current-buffer (or buffer (current-buffer))
(when (sieve-manage-opened)
(sieve-manage-send "LOGOUT")
(sit-for 1))
(when (and sieve-manage-process
(memq (process-status sieve-manage-process) '(open run)))
(delete-process sieve-manage-process))
(setq sieve-manage-process nil)
(sieve-manage-erase)
t))
(defun sieve-manage-capability (&optional name value buffer)
"Check if capability NAME of server BUFFER match VALUE.
If it does, return the server value of NAME. If not return nil.
If VALUE is nil, do not check VALUE and return server value.
If NAME is nil, return the full server list of capabilities."
(with-current-buffer (or buffer (current-buffer))
(if (null name)
sieve-manage-capability
(let ((server-value (cadr (assoc name sieve-manage-capability))))
(when (or (null value)
(and server-value
(string-match value server-value)))
server-value)))))
(defun sieve-manage-listscripts (&optional buffer)
(with-current-buffer (or buffer (current-buffer))
(sieve-manage-send "LISTSCRIPTS")
(sieve-manage-parse-listscripts)))
(defun sieve-manage-havespace (name size &optional buffer)
(with-current-buffer (or buffer (current-buffer))
(sieve-manage-send (format "HAVESPACE \"%s\" %s" name size))
(sieve-manage-parse-okno)))
(defun sieve-manage-putscript (name content &optional buffer)
(with-current-buffer (or buffer (current-buffer))
(sieve-manage-send (format "PUTSCRIPT \"%s\" {%d+}%s%s" name
Fix (mostly multibyte) issues in sieve-manage.el (Bug#54154) The managesieve protocol (s. RFC5804) requires support for (a sightly restricted variant of) UTF-8 in script content and script names. This commit fixes/improves the handling of multibyte characters. In addition, `sieve-manage-getscript' now properly handles NO responses from the server instead of inflooping. There are also some logging improvements. * lisp/net/sieve-manage.el (sieve-manage--append-to-log): (sieve-manage--message): (sieve-manage--error): (sieve-manage-encode): (sieve-manage-decode): (sieve-manage-no-p): New functions. (sieve-manage-make-process-buffer): Switch process buffer to unibyte. (sieve-manage-open-server): Add `:coding 'raw-text-unix` to `open-network-stream' call. Use unix EOLs in order to keep matching CRLF (aka "\r\n") intact. (sieve-manage-send): Make sure that UTF-8 multibyte characters are properly encoded before sending data to the server. (sieve-manage-getscript): (sieve-manage-putscript): Use the changes above to fix down/uploading scripts containing UTF-8 multibyte characters. (sieve-manage-listscripts): (sieve-manage-havespace) (sieve-manage-getscript) (sieve-manage-putscript): (sieve-manage-deletescript): (sieve-manage-setactive): Use the changes above to fix handling of script names which contain UTF-8 multibyte characters. (sieve-manage-parse-string): (sieve-manage-getscript): Add handling of server responses with type NO. Abort `sieve-manage-getscript' and show error message in message area. (sieve-manage-erase): (sieve-manage-drop-next-answer): (sieve-manage-parse-crlf): Return erased/dropped data (instead of nil). (sieve-sasl-auth): (sieve-manage-getscript): (sieve-manage-erase): (sieve-manage-open-server): (sieve-manage-open): (sieve-manage-send): Improve logging.
2022-02-28 11:08:07 +01:00
(length (sieve-manage-encode content))
sieve-manage-client-eol content))
(sieve-manage-parse-okno)))
(defun sieve-manage-deletescript (name &optional buffer)
(with-current-buffer (or buffer (current-buffer))
(sieve-manage-send (format "DELETESCRIPT \"%s\"" name))
(sieve-manage-parse-okno)))
(defun sieve-manage-getscript (name output-buffer &optional buffer)
(with-current-buffer (or buffer (current-buffer))
(sieve-manage-send (format "GETSCRIPT \"%s\"" name))
Fix (mostly multibyte) issues in sieve-manage.el (Bug#54154) The managesieve protocol (s. RFC5804) requires support for (a sightly restricted variant of) UTF-8 in script content and script names. This commit fixes/improves the handling of multibyte characters. In addition, `sieve-manage-getscript' now properly handles NO responses from the server instead of inflooping. There are also some logging improvements. * lisp/net/sieve-manage.el (sieve-manage--append-to-log): (sieve-manage--message): (sieve-manage--error): (sieve-manage-encode): (sieve-manage-decode): (sieve-manage-no-p): New functions. (sieve-manage-make-process-buffer): Switch process buffer to unibyte. (sieve-manage-open-server): Add `:coding 'raw-text-unix` to `open-network-stream' call. Use unix EOLs in order to keep matching CRLF (aka "\r\n") intact. (sieve-manage-send): Make sure that UTF-8 multibyte characters are properly encoded before sending data to the server. (sieve-manage-getscript): (sieve-manage-putscript): Use the changes above to fix down/uploading scripts containing UTF-8 multibyte characters. (sieve-manage-listscripts): (sieve-manage-havespace) (sieve-manage-getscript) (sieve-manage-putscript): (sieve-manage-deletescript): (sieve-manage-setactive): Use the changes above to fix handling of script names which contain UTF-8 multibyte characters. (sieve-manage-parse-string): (sieve-manage-getscript): Add handling of server responses with type NO. Abort `sieve-manage-getscript' and show error message in message area. (sieve-manage-erase): (sieve-manage-drop-next-answer): (sieve-manage-parse-crlf): Return erased/dropped data (instead of nil). (sieve-sasl-auth): (sieve-manage-getscript): (sieve-manage-erase): (sieve-manage-open-server): (sieve-manage-open): (sieve-manage-send): Improve logging.
2022-02-28 11:08:07 +01:00
(sieve-manage-decode (sieve-manage-parse-string)
output-buffer)
(sieve-manage-parse-crlf)
(sieve-manage-parse-okno)))
(defun sieve-manage-setactive (name &optional buffer)
(with-current-buffer (or buffer (current-buffer))
(sieve-manage-send (format "SETACTIVE \"%s\"" name))
(sieve-manage-parse-okno)))
;; Protocol parsing routines
(defun sieve-manage-wait-for-answer ()
(let ((pattern "^\\(OK\\|NO\\).*\n")
pos)
(while (not pos)
(setq pos (search-forward-regexp pattern nil t))
(goto-char (point-min))
(sleep-for 0 50))
pos))
(defun sieve-manage-drop-next-answer ()
(sieve-manage-wait-for-answer)
(sieve-manage-erase))
(defun sieve-manage-ok-p (rsp)
(string= (downcase (or (car-safe rsp) "")) "ok"))
Fix (mostly multibyte) issues in sieve-manage.el (Bug#54154) The managesieve protocol (s. RFC5804) requires support for (a sightly restricted variant of) UTF-8 in script content and script names. This commit fixes/improves the handling of multibyte characters. In addition, `sieve-manage-getscript' now properly handles NO responses from the server instead of inflooping. There are also some logging improvements. * lisp/net/sieve-manage.el (sieve-manage--append-to-log): (sieve-manage--message): (sieve-manage--error): (sieve-manage-encode): (sieve-manage-decode): (sieve-manage-no-p): New functions. (sieve-manage-make-process-buffer): Switch process buffer to unibyte. (sieve-manage-open-server): Add `:coding 'raw-text-unix` to `open-network-stream' call. Use unix EOLs in order to keep matching CRLF (aka "\r\n") intact. (sieve-manage-send): Make sure that UTF-8 multibyte characters are properly encoded before sending data to the server. (sieve-manage-getscript): (sieve-manage-putscript): Use the changes above to fix down/uploading scripts containing UTF-8 multibyte characters. (sieve-manage-listscripts): (sieve-manage-havespace) (sieve-manage-getscript) (sieve-manage-putscript): (sieve-manage-deletescript): (sieve-manage-setactive): Use the changes above to fix handling of script names which contain UTF-8 multibyte characters. (sieve-manage-parse-string): (sieve-manage-getscript): Add handling of server responses with type NO. Abort `sieve-manage-getscript' and show error message in message area. (sieve-manage-erase): (sieve-manage-drop-next-answer): (sieve-manage-parse-crlf): Return erased/dropped data (instead of nil). (sieve-sasl-auth): (sieve-manage-getscript): (sieve-manage-erase): (sieve-manage-open-server): (sieve-manage-open): (sieve-manage-send): Improve logging.
2022-02-28 11:08:07 +01:00
(defun sieve-manage-no-p (rsp)
(string= (downcase (or (car-safe rsp) "")) "no"))
(defun sieve-manage-is-okno ()
(when (looking-at (concat
"^\\(OK\\|NO\\)\\( (\\([^)]+\\))\\)?\\( \\(.*\\)\\)?"
sieve-manage-server-eol))
(let ((status (match-string 1))
(resp-code (match-string 3))
(response (match-string 5)))
(when response
(goto-char (match-beginning 5))
(setq response (sieve-manage-is-string)))
(list status resp-code response))))
(defun sieve-manage-parse-okno ()
(let (rsp)
(while (null rsp)
(accept-process-output (get-buffer-process (current-buffer)) 1)
(goto-char (point-min))
(setq rsp (sieve-manage-is-okno)))
(sieve-manage-erase)
rsp))
(defun sieve-manage-parse-capability (str)
"Parse managesieve capability string `STR'.
Return alist of capabilities, suitable for assignment
to local variable `sieve-manage-capability'."
(let ((capas (delq nil
(mapcar #'split-string-and-unquote
(split-string str "\n")))))
(when (string= "OK" (caar (last capas)))
(setq sieve-manage-state 'nonauth))
capas))
(defun sieve-manage-is-string ()
(cond ((looking-at "\"\\([^\"]+\\)\"")
(prog1
(match-string 1)
(goto-char (match-end 0))))
((looking-at (concat "{\\([0-9]+\\+?\\)}" sieve-manage-server-eol))
(let ((pos (match-end 0))
(len (string-to-number (match-string 1))))
(if (< (point-max) (+ pos len))
nil
(goto-char (+ pos len))
(buffer-substring pos (+ pos len)))))))
(defun sieve-manage-parse-string ()
(let (rsp)
(while (null rsp)
(accept-process-output (get-buffer-process (current-buffer)) 1)
(goto-char (point-min))
Fix (mostly multibyte) issues in sieve-manage.el (Bug#54154) The managesieve protocol (s. RFC5804) requires support for (a sightly restricted variant of) UTF-8 in script content and script names. This commit fixes/improves the handling of multibyte characters. In addition, `sieve-manage-getscript' now properly handles NO responses from the server instead of inflooping. There are also some logging improvements. * lisp/net/sieve-manage.el (sieve-manage--append-to-log): (sieve-manage--message): (sieve-manage--error): (sieve-manage-encode): (sieve-manage-decode): (sieve-manage-no-p): New functions. (sieve-manage-make-process-buffer): Switch process buffer to unibyte. (sieve-manage-open-server): Add `:coding 'raw-text-unix` to `open-network-stream' call. Use unix EOLs in order to keep matching CRLF (aka "\r\n") intact. (sieve-manage-send): Make sure that UTF-8 multibyte characters are properly encoded before sending data to the server. (sieve-manage-getscript): (sieve-manage-putscript): Use the changes above to fix down/uploading scripts containing UTF-8 multibyte characters. (sieve-manage-listscripts): (sieve-manage-havespace) (sieve-manage-getscript) (sieve-manage-putscript): (sieve-manage-deletescript): (sieve-manage-setactive): Use the changes above to fix handling of script names which contain UTF-8 multibyte characters. (sieve-manage-parse-string): (sieve-manage-getscript): Add handling of server responses with type NO. Abort `sieve-manage-getscript' and show error message in message area. (sieve-manage-erase): (sieve-manage-drop-next-answer): (sieve-manage-parse-crlf): Return erased/dropped data (instead of nil). (sieve-sasl-auth): (sieve-manage-getscript): (sieve-manage-erase): (sieve-manage-open-server): (sieve-manage-open): (sieve-manage-send): Improve logging.
2022-02-28 11:08:07 +01:00
(unless (setq rsp (sieve-manage-is-string))
(when (sieve-manage-no-p (sieve-manage-is-okno))
;; simple `error' is enough since `sieve-manage-erase'
;; already adds the server response to the log
(error (sieve-manage-erase)))))
(sieve-manage-erase (point))
rsp))
(defun sieve-manage-parse-crlf ()
(when (looking-at sieve-manage-server-eol)
(sieve-manage-erase (match-end 0))))
(defun sieve-manage-parse-listscripts ()
(let (tmp rsp data)
(while (null rsp)
(while (null (or (setq rsp (sieve-manage-is-okno))
Fix (mostly multibyte) issues in sieve-manage.el (Bug#54154) The managesieve protocol (s. RFC5804) requires support for (a sightly restricted variant of) UTF-8 in script content and script names. This commit fixes/improves the handling of multibyte characters. In addition, `sieve-manage-getscript' now properly handles NO responses from the server instead of inflooping. There are also some logging improvements. * lisp/net/sieve-manage.el (sieve-manage--append-to-log): (sieve-manage--message): (sieve-manage--error): (sieve-manage-encode): (sieve-manage-decode): (sieve-manage-no-p): New functions. (sieve-manage-make-process-buffer): Switch process buffer to unibyte. (sieve-manage-open-server): Add `:coding 'raw-text-unix` to `open-network-stream' call. Use unix EOLs in order to keep matching CRLF (aka "\r\n") intact. (sieve-manage-send): Make sure that UTF-8 multibyte characters are properly encoded before sending data to the server. (sieve-manage-getscript): (sieve-manage-putscript): Use the changes above to fix down/uploading scripts containing UTF-8 multibyte characters. (sieve-manage-listscripts): (sieve-manage-havespace) (sieve-manage-getscript) (sieve-manage-putscript): (sieve-manage-deletescript): (sieve-manage-setactive): Use the changes above to fix handling of script names which contain UTF-8 multibyte characters. (sieve-manage-parse-string): (sieve-manage-getscript): Add handling of server responses with type NO. Abort `sieve-manage-getscript' and show error message in message area. (sieve-manage-erase): (sieve-manage-drop-next-answer): (sieve-manage-parse-crlf): Return erased/dropped data (instead of nil). (sieve-sasl-auth): (sieve-manage-getscript): (sieve-manage-erase): (sieve-manage-open-server): (sieve-manage-open): (sieve-manage-send): Improve logging.
2022-02-28 11:08:07 +01:00
(setq tmp (sieve-manage-decode
(sieve-manage-is-string)))))
(accept-process-output (get-buffer-process (current-buffer)) 1)
(goto-char (point-min)))
(when tmp
(while (not (looking-at (concat "\\( ACTIVE\\)?"
sieve-manage-server-eol)))
(accept-process-output (get-buffer-process (current-buffer)) 1)
(goto-char (point-min)))
(if (match-string 1)
(push (cons 'active tmp) data)
(push tmp data))
(goto-char (match-end 0))
(setq tmp nil)))
(sieve-manage-erase)
(if (sieve-manage-ok-p rsp)
data
rsp)))
(defun sieve-manage-send (cmdstr)
Fix (mostly multibyte) issues in sieve-manage.el (Bug#54154) The managesieve protocol (s. RFC5804) requires support for (a sightly restricted variant of) UTF-8 in script content and script names. This commit fixes/improves the handling of multibyte characters. In addition, `sieve-manage-getscript' now properly handles NO responses from the server instead of inflooping. There are also some logging improvements. * lisp/net/sieve-manage.el (sieve-manage--append-to-log): (sieve-manage--message): (sieve-manage--error): (sieve-manage-encode): (sieve-manage-decode): (sieve-manage-no-p): New functions. (sieve-manage-make-process-buffer): Switch process buffer to unibyte. (sieve-manage-open-server): Add `:coding 'raw-text-unix` to `open-network-stream' call. Use unix EOLs in order to keep matching CRLF (aka "\r\n") intact. (sieve-manage-send): Make sure that UTF-8 multibyte characters are properly encoded before sending data to the server. (sieve-manage-getscript): (sieve-manage-putscript): Use the changes above to fix down/uploading scripts containing UTF-8 multibyte characters. (sieve-manage-listscripts): (sieve-manage-havespace) (sieve-manage-getscript) (sieve-manage-putscript): (sieve-manage-deletescript): (sieve-manage-setactive): Use the changes above to fix handling of script names which contain UTF-8 multibyte characters. (sieve-manage-parse-string): (sieve-manage-getscript): Add handling of server responses with type NO. Abort `sieve-manage-getscript' and show error message in message area. (sieve-manage-erase): (sieve-manage-drop-next-answer): (sieve-manage-parse-crlf): Return erased/dropped data (instead of nil). (sieve-sasl-auth): (sieve-manage-getscript): (sieve-manage-erase): (sieve-manage-open-server): (sieve-manage-open): (sieve-manage-send): Improve logging.
2022-02-28 11:08:07 +01:00
(setq cmdstr (sieve-manage-encode
(concat cmdstr sieve-manage-client-eol)))
(sieve-manage--append-to-log cmdstr)
(process-send-string sieve-manage-process cmdstr))
(provide 'sieve-manage)
;;; sieve-manage.el ends here