From 5f4926fe6ea697d012586305915298564e827985 Mon Sep 17 00:00:00 2001 From: yamaoka Date: Wed, 13 Nov 2002 12:36:35 +0000 Subject: [PATCH] Synch with the flim-1_14 branch. --- ChangeLog | 418 +++++++++++++++++++++++++++++++++++--- FLIM-API.en | 13 +- FLIM-MK | 2 +- VERSION | 51 ++++- eword-decode.el | 98 ++++----- hmac-md5.el | 6 - luna.el | 21 +- md4.el | 237 ++++++++++++++++++++++ mel-b-el.el | 5 +- mel-q.el | 5 +- mime-def.el | 69 +++---- mime-en.texi | 15 +- mime-ja.texi | 7 +- mime-parse.el | 327 +++++++++++++++++++++++------- ntlm.el | 531 +++++++++++++++++++++++++++++++++++++++++++++++++ sasl-ntlm.el | 65 ++++++ sasl-scram.el | 260 ++++++++++++++++++++++++ sasl.el | 7 +- smtp.el | 147 +++++++++++--- smtpmail.el | 8 +- std11.el | 31 ++- tests/test-rfc2231.el | 218 ++++++++++++++++++++ tests/test-sasl.el | 58 ++++++ 23 files changed, 2333 insertions(+), 266 deletions(-) create mode 100644 md4.el create mode 100644 ntlm.el create mode 100644 sasl-ntlm.el create mode 100644 sasl-scram.el create mode 100644 tests/test-rfc2231.el diff --git a/ChangeLog b/ChangeLog index d86ccf6..f052b41 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,24 +1,162 @@ -2002-07-26 Katsumi Yamaoka +2002-11-06 Yoichi NAKAYAMA + + * mime-parse.el (mime-parse-buffer): Require mmbuffer. + +2002-09-26 TSUCHIYA Masatoshi + + * luna.el (luna-define-method): Clear method cache of child + classes. + +2002-09-24 TSUCHIYA Masatoshi + + * mime-ja.texi (CVS): Escape @. + + * luna.el (luna-define-method): Fix the bug that method cache is + not cleard. + +2002-09-14 KOSEKI Yoshinori + + * mime-en.texi (CVS): Fix Typo. (@ to @@). + mime-ja.texi (CVS): Ditto. + +2002-08-26 MORIOKA Tomohiko + + * std11.el: Update Copyright header. + +2002-07-30 MORIOKA Tomohiko + + * std11.el (std11-non-atom-regexp): New constant. + (std11-analyze-atom): New implementation to avoid error in current + XEmacs UTF-2000 [may be caused by a bug about regexp]. + +2002-07-26 Katsumi Yamaoka * smtp.el (smtp-open-connection-function): Add doc. (smtp-end-of-line): Doc fix. -2002-07-24 Katsumi Yamaoka +2002-07-24 Katsumi Yamaoka * smtp.el (smtp-end-of-line): New variable. (smtp-read-response): Use it. (smtp-send-command): Use it. (smtp-send-data): Use it. -2001-07-30 AMAKAWA Shuhei +2002-01-16 Hiroya Murata + + * luna.el (luna-class-find-member): Don't search parents' + method-spaces. + +2002-02-01 Kenichi OKADA + + * eword-encode.el (mime-header-encode-method-alist): New variable. + (mime-encode-field-body): Use `mime-header-encode-method-alist'. + (mime-encode-header-in-buffer): Error if cannot encode. + +2001-11-19 Kenichi OKADA + + * smtp.el (smtp-find-server): Fix. + +2001-11-18 Kenichi OKADA + + * smtp.el (smtp-send-by-myself): Fix. + +2001-11-18 Kenichi OKADA + + * smtp.el (smtp-send-by-myself): New variable. + (smtp-use-starttls-ignore-error): New variable. + (smtp-find-mx): New function. + (smtp-dig): New function. + (smtp-find-server): New function. + (smtp-send-buffer-by-myself): New funcion. + (smtp-send-buffer): Change for `smtp-send-buffer-by-myself'. + +2001-11-03 Shuhei KOBAYASHI + + * hmac-md5.el: Removed kludge for Emacs 21 prerelease versions. + +2001-09-21 Kenichi OKADA + + * smtp.el(smtp-submit-package): Check extensions for starttls. + +2001-07-16 Katsumi Yamaoka + + * smtpmail.el (smtpmail-send-it): Work even if the first line of + the subject field has no content (synch with Emacs 20.3). + +2001-07-30 AMAKAWA Shuhei * smtp.el (smtp-submit-package): Send EHLO after starttls. +2001-06-01 Katsumi Yamaoka + + * mel-b-el.el: Require `pces' for the macro `as-binary-process' + when compiling. + + * mel-q.el: Add a comment that the feature `poem' is also required + for the macro `as-binary-process'. + +2001-05-31 Shuhei KOBAYASHI + + Merged MIME Parameter Value decoder. + + * mime-parse.el (mime-decode-parameters): Renamed from + `mime-decode-parameter-plist'. + (mime-decode-parameter-alist): Removed. + (mime-decode-alist-to-plist): Ditto. + + * FLIM-API.en (mime-entity-encoding): Abolish optional argument + `default-encoding'. + (mime-parse-Content-Tranfer-Encoding): Ditto. + 2001-05-21 SHIMADA Mitsunobu * LIMIT: CVS commit (apply unlimited patch to flim-1_14 branch) +2001-05-02 Shuhei KOBAYASHI + + * eword-decode.el (eword-decode-encoded-word): Don't use `let'. + + * mime-parse.el (mime-decode-parameter-plist): Modified + description of return value. +X (mime-parse-Content-Type): Ditto. + (mime-read-Content-Type): Ditto. +X (mime-parse-Content-Disposition): Ditto. + (mime-read-Content-Disposition): Ditto. +X (mime-parse-Content-Transfer-Encoding): Ditto. + (mime-read-Content-Transfer-Encoding): Ditto. + +2001-05-01 Shuhei KOBAYASHI + +X * mime-parse.el (mime-parse-parameters): Don't use `equal' for +X strings. +X (mime-parse-Content-Type): Ditto. + +2001-04-30 Shuhei KOBAYASHI + + * mime-parse.el (mime-decode-parameter-value): Use one temporary + buffer. + (mime-decode-parameter-plist): Changed internal data structure. + +2001-04-28 Shuhei KOBAYASHI + + * eword-decode.el (eword-encoded-word-regexp): Match for language. + (eword-decode-region): Refer the 7th parens, not 6th. + (eword-decode-encoded-word): Extract language information. + (eword-decode-encoded-text): New optional argument `language'. + + * mime-def.el (mime-charset-regexp): Updated for RFC2231. + + * mime-parse.el (mime-decode-parameter-plist): Fix regexp. + Use symbol for language information. + + * tests/test-rfc2231.el: Renamed all testcases. + +2001-04-27 Shuhei KOBAYASHI + + * mime-parse.el (mime-decode-parameter-value): Don't use + `int-char'. + 2001-04-27 Shuhei KOBAYASHI * mime.el (mime-entity-read-field): Would capitalize twice. @@ -29,16 +167,93 @@ * mmgeneric.el (mime-entity-fetch-field): Ditto. +2001-04-26 Shuhei KOBAYASHI + + * mime-parse.el (mime-decode-parameter-plist): Modified + description of return value. +X (mime-parse-Content-Type): Ditto. + (mime-read-Content-Type): Ditto. +X (mime-parse-Content-Disposition): Ditto. + (mime-read-Content-Disposition): Ditto. + (mime-read-Content-Transfer-Encoding): Ditto. + +2001-04-25 Shuhei KOBAYASHI + + * mime-parse.el (mime-lexical-analyze): Removed comments. + 2001-04-22 TAKAHASHI Kaoru * LIMIT: Version 1.14.7 (Fujiidera) released. (apply unlimited patch to FLIM Version 1.14.2) +2001-04-22 Shuhei KOBAYASHI + + * mime-parse.el (mime-decode-parameter-value): New + implementation; use temporary buffer for conversion. + (mime-decode-parameter-encode-segment): Ditto. + (mime-decode-parameter-plist): Would put empty language info. + + * test/test-rfc2231.el (test-rfc2231-10, test-rfc2231-11, + test-rfc2231-12): New testcases for language info. + +2001-04-22 Shuhei KOBAYASHI + + * mime-parse.el: Fixed comments. + + * test/test-rfc2231.el (test-rfc2231-9): New testcase. + +2001-04-22 Shuhei KOBAYASHI + + * test/test-rfc2231.el (test-rfc2231-7, test-rfc2231-8): + New testcases. + +2001-04-22 Shuhei KOBAYASHI + + * mime-def.el (mime-content-type-parameter): Expand + `mime-content-type-parameters'. + +X * mime-parse.el (mime-parse-Content-Disposition): Add +X description of return value to the docstring. +X (mime-parse-Content-Transfer-Encoding): Ditto. + + * test/test-rfc2231.el: Made independent of internal + representation of Content-Type. + +2001-04-22 Shuhei KOBAYASHI + + * FLIM-MK (check-flim): Limit filename of test files. + + * test/test-rfc2231.el: New file. + +2001-04-19 Shuhei KOBAYASHI + + * mime-parse.el (mime-decode-parameter-plist): Shortcut for + parameters without extensions. + +2001-04-19 Shuhei KOBAYASHI + + * mime-def.el (make-mime-content-type): Don't reverse parameters. + (make-mime-content-disposition): New function. + + * mime-parse.el (mime-decode-parameter-value): Removed comments. + (mime-decode-parameter-encode-segment): New function. + (mime-decode-parameter-plist): New implementation. + Switched from decode-then-concat to concat-then-decode model. +X (mime-parse-parameters): Strip quoted-pair in quoted-string. +X (mime-parse-Content-Type): Use `make-mime-content-type'. +X (mime-parse-Content-Disposition): Use +X `make-mime-content-disposition'. + 2001-04-15 Shuhei KOBAYASHI * eword-decode.el (eword-lexical-analyze-internal): Fix typo. [cf. ] +2001-04-11 Shuhei KOBAYASHI + + * mime-parse.el (mime-decode-parameter-value): Allow lowercase. + (mime-decode-parameter-plist): Ditto. + 2001-04-10 Akihiro Arisawa * std11.el (std11-lexical-analyze): Fix typo. @@ -117,6 +332,161 @@ md5-dl.el, md5.el, sha1-dl.el, sha1-el.el, sha1.el: Update Copyright header. +2001-02-28 Shuhei KOBAYASHI + + * mime-parse.el (mime-decode-parameter-plist, + mime-decode-parameter-alist, mime-decode-parameters): + Add doc string. + +2001-02-28 Shuhei KOBAYASHI + + * mime-parse.el (mime-decode-parameter-value): Decode MIME charset + in multibyte buffer. [cf. ] + (mime-decode-parameter-plist): Downcase attributes. + [cf. ] + (mime-decode-parameters): Alias for `mime-decode-parameter-plist' + instead of `mime-decode-parameter-alist'. + Add autoload cookie. + (mime-parse-parameters-from-list): Make obsolete. + (mime-parse-parameters): Return results as a plist. +X (mime-parse-Content-Type, mime-read-Content-Type): Moved type check + to the caller side. +X (mime-parse-Content-Disposition, mime-read-Content-Disposition): + Ditto. +X (mime-parse-Content-Transfer-Encoding, + mime-read-Content-Transfer-Encoding): Ditto. + +2001-02-27 Shuhei KOBAYASHI + + MIME Parameter Value decoder support. + + * mime-def.el (std11-quoted-pair-regexp, std11-non-qtext-char-list, + std11-qtext-regexp, std11-quoted-string-regexp): Removed. + (mime-media-type/subtype-regexp): Ditto. + (mime-attribute-char-regexp, mime-language-regexp, + mime-encoding-regexp): New constants. + + * mime-parse.el (mime-lexical-analyze): New function. + (mime/content-parameter-value-regexp, mime::parameter-regexp): + Removed. +X (mime-parse-parameter): Ditto. + (mime-decode-parameter-value, mime-decode-parameter-plist, + mime-parse-alist-to-plist, mime-decode-parameter-alist): + New functions. + (mime-parse-parameters-from-list): New alias for + `mime-decode-parameter-plist'. + (mime-decode-parameters): New alias for + `mime-decode-parameter-alist'. + (mime-parse-parameters): New function. + (mime-disposition-type-regexp): Removed. +X (mime-parse-Content-Type, mime-parse-Content-Disposition, +X mime-parse-Content-Transfer-Encoding): New implementation. + (mime-read-Content-Type, mime-read-Content-Disposition, + mime-read-Content-Transfer-Encoding): Ditto. + +2001-02-26 Shuhei KOBAYASHI + + * hmac-md5.el, hmac-sha1.el: Modify comments. + +2001-02-25 Shuhei KOBAYASHI + + * hex-util.el, hmac-def.el, hmac-md5.el, hmac-sha1.el, + md5-dl.el, md5.el, sha1-dl.el, sha1-el.el, sha1.el: + Update Copyright header. + +2001-02-20 Kenichi OKADA + + * tests/test-sasl.el(test-sasl-ntlm-imap): Fix + `sasl-read-passphrase' + +2001-02-20 Kenichi OKADA + + * tests/test-sasl.el(test-sasl-ntlm-imap): Change name. + Delete wrong lines. + +2001-02-20 Taro Kawagishi + + * tests/test-sasl.el(test-sasl-digest-ntlm-imap): New test. + +2001-02-17 Kenichi OKADA + + * sasl-ntlm.el(sasl-ntlm-response): self-Hash. + +2001-02-17 Kenichi OKADA + + * ntlm.el(smb-passwd-hash): Fix `upcase' for XEmacs. + +2001-02-17 Kenichi OKADA + + * ntlm.el(TopLevel): Require `poem' + (ntlm-build-auth-request): Omit `request-bufIndex' + (ntlm-build-auth-response): Omit `response', `ident' and `msgType' + Use `string-as-unibyte' of `poem'. + +2001-02-17 Kenichi OKADA + + * sasl-scram.el(sasl-scram-md5-parse-server-msg-1): Error + if server's response cannot be parsed. + +2001-02-17 Kenichi OKADA + + * sasl-scram.el(sasl-scram-md5-server-salt): New function. + (sasl-scram-md5-response-2): Use `sasl-scram-md5-server-salt' + +2001-02-17 Kenichi OKADA + + * sasl-scram.el(sasl-scram-md5-make-unique-nonce): Rewrite. + +2001-02-17 Kenichi OKADA + + * sasl-scram.el: Add comment. + (sasl-scram-md5-steps): New variable. + (sasl-scram-md5-make-client-msg-1): Add optional nonce. + (sasl-scram-md5-make-client-msg-2): New function. + (sasl-scram-md5-make-server-msg-2): Rewrite. + (sasl-scram-md5-response-1): New function. + (sasl-scram-md5-response-2): New function. + (sasl-scram-md5-authenticate-server): New function. + * test/test-sasl.el(test-sasl-scram-md5-imap): New function. + +2001-02-16 Kenichi OKADA + + * sasl-scram.el: rename from scram-md5.el + (TopLevel): Provide `sasl-scram'. + Fix prefix. + Fix comments. + require `sasl'. + (sasl-scram-make-unique-nonce): use `sasl-unique-id'. + (sasl-scram-md5-unique-id-function): New variable. + * sasl.el(sasl-mechanisms): Add SCRAM-MD5. + (sasl-mechanism-alist): Ditto. + +2001-02-16 Kenichi OKADA + + * md4.el(md4-pack-int16): Taken form ntlm.el + (md4-pack-int32): Ditto. + (md4-unpack-int16): Ditto. + (md4-unpack-int32): Ditto. + * ntlm.el (pack-int16): Delete. + (pack-int32): Delete. + (unpack-int16): Delete. + (unpack-int32): Delete. + +2001-02-16 Kenichi OKADA + + * sasl.el(sasl-mechanisms): Add NTLM. + (sasl-mechanism-alist): Add NTLM. + +2001-02-16 Kenichi OKADA + + * test/test-sasl.el: New file. + +2001-02-16 Taro Kawagishi + + * md4.el: New file. + * ntlm.el: New file. + * sasl-ntlm.el: New file. + 2000-12-27 MORIOKA Tomohiko * mime-conf.el (mime-mailcap-file): Turn to non user option. @@ -171,7 +541,7 @@ * qmtp.el (qmtp-open-connection-function): Revert initial value to `open-network-stream'. (qmtp-send-buffer): Use `binary-funcall'. - + 2000-12-23 OKAZAKI Tetsurou * FLIM-ELS (flim-modules): Delete `mmdbuffer'. @@ -415,7 +785,7 @@ * mmbuffer.el (mime-write-entity-body): Use `binary-write-region' instead of `write-region-as-binary'. (mime-write-entity): Don't use `write-region-as-raw-text-CRLF'. - + * mime-def.el: Don't require `poem'. (binary-insert-file-contents): New function. (binary-write-region): New function. @@ -558,9 +928,9 @@ 2000-12-04 Daiki Ueno - * smtpmail.el (smtpmail-send-it): Use `smtp-send-buffer' instead of - `smtp-via-smtp'. - (smtpmail-send-queued-mail): Ditto. + * smtpmail.el (smtpmail-send-it): Use `smtp-send-buffer' instead of + `smtp-via-smtp'. + (smtpmail-send-queued-mail): Ditto. 2000-11-24 MORIOKA Tomohiko @@ -874,8 +1244,8 @@ 2000-05-25 Tanaka Akira - * mime-en.sgml, mime-ja.sgml: Update for CVS via SSH. - + * mime-en.sgml, mime-ja.sgml: Update for CVS via SSH. + 2000-05-09 Katsumi Yamaoka * smtp.el (smtp-deduce-address-list): Set `case-fold-search' to `t' @@ -1636,7 +2006,7 @@ 1999-03-01 MORIOKA Tomohiko * mel.el (mime-decode-string): Return STRING if return value of - `(mel-find-function 'mime-decode-string encoding)' is nil. + `(mel-find-function 'mime-decode-string encoding)' is nil. 1999-02-10 MORIOKA Tomohiko @@ -2957,12 +3327,12 @@ 1998-08-28 MORIOKA Tomohiko * eword-encode.el (eword-encode-field): Use `capitalize' instead - of `downcase' for `field-name'. + of `downcase' for `field-name'. * eword-encode.el (eword-encode-structured-field-body): New - function. + function. (eword-encode-field): Use `eword-encode-structured-field-body' for - "MIME-Version" and "User-Agent" field. + "MIME-Version" and "User-Agent" field. 1998-08-26 Shuhei KOBAYASHI @@ -2972,15 +3342,15 @@ * eword-encode.el (eword-encode-address-list): New function. (eword-encode-field): Use `eword-encode-address-list' instead of - `tm-eword::encode-address-list'; abolish - `tm-eword::encode-address-list'. + `tm-eword::encode-address-list'; abolish + `tm-eword::encode-address-list'. * eword-encode.el (eword-encode-field): Use `eword-encode-string' - instead of `tm-eword::encode-string'; abolish - `tm-eword::encode-string'. + instead of `tm-eword::encode-string'; abolish + `tm-eword::encode-string'. * eword-encode.el: Rename `tm-eword::make-rword' -> - `make-ew-rword'; rename `tm-eword::rword-' -> `ew-rword-'. + `make-ew-rword'; rename `tm-eword::rword-' -> `ew-rword-'. 1998-08-26 Shuhei KOBAYASHI @@ -3658,7 +4028,7 @@ * FLIM: Version 1.2.0 (J-Dþjò)-A was released. * README.en (What's FLIM): Delete description about - std11-parse.el; add description about mailcap.el. + std11-parse.el; add description about mailcap.el. 1998-05-06 MORIOKA Tomohiko @@ -3745,7 +4115,7 @@ * FLIM: Version 1.0.1 (Ky-Dòto)-A was released. * mime-def.el (mime-spadework-module-version-string): New - constant. + constant. * eword-encode.el: Abolish constant 'eword-encode-version. @@ -3782,6 +4152,6 @@ * Makefile: New file. * mime-def.el, std11-parse.el, std11.el, eword-decode.el, - eword-encode.el: Copied from MEL, SEMI (mime-def.el - eword-decode.el eword-encode.el) and APEL (std11-parse.el - std11.el). + eword-encode.el: Copied from MEL, SEMI (mime-def.el + eword-decode.el eword-encode.el) and APEL (std11-parse.el + std11.el). diff --git a/FLIM-API.en b/FLIM-API.en index 539a559..533ce5d 100644 --- a/FLIM-API.en +++ b/FLIM-API.en @@ -200,12 +200,11 @@ ULEVEL specifies implementation level: (Usage: SEMI 1.14 MIME-View) -[Function] mime-entity-encoding (entity &optional default-encoding) +[Function] mime-entity-encoding (entity) Return content-transfer-encoding of ENTITY. - If the ENTITY does not have Content-Transfer-Encoding field, this - function returns DEFAULT-ENCODING. If it is nil, "7bit" is used as - default value. + If the ENTITY does not have valid Content-Transfer-Encoding field, + return nil. [Suggest] (Usage: SEMI 1.14 MIME-View) @@ -905,16 +904,16 @@ and return parsed it. [Function] mime-parse-Content-Transfer-Encoding (string) Parse STRING as field-body of Content-Transfer-Encoding field. + If STRING is not a valid Content-Transfer-Encoding field, + return nil. [Suggest] -[Function] mime-read-Content-Transfer-Encoding (&optional default-encoding) +[Function] mime-read-Content-Transfer-Encoding () Read field-body of Content-Transfer-Encoding field from current-buffer, and return it. - If is is not found, return DEFAULT-ENCODING. - [Suggest] diff --git a/FLIM-MK b/FLIM-MK index 701ff61..68c42d4 100644 --- a/FLIM-MK +++ b/FLIM-MK @@ -40,7 +40,7 @@ LISPDIR=%s\n" PREFIX LISPDIR)))) (defun check-flim () (config-flim) (require 'lunit) - (let ((files (directory-files "tests" t)) + (let ((files (directory-files "tests" t "^test-.*\\.el$")) (suite (lunit-make-test-suite))) (while files (if (file-regular-p (car files)) diff --git a/VERSION b/VERSION index 76efd59..f5d570f 100644 --- a/VERSION +++ b/VERSION @@ -48,11 +48,18 @@ 1.13.0 Iwami $(B@P8+(B 1.13.1 Tawaramoto $(BED86K\(B ; <=> $(B6aE4(B $(B@>ED86K\(B 1.13.2 Kasanui $(B3^K%(B ------- Ninokuchi $(B?7%N8}(B ------- Yagi $(BH,LZ(B ; = $(B6aE4(B $(BBg:e@~(B ------- Yagi-Nishiguchi $(BH,LZ@>8}(B ------- Unebigory-Dòmae-A $(B@&K58fNMA0(B ------- Kashiharajingu-mae $(B3`86?@5\A0(B ; = $(B6aE4(B $(BFnBg:e@~!"5HLn@~(B +1.14.0 Ninokuchi $(B?7%N8}(B +1.14.1 Yagi $(BH,LZ(B ; = $(B6aE4(B $(BBg:e@~(B +1.14.2 Yagi-Nishiguchi $(BH,LZ@>8}(B +1.14.3 Unebigory-Dòmae-A $(B@&K58fNMA0(B +1.14.4 Kashiharajing-Dþ-mae-A $(B3`86?@5\A0(B ; = $(B6aE4(B $(BFnBg:e@~!"5HLn@~(B + + +;;------------------------------------------------------------------------- +;; Keihan Electric Railway $(B5~:eEE5$E4F;(B http://www.keihan.co.jp/ +;; $(B3{El@~(B +;;------------------------------------------------------------------------- +1.14.5 Demachiyanagi $(B=PD.Lx(B ; <=> $(B1CEE(B [Chao Version names] @@ -117,10 +124,34 @@ ;;------------------------------------------------------------------------- ;; Hokuriku Railway $(BKLN&E4F;(B ;; Nomi Line $(BG=H~@~(B $(B!J5l(B $(BG=H~EE5$E4F;!K(B -;;------------------------------------------------------------------------- -1.13.4 Shin-Terai $(B?7;{0f(B ; <=> $(BKLN&K\@~(B $(B;{0f(B -1.13.5 Kaga-Fukuoka $(B2C2lJ!2,(B -1.13.6 Nakanosh-Dò-A $(BCf%N>1(B +;; +;; "$BN/CS(B" $B$*$h$S(B "$B;{0f@>8}(B" $B0J9_$O(B OHNO Toshihiko $B$5$^$4Ds6!$N!"(B +;; JTB $B@PLnE/JT!XA49qGQ@~;dE4$NDdl0lMw!Y$r85$K$7$F$$$^$9!#(B +;;------------------------------------------------------------------------- +1.13.4 Shin-Terai $B?7;{0f(B ; <=> $BKLN&K\@~(B $B;{0f(B +------ Tameike $BN/CS(B +1.13.5 Kaga-Fukuoka $B2C2lJ!2,(B +1.13.6 Nakanosh-Dò-A $BCf%N>1(B ; $B$N$A$KCf$N>1$K2~>N(B +1.14.0 Gokend-Dò-A $B8^4VF2(B +1.14.3 Terai-Nishikuchi $B;{0f@>8}(B +1.14.4 Jid-Dò-Asha-Renraku $B<+F0e3+H/(B +------ Tatsunokuchi $BC$8}(B ; $B$N$A$KC$8}29@t$K2~>N(B +------ Raimaru $BMh4](B +------ Higama $B2P3x(B +------ Iwauchi $B4dFb(B ; $B$N$A$K2C2l4dFb$K2~>N(B +------ Mitsukuchi $B;08}(B ; $B$N$A$K;0%D8}$K2~>N(B +------ Miyatake $B5\C](B +------ Todashino $BEtBf:{(B +------ Iwamoto $B4dK\(B ; $B$N$A$K?7DaMh$K2~>N(B +------ Tengu-yama $BE76i;3(B +------ Hon-Tsurugi $BK\DaMh(B +------ Tsurugi $BDaMh(B [LIMIT Version names] @@ -141,7 +172,7 @@ 1.14.4 Kawachi-Matsubara $(B2OFb>>86(B 1.14.5 Eganosh-Dò-A $(B7C2f%NAq(B 1.14.6 Takawashi $(B9bOI(B ------- Fuj-Dïdera-A $(BF#0f;{(B +1.14.7 Fuj-Dïdera-A $(BF#0f;{(B ------ Hajinosato $(BEZ;U$NN$(B ------ D-Dòmyòji-A $(BF;L@;{(B ------ Furuichi $(B8E;T(B ; = $(B6aE4(B $(BD9Ln@~(B diff --git a/eword-decode.el b/eword-decode.el index cc58861..fa3081e 100644 --- a/eword-decode.el +++ b/eword-decode.el @@ -55,13 +55,19 @@ (eval-when-compile (concat (regexp-quote "=?") "\\(" - mime-charset-regexp + mime-charset-regexp ; 1 "\\)" + "\\(" + (regexp-quote "*") + mime-language-regexp ; 2 + "\\)?" (regexp-quote "?") - "\\([BbQq]\\)" + "\\(" + mime-encoding-regexp ; 3 + "\\)" (regexp-quote "?") "\\(" - eword-encoded-text-regexp + eword-encoded-text-regexp ; 4 "\\)" (regexp-quote "?=")))) ) @@ -231,7 +237,7 @@ such as a version of Net$cape)." "\\(\n?[ \t]\\)+" "\\(" eword-encoded-word-regexp "\\)") nil t) - (replace-match "\\1\\6") + (replace-match "\\1\\7") (goto-char (point-min)) ) (while (re-search-forward eword-encoded-word-regexp nil t) @@ -529,64 +535,66 @@ If SEPARATOR is not nil, it is used as header separator." word)) (defun eword-decode-encoded-word (word &optional must-unfold) - "Decode WORD if it is an encoded-word. - -If your emacs implementation can not decode the charset of WORD, it -returns WORD. Similarly the encoded-word is broken, it returns WORD. - -If MUST-UNFOLD is non-nil, it unfolds and eliminates line-breaks even -if there are in decoded encoded-word (generated by bad manner MUA such -as a version of Net$cape)." - (or (if (string-match eword-encoded-word-regexp word) - (let ((charset - (substring word (match-beginning 1) (match-end 1)) - ) - (encoding - (upcase - (substring word (match-beginning 2) (match-end 2)) - )) - (text - (substring word (match-beginning 3) (match-end 3)) - )) - (condition-case err - (eword-decode-encoded-text charset encoding text must-unfold) - (error - (funcall eword-decode-encoded-word-error-handler word err) - )) - )) + "Decode WORD as an encoded-word. + +If charset is unknown or unsupported, return WORD. +If encoding is unknown, or some error occurs while decoding, +`eword-decode-encoded-word-error-handler' is called with WORD and an +error condition. + +If MUST-UNFOLD is non-nil, unfold decoded WORD." + (or (and (string-match eword-encoded-word-regexp word) + (condition-case err + (eword-decode-encoded-text + ;; charset + (substring word (match-beginning 1)(match-end 1)) + ;; language + (when (match-beginning 2) + (intern + (downcase + (substring word (1+ (match-beginning 2))(match-end 2))))) + ;; encoding + (upcase + (substring word (match-beginning 3)(match-end 3))) + ;; encoded-text + (substring word (match-beginning 4)(match-end 4)) + must-unfold) + (error + (funcall eword-decode-encoded-word-error-handler word err)))) word)) ;;; @ encoded-text decoder ;;; -(defun eword-decode-encoded-text (charset encoding string +(defun eword-decode-encoded-text (charset language encoding string &optional must-unfold) "Decode STRING as an encoded-text. If your emacs implementation can not decode CHARSET, it returns nil. +If LANGUAGE is non-nil, it is put to `mime-language' text-property. If ENCODING is not \"B\" or \"Q\", it occurs error. So you should write error-handling code if you don't want break by errors. If MUST-UNFOLD is non-nil, it unfolds and eliminates line-breaks even if there are in decoded encoded-text (generated by bad manner MUA such as a version of Net$cape)." - (let ((cs (mime-charset-to-coding-system charset))) - (if cs - (let ((dest (encoded-text-decode-string string encoding))) - (when dest - (setq dest (decode-mime-charset-string dest charset)) - (if must-unfold - (mapconcat (function - (lambda (chr) - (cond ((eq chr ?\n) "") - ((eq chr ?\t) " ") - (t (char-to-string chr))) - )) - (std11-unfold-string dest) - "") - dest)))))) + (when (mime-charset-to-coding-system charset) + (let ((dest (encoded-text-decode-string string encoding))) + (when dest + (setq dest (decode-mime-charset-string dest charset)) + (when must-unfold + (mapconcat + (function + (lambda (chr) + (cond ((eq chr ?\n) "") + ((eq chr ?\t) " ") + (t (char-to-string chr))))) + (std11-unfold-string dest) "")) + (when language + (put-text-property 0 (length dest) 'mime-language language dest)) + dest)))) ;;; @ lexical analyze diff --git a/hmac-md5.el b/hmac-md5.el index d003b50..097a959 100644 --- a/hmac-md5.el +++ b/hmac-md5.el @@ -65,12 +65,6 @@ (eval-when-compile (require 'hmac-def)) (require 'hex-util) ; (decode-hex-string STRING) -;; Kludge for Emacs pretest 21.0.90 - 21.0.100 !!! -;; they have `md5' as a built-in function but do not provide 'md5. -(eval-and-compile - (if (and (fboundp 'md5) - (subrp (symbol-function 'md5))) - (provide 'md5))) (require 'md5) ; expects (md5 STRING) ;; To share *.elc files between Emacs w/ and w/o DL patch, diff --git a/luna.el b/luna.el index b307ad9..f33b83f 100644 --- a/luna.el +++ b/luna.el @@ -1,6 +1,6 @@ ;;; luna.el --- tiny OOP system kernel -;; Copyright (C) 1999,2000 Free Software Foundation, Inc. +;; Copyright (C) 1999,2000,2002 Free Software Foundation, Inc. ;; Author: MORIOKA Tomohiko ;; Keywords: OOP @@ -97,15 +97,7 @@ The optional 2nd arg SLOTS is a list of slots CLASS will have." (defun luna-class-find-member (class member-name) (or (stringp member-name) (setq member-name (symbol-name member-name))) - (or (intern-soft member-name (luna-class-obarray class)) - (let ((parents (luna-class-parents class)) - ret) - (while (and parents - (null - (setq ret (luna-class-find-member - (luna-find-class (pop parents)) - member-name))))) - ret))) + (intern-soft member-name (luna-class-obarray class))) ;; Return a member (slot or method) of CLASS that has name @@ -172,8 +164,13 @@ The optional 5th BODY is the body of the method." (sym (luna-class-find-or-make-member (luna-find-class ',class) ',name)) (cache (get ',name 'luna-method-cache))) - (if cache - (unintern ',class cache)) + (and cache + (fboundp sym) + (mapatoms + (lambda (s) + (if (memq (symbol-function sym) (symbol-value s)) + (unintern s cache))) + cache)) (fset sym func) (put sym 'luna-method-qualifier ,method-qualifier)))) diff --git a/md4.el b/md4.el new file mode 100644 index 0000000..42cc7ab --- /dev/null +++ b/md4.el @@ -0,0 +1,237 @@ +;;; md4.el --- MD4 Message Digest Algorithm. + +;; Copyright (C) 2001 Taro Kawagishi +;; Author: Taro Kawagishi +;; Keywords: MD4 +;; Version: 1.00 +;; Created: February 2001 + +;; This file is part of FLIM (Faithful Library about Internet Message). + +;; This program 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 2, or (at your option) +;; any later version. +;; +;; This program 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 this program; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, +;; Boston, MA 02111-1307, USA. + +;;; Code: + +;;; +;;; MD4 hash calculation + +(defun print-int32 (int32) + "print 32 bits integer in 4 bytes string as little endian" + (let ((h (car int32)) (l (cdr int32))) + (list (logand l 255) (lsh l -8) (logand h 255) (lsh h -8)))) + +(defun print-string-hexa (str) + "print a string in hexadecimal" + (let (out) + (mapcar (function (lambda (x) (concat out (format "%x" x)))) str))) + +(defvar md4-buffer (make-vector 4 '(0 . 0)) + "work buffer of four 32-bit integers") + +(defun md4 (in n) + "Returns the MD4 hash string of 16 bytes long for a string IN of N +bytes long. N is required to handle strings containing character 0." + (let (m + (b (cons 0 (* n 8))) + (i 0) + (buf (make-string 128 0)) c4) + ;; initial values + (aset md4-buffer 0 '(26437 . 8961)) ;0x67452301 + (aset md4-buffer 1 '(61389 . 43913)) ;0xefcdab89 + (aset md4-buffer 2 '(39098 . 56574)) ;0x98badcfe + (aset md4-buffer 3 '(4146 . 21622)) ;0x10325476 + + ;; process the string in 64 bits chunks + (while (> n 64) + (setq m (md4-copy64 (substring in 0 64))) + (md4-64 m) + (setq in (substring in 64)) + (setq n (- n 64))) + + ;; process the rest of the string (length is now n <= 64) + (setq i 0) + (while (< i n) + (aset buf i (aref in i)) + (setq i (1+ i))) + (aset buf n 128) ;0x80 + (if (<= n 55) + (progn + (setq c4 (md4-pack-int32 b)) + (aset buf 56 (aref c4 0)) + (aset buf 57 (aref c4 1)) + (aset buf 58 (aref c4 2)) + (aset buf 59 (aref c4 3)) + (setq m (md4-copy64 buf)) + (md4-64 m)) + ;; else + (setq c4 (md4-pack-int32 b)) + (aset buf 120 (aref c4 0)) + (aset buf 121 (aref c4 1)) + (aset buf 122 (aref c4 2)) + (aset buf 123 (aref c4 3)) + (setq m (md4-copy64 buf)) + (md4-64 m) + (setq m (md4-copy64 (substring buf 64))) + (md4-64 m))) + + (concat (md4-pack-int32 (aref md4-buffer 0)) + (md4-pack-int32 (aref md4-buffer 1)) + (md4-pack-int32 (aref md4-buffer 2)) + (md4-pack-int32 (aref md4-buffer 3)))) + +(defsubst md4-F (x y z) (logior (logand x y) (logand (lognot x) z))) +(defsubst md4-G (x y z) (logior (logand x y) (logand x z) (logand y z))) +(defsubst md4-H (x y z) (logxor x y z)) + +(defmacro md4-make-step (name func) + (` + (defun (, name) (a b c d xk s ac) + (let* + ((h1 (+ (car a) ((, func) (car b) (car c) (car d)) (car xk) (car ac))) + (l1 (+ (cdr a) ((, func) (cdr b) (cdr c) (cdr d)) (cdr xk) (cdr ac))) + (h2 (logand 65535 (+ h1 (lsh l1 -16)))) + (l2 (logand 65535 l1)) + ;; cyclic shift of 32 bits integer + (h3 (logand 65535 (if (> s 15) + (+ (lsh h2 (- s 32)) (lsh l2 (- s 16))) + (+ (lsh h2 s) (lsh l2 (- s 16)))))) + (l3 (logand 65535 (if (> s 15) + (+ (lsh l2 (- s 32)) (lsh h2 (- s 16))) + (+ (lsh l2 s) (lsh h2 (- s 16))))))) + (cons h3 l3))))) + +(md4-make-step md4-round1 md4-F) +(md4-make-step md4-round2 md4-G) +(md4-make-step md4-round3 md4-H) + +(defsubst md4-add (x y) + "Return 32-bit sum of 32-bit integers X and Y." + (let ((h (+ (car x) (car y))) + (l (+ (cdr x) (cdr y)))) + (cons (logand 65535 (+ h (lsh l -16))) (logand 65535 l)))) + +(defsubst md4-and (x y) + (cons (logand (car x) (car y)) (logand (cdr x) (cdr y)))) + +(defun md4-64 (m) + "Calculate md4 of 64 bytes chunk M which is represented as 16 pairs of +32 bits integers. The resulting md4 value is placed in md4-buffer." + (let ((a (aref md4-buffer 0)) + (b (aref md4-buffer 1)) + (c (aref md4-buffer 2)) + (d (aref md4-buffer 3))) + (setq a (md4-round1 a b c d (aref m 0) 3 '(0 . 0)) + d (md4-round1 d a b c (aref m 1) 7 '(0 . 0)) + c (md4-round1 c d a b (aref m 2) 11 '(0 . 0)) + b (md4-round1 b c d a (aref m 3) 19 '(0 . 0)) + a (md4-round1 a b c d (aref m 4) 3 '(0 . 0)) + d (md4-round1 d a b c (aref m 5) 7 '(0 . 0)) + c (md4-round1 c d a b (aref m 6) 11 '(0 . 0)) + b (md4-round1 b c d a (aref m 7) 19 '(0 . 0)) + a (md4-round1 a b c d (aref m 8) 3 '(0 . 0)) + d (md4-round1 d a b c (aref m 9) 7 '(0 . 0)) + c (md4-round1 c d a b (aref m 10) 11 '(0 . 0)) + b (md4-round1 b c d a (aref m 11) 19 '(0 . 0)) + a (md4-round1 a b c d (aref m 12) 3 '(0 . 0)) + d (md4-round1 d a b c (aref m 13) 7 '(0 . 0)) + c (md4-round1 c d a b (aref m 14) 11 '(0 . 0)) + b (md4-round1 b c d a (aref m 15) 19 '(0 . 0)) + + a (md4-round2 a b c d (aref m 0) 3 '(23170 . 31129)) ;0x5A827999 + d (md4-round2 d a b c (aref m 4) 5 '(23170 . 31129)) + c (md4-round2 c d a b (aref m 8) 9 '(23170 . 31129)) + b (md4-round2 b c d a (aref m 12) 13 '(23170 . 31129)) + a (md4-round2 a b c d (aref m 1) 3 '(23170 . 31129)) + d (md4-round2 d a b c (aref m 5) 5 '(23170 . 31129)) + c (md4-round2 c d a b (aref m 9) 9 '(23170 . 31129)) + b (md4-round2 b c d a (aref m 13) 13 '(23170 . 31129)) + a (md4-round2 a b c d (aref m 2) 3 '(23170 . 31129)) + d (md4-round2 d a b c (aref m 6) 5 '(23170 . 31129)) + c (md4-round2 c d a b (aref m 10) 9 '(23170 . 31129)) + b (md4-round2 b c d a (aref m 14) 13 '(23170 . 31129)) + a (md4-round2 a b c d (aref m 3) 3 '(23170 . 31129)) + d (md4-round2 d a b c (aref m 7) 5 '(23170 . 31129)) + c (md4-round2 c d a b (aref m 11) 9 '(23170 . 31129)) + b (md4-round2 b c d a (aref m 15) 13 '(23170 . 31129)) + + a (md4-round3 a b c d (aref m 0) 3 '(28377 . 60321)) ;0x6ED9EBA1 + d (md4-round3 d a b c (aref m 8) 9 '(28377 . 60321)) + c (md4-round3 c d a b (aref m 4) 11 '(28377 . 60321)) + b (md4-round3 b c d a (aref m 12) 15 '(28377 . 60321)) + a (md4-round3 a b c d (aref m 2) 3 '(28377 . 60321)) + d (md4-round3 d a b c (aref m 10) 9 '(28377 . 60321)) + c (md4-round3 c d a b (aref m 6) 11 '(28377 . 60321)) + b (md4-round3 b c d a (aref m 14) 15 '(28377 . 60321)) + a (md4-round3 a b c d (aref m 1) 3 '(28377 . 60321)) + d (md4-round3 d a b c (aref m 9) 9 '(28377 . 60321)) + c (md4-round3 c d a b (aref m 5) 11 '(28377 . 60321)) + b (md4-round3 b c d a (aref m 13) 15 '(28377 . 60321)) + a (md4-round3 a b c d (aref m 3) 3 '(28377 . 60321)) + d (md4-round3 d a b c (aref m 11) 9 '(28377 . 60321)) + c (md4-round3 c d a b (aref m 7) 11 '(28377 . 60321)) + b (md4-round3 b c d a (aref m 15) 15 '(28377 . 60321))) + + (aset md4-buffer 0 (md4-add a (aref md4-buffer 0))) + (aset md4-buffer 1 (md4-add b (aref md4-buffer 1))) + (aset md4-buffer 2 (md4-add c (aref md4-buffer 2))) + (aset md4-buffer 3 (md4-add d (aref md4-buffer 3))) + )) + +(defun md4-copy64 (seq) + "Unpack a 64 bytes string into 16 pairs of 32 bits integers." + (let ((int32s (make-vector 16 0)) (i 0) j) + (while (< i 16) + (setq j (* i 4)) + (aset int32s i (cons (+ (aref seq (+ j 2)) (lsh (aref seq (+ j 3)) 8)) + (+ (aref seq j) (lsh (aref seq (1+ j)) 8)))) + (setq i (1+ i))) + int32s)) + +;;; +;;; sub functions + +(defun md4-pack-int16 (int16) + "Pack 16 bits integer in 2 bytes string as little endian." + (let ((str (make-string 2 0))) + (aset str 0 (logand int16 255)) + (aset str 1 (lsh int16 -8)) + str)) + +(defun md4-pack-int32 (int32) + "Pack 32 bits integer in a 4 bytes string as little endian. A 32 bits +integer is represented as a pair of two 16 bits integers (cons high low)." + (let ((str (make-string 4 0)) + (h (car int32)) (l (cdr int32))) + (aset str 0 (logand l 255)) + (aset str 1 (lsh l -8)) + (aset str 2 (logand h 255)) + (aset str 3 (lsh h -8)) + str)) + +(defun md4-unpack-int16 (str) + (if (eq 2 (length str)) + (+ (lsh (aref str 1) 8) (aref str 0)) + (error "%s is not 2 bytes long" str))) + +(defun md4-unpack-int32 (str) + (if (eq 4 (length str)) + (cons (+ (lsh (aref str 3) 8) (aref str 2)) + (+ (lsh (aref str 1) 8) (aref str 0))) + (error "%s is not 4 bytes long" str))) + +(provide 'md4) + +;;; md4.el ends here diff --git a/mel-b-el.el b/mel-b-el.el index 2937238..f8a13ef 100644 --- a/mel-b-el.el +++ b/mel-b-el.el @@ -1,6 +1,6 @@ ;;; mel-b-el.el --- Base64 encoder/decoder. -;; Copyright (C) 1992,1995,1996,1997,1998,1999 Free Software Foundation, Inc. +;; Copyright (C) 1992,95,96,97,98,99,2001 Free Software Foundation, Inc. ;; Author: ENAMI Tsugutomo ;; MORIOKA Tomohiko @@ -27,6 +27,9 @@ ;;; Code: (require 'mime-def) +(eval-when-compile + ;; XXX: the macro `as-binary-process' should be provided when compiling. + (require 'pces)) ;;; @ variables diff --git a/mel-q.el b/mel-q.el index a5830d2..4a59b02 100644 --- a/mel-q.el +++ b/mel-q.el @@ -1,6 +1,6 @@ ;;; mel-q.el --- Quoted-Printable encoder/decoder. -;; Copyright (C) 1995,1996,1997,1998,1999 Free Software Foundation, Inc. +;; Copyright (C) 1995,96,97,98,99,2000,2001 Free Software Foundation, Inc. ;; Author: MORIOKA Tomohiko ;; Created: 1995/6/25 @@ -29,8 +29,11 @@ (require 'path-util) (eval-when-compile ;; XXX: should provide char-list instead of string-to-char-list. + ;; XXx: and also the macro `as-binary-process' should be provided + ;; XXx: by the module "pces" which will be loaded by way of "poem". (require 'poem)) + ;;; @ Quoted-Printable encoder ;;; diff --git a/mime-def.el b/mime-def.el index deeb740..7197b34 100644 --- a/mime-def.el +++ b/mime-def.el @@ -1,8 +1,9 @@ ;;; mime-def.el --- definition module about MIME -*- coding: ctext; -*- -;; Copyright (C) 1995,96,97,98,99,2000 Free Software Foundation, Inc. +;; Copyright (C) 1995,96,97,98,99,2000,2001,2002 Free Software Foundation, Inc. ;; Author: MORIOKA Tomohiko +;; Shuhei KOBAYASHI ;; Keywords: definition, MIME, multimedia, mail, news ;; This file is part of FLIM (Faithful Library about Internet Message). @@ -28,10 +29,7 @@ (require 'mcharset) (require 'alist) -(eval-when-compile - (require 'cl) ; list* - (require 'luna) ; luna-arglist-to-arguments - ) +(eval-when-compile (require 'luna)) ; luna-arglist-to-arguments (eval-and-compile (defconst mime-library-product ["LIMIT" (1 14 7) "Fujiidera"] @@ -129,36 +127,28 @@ If method is nil, this field will not be encoded." (defalias 'char-int 'identity)) -;;; @ about STD 11 +;;; @ MIME constants ;;; -(eval-and-compile - (defconst std11-quoted-pair-regexp "\\\\.") - (defconst std11-non-qtext-char-list '(?\" ?\\ ?\r ?\n)) - (defconst std11-qtext-regexp - (eval-when-compile - (concat "[^" std11-non-qtext-char-list "]")))) -(defconst std11-quoted-string-regexp - (eval-when-compile - (concat "\"" - (regexp-* - (regexp-or std11-qtext-regexp std11-quoted-pair-regexp)) - "\""))) - +(defconst mime-tspecial-char-list + '(?\] ?\[ ?\( ?\) ?< ?> ?@ ?, ?\; ?: ?\\ ?\" ?/ ?? ?=)) +(defconst mime-token-regexp + (concat "[^" mime-tspecial-char-list "\000-\040]+")) +(defconst mime-attribute-char-regexp + (concat "[^" mime-tspecial-char-list "\000-\040" + "*'%" ; introduced in RFC 2231. + "]")) -;;; @ about MIME -;;; +(defconst mime-charset-regexp + (concat "[^" mime-tspecial-char-list "\000-\040" + "*'%" ; should not include "%"? + "]+")) -(eval-and-compile - (defconst mime-tspecial-char-list - '(?\] ?\[ ?\( ?\) ?< ?> ?@ ?, ?\; ?: ?\\ ?\" ?/ ?? ?=))) -(defconst mime-token-regexp - (eval-when-compile - (concat "[^" mime-tspecial-char-list "\000-\040]+"))) -(defconst mime-charset-regexp mime-token-regexp) +;; More precisely, length of "[A-Za-z]+" is limited to at most 8. +;; (defconst mime-language-regexp "[A-Za-z]+\\(-[A-Za-z]+\\)*") +(defconst mime-language-regexp "[-A-Za-z]+") -(defconst mime-media-type/subtype-regexp - (concat mime-token-regexp "/" mime-token-regexp)) +(defconst mime-encoding-regexp mime-token-regexp) ;;; @@ base64 / B @@ -204,10 +194,9 @@ If method is nil, this field will not be encoded." ;;; (defsubst make-mime-content-type (type subtype &optional parameters) - (list* (cons 'type type) - (cons 'subtype subtype) - (nreverse parameters)) - ) + (cons (cons 'type type) + (cons (cons 'subtype subtype) + parameters))) (defsubst mime-content-type-primary-type (content-type) "Return primary-type of CONTENT-TYPE." @@ -215,15 +204,15 @@ If method is nil, this field will not be encoded." (defsubst mime-content-type-subtype (content-type) "Return subtype of CONTENT-TYPE." - (cdr (cadr content-type))) + (cdr (car (cdr content-type)))) (defsubst mime-content-type-parameters (content-type) "Return parameters of CONTENT-TYPE." - (cddr content-type)) + (cdr (cdr content-type))) (defsubst mime-content-type-parameter (content-type parameter) "Return PARAMETER value of CONTENT-TYPE." - (cdr (assoc parameter (mime-content-type-parameters content-type)))) + (cdr (assoc parameter (cdr (cdr content-type))))) (defsubst mime-type/subtype-string (type &optional subtype) @@ -237,6 +226,10 @@ If method is nil, this field will not be encoded." ;;; @ Content-Disposition ;;; +(defsubst make-mime-content-disposition (type &optional parameters) + (cons (cons 'type type) + parameters)) + (defsubst mime-content-disposition-type (content-disposition) "Return disposition-type of CONTENT-DISPOSITION." (cdr (car content-disposition))) @@ -325,7 +318,7 @@ service." (or (fboundp sym) (fset sym (symbol-function f)) )))) - + (defsubst mel-copy-backend (src-backend dst-backend) (let ((services mel-service-list)) (while services diff --git a/mime-en.texi b/mime-en.texi index 33c4efa..e04f744 100644 --- a/mime-en.texi +++ b/mime-en.texi @@ -25,10 +25,10 @@ process Internet Messages for GNU Emacsen. * Content-Transfer-Encoding:: Encoding Method * encoded-word:: Network representation of header * custom:: Various Customization -* Appendix:: -* Concept Index:: -* Function Index:: -* Variable Index:: +* Appendix:: +* Concept Index:: +* Function Index:: +* Variable Index:: @end menu @node Introduction, How to use, Top, Top @@ -1533,14 +1533,13 @@ newest FLIM by the following method. @example (0) cvs login - % cvs -d :pserver:anonymous@@chamonix.jaist.ac.jp:/hare/cvs/root \ - login + % cvs -d :pserver:anonymous@@cvs.m17n.org:/cvs/root login CVS password: [CR] # NULL string (1) checkout - % cvs -d :pserver:anonymous@@chamonix.jaist.ac.jp:/hare/cvs/root \ + % cvs -d :pserver:anonymous@@cvs.m17n.org:/cvs/root checkout checkout [-r TAG] flim @end example @@ -1549,7 +1548,7 @@ If you would like to join CVS based development, please send mail to @itemize @bullet @item - + @end itemize @noindent diff --git a/mime-ja.texi b/mime-ja.texi index cdda163..c7520bd 100644 --- a/mime-ja.texi +++ b/mime-ja.texi @@ -1529,14 +1529,13 @@ FLIM $B$N(B file $B$O(B CVS $B$r;H$C$F4IM}$5$l$F$$$^$9!#$3$N$?$a!"0J2<$NJ}K @example (0) cvs login - % cvs -d :pserver:anonymous@@chamonix.jaist.ac.jp:/hare/cvs/root \ - login + % cvs -d :pserver:anonymous@@cvs.m17n.org:/cvs/root login CVS password: [CR] # NULL string (1) checkout - % cvs -d :pserver:anonymous@@chamonix.jaist.ac.jp:/hare/cvs/root \ + % cvs -d :pserver:anonymous@@cvs.m17n.org:/cvs/root checkout checkout [-r TAG] flim @end example @@ -1545,7 +1544,7 @@ CVS $B$rMQ$$$?3+H/$K;22C$7$?$$J}$O(B @itemize @bullet @item - + @end itemize @noindent diff --git a/mime-parse.el b/mime-parse.el index ce8aeaf..a952c36 100644 --- a/mime-parse.el +++ b/mime-parse.el @@ -1,11 +1,12 @@ ;;; mime-parse.el --- MIME message parser -;; Copyright (C) 1994,1995,1996,1997,1998,1999 Free Software Foundation, Inc. +;; Copyright (C) 1994,95,96,97,98,99,2001 Free Software Foundation, Inc. ;; Author: MORIOKA Tomohiko +;; Shuhei KOBAYASHI ;; Keywords: parse, MIME, multimedia, mail, news -;; This file is part of SEMI (Spadework for Emacs MIME Interfaces). +;; This file is part of FLIM (Faithful Library about Internet Message). ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as @@ -57,59 +58,245 @@ be the result." (defun mime-analyze-tspecial (string start) (if (and (> (length string) start) (memq (aref string start) mime-tspecial-char-list)) - (cons (cons 'tpecials (substring string start (1+ start))) - (1+ start)) - )) + (cons (cons 'tspecials (substring string start (1+ start))) + (1+ start)))) (defun mime-analyze-token (string start) (if (and (string-match mime-token-regexp string start) (= (match-beginning 0) start)) (let ((end (match-end 0))) (cons (cons 'mime-token (substring string start end)) - ;;(substring string end) - end) - ))) + end)))) + +(defun mime-lexical-analyze (string) + "Analyze STRING as lexical tokens of MIME." + (let ((ret (std11-lexical-analyze string mime-lexical-analyzer)) + prev tail) + ;; skip leading linear-white-space. + (while (memq (car (car ret)) '(spaces comment)) + (setq ret (cdr ret))) + (setq prev ret + tail (cdr ret)) + ;; remove linear-white-space. + (while tail + (if (memq (car (car tail)) '(spaces comment)) + (progn + (setcdr prev (cdr tail)) + (setq tail (cdr tail))) + (setq prev (cdr prev) + tail (cdr tail)))) + ret)) ;;; @ field parser ;;; -(defconst mime/content-parameter-value-regexp - (concat "\\(" - std11-quoted-string-regexp - "\\|[^; \t\n]*\\)")) - -(defconst mime::parameter-regexp - (concat "^[ \t]*\;[ \t]*\\(" mime-token-regexp "\\)" - "[ \t]*=[ \t]*\\(" mime/content-parameter-value-regexp "\\)")) +(defun mime-decode-parameter-value (text charset language) + (with-temp-buffer + (set-buffer-multibyte nil) + (insert text) + (goto-char (point-min)) + (while (re-search-forward "%[0-9A-Fa-f][0-9A-Fa-f]" nil t) + (insert (prog1 (string-to-int + (buffer-substring (point)(- (point) 2)) + 16) + (delete-region (point)(- (point) 3))))) + (setq text (buffer-string)) + (when charset + ;; I believe that `decode-mime-charset-string' of mcs-e20.el should + ;; be independent of the value of `enable-multibyte-characters'. + (erase-buffer) + (set-buffer-multibyte t) + (setq text (decode-mime-charset-string text charset))) + (when language + (put-text-property 0 (length text) 'mime-language language text)) + text)) + +(defun mime-decode-parameter-encode-segment (segment) + (with-temp-buffer + (set-buffer-multibyte nil) + (insert segment) + (goto-char (point-min)) + (while (progn + (when (looking-at (eval-when-compile + (concat mime-attribute-char-regexp "+"))) + (goto-char (match-end 0))) + (not (eobp))) + (insert (prog1 (format "%%%02X" (char-int (char-after))) + (delete-region (point)(1+ (point)))))) + (buffer-string))) + +(defun mime-decode-parameters (params) + "Decode PARAMS as a property list of MIME parameter values. +Return value is an association list of MIME parameter values. +If parameter continuation is used, segments of values are concatenated. +If parameters contain charset information, values are decoded. +If parameters contain language information, it is set to `mime-language' +property of the decoded-value." + ;; (unless (zerop (% (length params) 2)) ...) + (let ((len (/ (length params) 2)) + dest eparams) + (while params + (if (and (string-match (eval-when-compile + (concat "^\\(" mime-attribute-char-regexp "+\\)" + "\\(\\*[0-9]+\\)?" ; continuation + "\\(\\*\\)?$")) ; charset/language + (car params)) + (> (match-end 0) (match-end 1))) + ;; parameter value extensions are used. + (let* ((attribute (downcase + (substring (car params) 0 (match-end 1)))) + (section (if (match-beginning 2) + (string-to-int + (substring (car params) + (1+ (match-beginning 2)) + (match-end 2))) + 0)) + ;; EPARAM := (ATTRIBUTE VALUES CHARSET LANGUAGE) + ;; VALUES := [1*VALUE] ; vector of LEN elements. + (eparam (assoc attribute eparams)) + (value (progn + (setq params (cdr params)) + (car params)))) + (if eparam + (setq eparam (cdr eparam)) + (setq eparam (list (make-vector len nil) nil nil) + eparams (cons (cons attribute eparam) eparams))) + ;; if parameter-name ends with "*", it is an extended-parameter. + (if (match-beginning 3) + (if (zerop section) + ;; extended-initial-parameter. + (if (string-match (eval-when-compile + (concat + "^\\(" mime-charset-regexp "\\)?" + "'\\(" mime-language-regexp "\\)?" + "'\\(\\(" mime-attribute-char-regexp + "\\|%[0-9A-Fa-f][0-9A-Fa-f]\\)+\\)$")) + value) + (progn + ;; text + (aset (car eparam) 0 + (substring value (match-beginning 3))) + (setq eparam (cdr eparam)) + ;; charset + (when (match-beginning 1) + (setcar eparam + (downcase + (substring value 0 (match-end 1))))) + (setq eparam (cdr eparam)) + ;; language + (when (match-beginning 2) + (setcar eparam + (intern + (downcase + (substring value + (match-beginning 2) + (match-end 2))))))) + ;; invalid parameter-value. + (aset (car eparam) 0 + (mime-decode-parameter-encode-segment value))) + ;; extended-other-parameter. + (if (string-match (eval-when-compile + (concat + "^\\(\\(" mime-attribute-char-regexp + "\\|%[0-9A-Fa-f][0-9A-Fa-f]\\)+\\)$")) + value) + (aset (car eparam) section value) + ;; invalid parameter-value. + (aset (car eparam) section + (mime-decode-parameter-encode-segment value)))) + ;; regular-parameter. parameter continuation only. + (aset (car eparam) section + (mime-decode-parameter-encode-segment value)))) + ;; parameter value extensions are not used, + ;; or invalid attribute-name (in RFC2231, although valid in RFC2045). + (setq dest (cons (cons (downcase (car params)) +;;; ;; decode (invalid!) encoded-words. +;;; (eword-decode-string +;;; (decode-mime-charset-string +;;; (car (cdr params)) +;;; default-mime-charset) +;;; 'must-unfold) + (car (cdr params))) + dest) + params (cdr params))) + (setq params (cdr params))) + ;; concat and decode parameters. + (while eparams + (setq dest (cons (cons (car (car eparams)) ; attribute + (mime-decode-parameter-value + (mapconcat (function identity) + (nth 1 (car eparams)) ; values + "") + (nth 2 (car eparams)) ; charset + (nth 3 (car eparams)) ; language + )) + dest) + eparams (cdr eparams))) + dest)) + +;;; for compatibility with flim-1_13-rfc2231 API. +(defalias 'mime-parse-parameters-from-list 'mime-decode-parameters) +(make-obsolete 'mime-parse-parameters-from-list 'mime-decode-parameters) + +(defun mime-parse-parameters (tokens) + "Parse TOKENS as MIME parameter values. +Return a property list, which is a list of the form +\(PARAMETER-NAME1 VALUE1 PARAMETER-NAME2 VALUE2...)." + (let (params attribute) + (while (and tokens + (eq (car (car tokens)) 'tspecials) + (string= (cdr (car tokens)) ";") + (setq tokens (cdr tokens)) + (eq (car (car tokens)) 'mime-token) + (progn + (setq attribute (cdr (car tokens))) + (setq tokens (cdr tokens))) + (eq (car (car tokens)) 'tspecials) + (string= (cdr (car tokens)) "=") + (setq tokens (cdr tokens)) + (memq (car (car tokens)) '(mime-token quoted-string))) + (setq params (cons (if (eq (car (car tokens)) 'quoted-string) + (std11-strip-quoted-pair (cdr (car tokens))) + (cdr (car tokens))) + (cons attribute params)) + tokens (cdr tokens))) + (nreverse params))) ;; unlimited patch by simm-emacs@fan.gr.jp ;; Mon, 10 Jan 2000 12:59:46 +0900 (defun mime-parse-parameter (string) (let ((str string)) (and mime-decode-unlimited - (string-match "\033" str) - (setq str (decode-coding-string string 'iso-2022-7bit-ss2))) - (if (string-match mime::parameter-regexp str) - (let ((e (match-end 2))) - (if mime-decode-unlimited - (cons - (cons (downcase - (encode-coding-string - (substring str (match-beginning 1) (match-end 1)) - 'iso-2022-7bit-ss2)) - (encode-coding-string - (std11-strip-quoted-string - (substring str (match-beginning 2) e)) - 'iso-2022-jp)) - (encode-coding-string (substring str e) 'iso-2022-7bit-ss2)) - (cons - (cons (downcase (substring str (match-beginning 1) (match-end 1))) - (std11-strip-quoted-string (substring sutr (match-beginning 2) e))) - (substring str e))))))) - - -;;; @ Content-Type + (string-match "\033" str) + (setq str (decode-coding-string string 'iso-2022-7bit-ss2))) + (if (string-match + `,(concat "^[ \t]*\;[ \t]*\\(" mime-token-regexp "\\)" + "[ \t]*=[ \t]*\\(" + "\\(\"\\([^\"\\\r\n]\\|\\\\.\\)*\"\\|[^; \t\n]*\\)" + "\\)") + str) + (let ((e (match-end 2))) + (if mime-decode-unlimited + (cons + (cons (downcase + (encode-coding-string + (substring str (match-beginning 1) (match-end 1)) + 'iso-2022-7bit-ss2)) + (encode-coding-string + (std11-strip-quoted-string + (substring str (match-beginning 2) e)) + 'iso-2022-jp)) + (encode-coding-string (substring str e) 'iso-2022-7bit-ss2)) + (cons + (cons + (downcase (substring str (match-beginning 1) (match-end 1))) + (std11-strip-quoted-string (substring sutr + (match-beginning 2) e))) + (substring str e))))))) + + +;;; @@ Content-Type ;;; ;;;###autoload @@ -138,28 +325,23 @@ are string." ;;;###autoload (defun mime-read-Content-Type () - "Read field-body of Content-Type field from current-buffer, -and return parsed it. Format of return value is as same as -`mime-parse-Content-Type'." - (let ((str (std11-field-body "Content-Type"))) - (if str - (mime-parse-Content-Type str) + "Parse field-body of Content-Type field of current-buffer. +Return value is a mime-content-type object. +If Content-Type field is not found, return nil." + (let ((field-body (std11-field-body "Content-Type"))) + (if field-body + (mime-parse-Content-Type field-body) ))) -;;; @ Content-Disposition +;;; @@ Content-Disposition ;;; -(eval-and-compile - (defconst mime-disposition-type-regexp mime-token-regexp) - ) - ;;;###autoload (defun mime-parse-Content-Disposition (string) "Parse STRING as field-body of Content-Disposition field." (setq string (std11-unfold-string string)) - (if (string-match (eval-when-compile - (concat "^" mime-disposition-type-regexp)) string) + (if (string-match `,(concat "^" mime-token-regexp) string) (let* ((e (match-end 0)) (type (downcase (substring string 0 e))) ret dest) @@ -174,15 +356,16 @@ and return parsed it. Format of return value is as same as ;;;###autoload (defun mime-read-Content-Disposition () - "Read field-body of Content-Disposition field from current-buffer, -and return parsed it." - (let ((str (std11-field-body "Content-Disposition"))) - (if str - (mime-parse-Content-Disposition str) + "Parse field-body of Content-Disposition field of current-buffer. +Return value is a mime-content-disposition object. +If Content-Disposition field is not found, return nil." + (let ((field-body (std11-field-body "Content-Disposition"))) + (if field-body + (mime-parse-Content-Disposition field-body) ))) -;;; @ Content-Transfer-Encoding +;;; @@ Content-Transfer-Encoding ;;; ;;;###autoload @@ -200,32 +383,31 @@ and return parsed it." )))) ;;;###autoload -(defun mime-read-Content-Transfer-Encoding (&optional default-encoding) - "Read field-body of Content-Transfer-Encoding field from -current-buffer, and return it. -If is is not found, return DEFAULT-ENCODING." - (let ((str (std11-field-body "Content-Transfer-Encoding"))) - (if str - (mime-parse-Content-Transfer-Encoding str) - default-encoding))) +(defun mime-read-Content-Transfer-Encoding () + "Parse field-body of Content-Transfer-Encoding field of current-buffer. +Return value is a string. +If Content-Transfer-Encoding field is not found, return nil." + (let ((field-body (std11-field-body "Content-Transfer-Encoding"))) + (if field-body + (mime-parse-Content-Transfer-Encoding field-body) + ))) -;;; @ Content-Id / Message-Id +;;; @@ Content-ID / Message-ID ;;; ;;;###autoload (defun mime-parse-msg-id (tokens) - "Parse TOKENS as msg-id of Content-Id or Message-Id field." + "Parse TOKENS as msg-id of Content-ID or Message-ID field." (car (std11-parse-msg-id tokens))) ;;;###autoload (defun mime-uri-parse-cid (string) "Parse STRING as cid URI." - (inline - (mime-parse-msg-id (cons '(specials . "<") - (nconc - (cdr (cdr (std11-lexical-analyze string))) - '((specials . ">"))))))) + (mime-parse-msg-id (cons '(specials . "<") + (nconc + (cdr (cdr (std11-lexical-analyze string))) + '((specials . ">")))))) ;;; @ message parser @@ -358,6 +540,7 @@ If is is not found, return DEFAULT-ENCODING." (defun mime-parse-buffer (&optional buffer representation-type) "Parse BUFFER as a MIME message. If buffer is omitted, it parses current-buffer." + (require 'mmbuffer) (save-excursion (if buffer (set-buffer buffer)) (mime-parse-message (or representation-type diff --git a/ntlm.el b/ntlm.el new file mode 100644 index 0000000..33573b2 --- /dev/null +++ b/ntlm.el @@ -0,0 +1,531 @@ +;;; ntlm.el --- NTLM (NT LanManager) authentication support + +;; Copyright (C) 2001 Taro Kawagishi +;; Author: Taro Kawagishi +;; Keywords: NTLM, SASL +;; Version: 1.00 +;; Created: February 2001 + +;; This program 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 2, or (at your option) +;; any later version. +;; +;; This program 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 this program; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, +;; Boston, MA 02111-1307, USA. + +;;; Commentary: + +;; This library is a direct translation of the Samba release 2.2.0 +;; implementation of Windows NT and LanManager compatible password +;; encryption. +;; +;; Interface functions: +;; +;; ntlm-build-auth-request +;; This will return a binary string, which should be used in the +;; base64 encoded form and it is the caller's responsibility to encode +;; the returned string with base64. +;; +;; ntlm-build-auth-response +;; It is the caller's responsibility to pass a base64 decoded string +;; (which will be a binary string) as the first argument and to +;; encode the returned string with base64. The second argument user +;; should be given in user@domain format. +;; +;; ntlm-get-password-hashes +;; +;; +;; NTLM authentication procedure example: +;; +;; 1. Open a network connection to the Exchange server at the IMAP port (143) +;; 2. Receive an opening message such as: +;; "* OK Microsoft Exchange IMAP4rev1 server version 5.5.2653.7 (XXXX) ready" +;; 3. Ask for IMAP server capability by sending "NNN capability" +;; 4. Receive a capability message such as: +;; "* CAPABILITY IMAP4 IMAP4rev1 IDLE LITERAL+ LOGIN-REFERRALS MAILBOX-REFERRALS NAMESPACE AUTH=NTLM" +;; 5. Ask for NTLM authentication by sending a string +;; "NNN authenticate ntlm" +;; 6. Receive continuation acknowledgment "+" +;; 7. Send NTLM authentication request generated by 'ntlm-build-auth-request +;; 8. Receive NTLM challenge string following acknowledgment "+" +;; 9. Generate response to challenge by 'ntlm-build-auth-response +;; (here two hash function values of the user password are encrypted) +;; 10. Receive authentication completion message such as +;; "NNN OK AUTHENTICATE NTLM completed." + +;;; Code: + +(require 'poem) +(require 'md4) + +;;; +;;; NTLM authentication interface functions + +(defun ntlm-build-auth-request (user &optional domain) + "Return the NTLM authentication request string for USER and DOMAIN. +USER is a string representing a user name to be authenticated and +DOMAIN is a NT domain. USER can include a NT domain part as in +user@domain where the string after @ is used as the domain if DOMAIN +is not given." + (interactive) + (let ((request-ident (concat "NTLMSSP" (make-string 1 0))) + (request-msgType (concat (make-string 1 1) (make-string 3 0))) + ;0x01 0x00 0x00 0x00 + (request-flags (concat (make-string 1 7) (make-string 1 178) + (make-string 2 0))) + ;0x07 0xb2 0x00 0x00 + lu ld off-d off-u) + (when (string-match "@" user) + (unless domain + (setq domain (substring user (1+ (match-beginning 0))))) + (setq user (substring user 0 (match-beginning 0)))) + ;; set fields offsets within the request struct + (setq lu (length user)) + (setq ld (length domain)) + (setq off-u 32) ;offset to the string 'user + (setq off-d (+ 32 lu)) ;offset to the string 'domain + ;; pack the request struct in a string + (concat request-ident ;8 bytes + request-msgType ;4 bytes + request-flags ;4 bytes + (md4-pack-int16 lu) ;user field, count field + (md4-pack-int16 lu) ;user field, max count field + (md4-pack-int32 (cons 0 off-u)) ;user field, offset field + (md4-pack-int16 ld) ;domain field, count field + (md4-pack-int16 ld) ;domain field, max count field + (md4-pack-int32 (cons 0 off-d)) ;domain field, offset field + user ;bufer field + domain ;bufer field + ))) + +(defun ntlm-build-auth-response (challenge user password-hashes) + "Return the response string to a challenge string CHALLENGE given by +the NTLM based server for the user USER and the password hash list +PASSWORD-HASHES. NTLM uses two hash values which are represented +by PASSWORD-HASHES. PASSWORD-HASHES should be a return value of + (list (smb-passwd-hash password) (ntlm-md4hash password))" + (let* ((rchallenge (string-as-unibyte challenge)) + ;; get fields within challenge struct + ;;(ident (substring rchallenge 0 8)) ;ident, 8 bytes + ;;(msgType (substring rchallenge 8 12)) ;msgType, 4 bytes + (uDomain (substring rchallenge 12 20)) ;uDomain, 8 bytes + (flags (substring rchallenge 20 24)) ;flags, 4 bytes + (challengeData (substring rchallenge 24 32)) ;challengeData, 8 bytes + uDomain-len uDomain-offs + ;; response struct and its fields + lmRespData ;lmRespData, 24 bytes + ntRespData ;ntRespData, 24 bytes + domain ;ascii domain string + lu ld off-lm off-nt off-d off-u off-w off-s) + ;; extract domain string from challenge string + (setq uDomain-len (md4-unpack-int16 (substring uDomain 0 2))) + (setq uDomain-offs (md4-unpack-int32 (substring uDomain 4 8))) + (setq domain + (ntlm-unicode2ascii (substring challenge + (cdr uDomain-offs) + (+ (cdr uDomain-offs) uDomain-len)) + (/ uDomain-len 2))) + ;; overwrite domain in case user is given in @ format + (when (string-match "@" user) + (setq domain (substring user (1+ (match-beginning 0)))) + (setq user (substring user 0 (match-beginning 0)))) + + ;; generate response data + (setq lmRespData + (smb-owf-encrypt (car password-hashes) challengeData)) + (setq ntRespData + (smb-owf-encrypt (cadr password-hashes) challengeData)) + + ;; get offsets to fields to pack the response struct in a string + (setq lu (length user)) + (setq ld (length domain)) + (setq off-lm 64) ;offset to string 'lmResponse + (setq off-nt (+ 64 24)) ;offset to string 'ntResponse + (setq off-d (+ 64 48)) ;offset to string 'uDomain + (setq off-u (+ 64 48 (* 2 ld))) ;offset to string 'uUser + (setq off-w (+ 64 48 (* 2 (+ ld lu)))) ;offset to string 'uWks + (setq off-s (+ 64 48 (* 2 (+ ld lu lu)))) ;offset to string 'sessionKey + ;; pack the response struct in a string + (concat "NTLMSSP\0" ;response ident field, 8 bytes + (md4-pack-int32 '(0 . 3)) ;response msgType field, 4 bytes + + ;; lmResponse field, 8 bytes + ;;AddBytes(response,lmResponse,lmRespData,24); + (md4-pack-int16 24) ;len field + (md4-pack-int16 24) ;maxlen field + (md4-pack-int32 (cons 0 off-lm)) ;field offset + + ;; ntResponse field, 8 bytes + ;;AddBytes(response,ntResponse,ntRespData,24); + (md4-pack-int16 24) ;len field + (md4-pack-int16 24) ;maxlen field + (md4-pack-int32 (cons 0 off-nt)) ;field offset + + ;; uDomain field, 8 bytes + ;;AddUnicodeString(response,uDomain,domain); + ;;AddBytes(response, uDomain, udomain, 2*ld); + (md4-pack-int16 (* 2 ld)) ;len field + (md4-pack-int16 (* 2 ld)) ;maxlen field + (md4-pack-int32 (cons 0 off-d)) ;field offset + + ;; uUser field, 8 bytes + ;;AddUnicodeString(response,uUser,u); + ;;AddBytes(response, uUser, uuser, 2*lu); + (md4-pack-int16 (* 2 lu)) ;len field + (md4-pack-int16 (* 2 lu)) ;maxlen field + (md4-pack-int32 (cons 0 off-u)) ;field offset + + ;; uWks field, 8 bytes + ;;AddUnicodeString(response,uWks,u); + (md4-pack-int16 (* 2 lu)) ;len field + (md4-pack-int16 (* 2 lu)) ;maxlen field + (md4-pack-int32 (cons 0 off-w)) ;field offset + + ;; sessionKey field, 8 bytes + ;;AddString(response,sessionKey,NULL); + (md4-pack-int16 0) ;len field + (md4-pack-int16 0) ;maxlen field + (md4-pack-int32 (cons 0 (- off-s off-lm))) ;field offset + + ;; flags field, 4 bytes + flags ; + + ;; buffer field + lmRespData ;lmResponse, 24 bytes + ntRespData ;ntResponse, 24 bytes + (ntlm-ascii2unicode domain ;unicode domain string, 2*ld bytes + (length domain)) ; + (ntlm-ascii2unicode user ;unicode user string, 2*lu bytes + (length user)) ; + (ntlm-ascii2unicode user ;unicode user string, 2*lu bytes + (length user)) ; + ))) + +(defun ntlm-get-password-hashes (password) + "Return a pair of SMB hash and NT MD4 hash of the given password PASSWORD" + (list (smb-passwd-hash password) + (ntlm-md4hash password))) + +(defun ntlm-ascii2unicode (str len) + "Convert an ASCII string into a NT Unicode string, which is +little-endian utf16." + (let ((utf (make-string (* 2 len) 0)) (i 0) val) + (while (and (< i len) + (not (zerop (setq val (aref str i))))) + (aset utf (* 2 i) val) + (aset utf (1+ (* 2 i)) 0) + (setq i (1+ i))) + utf)) + +(defun ntlm-unicode2ascii (str len) + "Extract 7 bits ASCII part of a little endian utf16 string STR of length LEN." + (let ((buf (make-string len 0)) (i 0) (j 0)) + (while (< i len) + (aset buf i (logand (aref str j) 127)) ;(string-to-number "7f" 16) + (setq i (1+ i) + j (+ 2 j))) + buf)) + +(defun smb-passwd-hash (passwd) + "Return the SMB password hash string of 16 bytes long for the given password +string PASSWD. PASSWD is truncated to 14 bytes if longer." + (let ((len (min (length passwd) 14))) + (smbdes-e-p16 + (concat (substring (upcase passwd) 0 len) ;fill top 14 bytes with passwd + (make-string (- 15 len) 0))))) + +(defun smb-owf-encrypt (passwd c8) + "Return the response string of 24 bytes long for the given password +string PASSWD based on the DES encryption. PASSWD is of at most 14 +bytes long and the challenge string C8 of 8 bytes long." + (let ((len (min (length passwd) 16)) p22) + (setq p22 (concat (substring passwd 0 len) ;fill top 16 bytes with passwd + (make-string (- 22 len) 0))) + (smbdes-e-p24 p22 c8))) + +(defun smbdes-e-p24 (p22 c8) + "Return a 24 bytes hashed string for a 21 bytes string P22 and a 8 bytes +string C8." + (concat (smbhash c8 p22 t) ;hash first 8 bytes of p22 + (smbhash c8 (substring p22 7) t) + (smbhash c8 (substring p22 14) t))) + +(defconst smb-sp8 [75 71 83 33 64 35 36 37]) + +(defun smbdes-e-p16 (p15) + "Return a 16 bytes hashed string for a 15 bytes string P15." + (concat (smbhash smb-sp8 p15 t) ;hash of first 8 bytes of p15 + (smbhash smb-sp8 (substring p15 7) t) ;hash of last 8 bytes of p15 + )) + +(defun smbhash (in key forw) + "Return the hash string of length 8 for a string IN of length 8 and +a string KEY of length 8. FORW is t or nil." + (let ((out (make-string 8 0)) + outb ;string of length 64 + (inb (make-string 64 0)) + (keyb (make-string 64 0)) + (key2 (smb-str-to-key key)) + (i 0) aa) + (while (< i 64) + (unless (zerop (logand (aref in (/ i 8)) (lsh 1 (- 7 (% i 8))))) + (aset inb i 1)) + (unless (zerop (logand (aref key2 (/ i 8)) (lsh 1 (- 7 (% i 8))))) + (aset keyb i 1)) + (setq i (1+ i))) + (setq outb (smb-dohash inb keyb forw)) + (setq i 0) + (while (< i 64) + (unless (zerop (aref outb i)) + (setq aa (aref out (/ i 8))) + (aset out (/ i 8) + (logior aa (lsh 1 (- 7 (% i 8)))))) + (setq i (1+ i))) + out)) + +(defun smb-str-to-key (str) + "Return a string of length 8 for the given string STR of length 7." + (let ((key (make-string 8 0)) + (i 7)) + (aset key 0 (lsh (aref str 0) -1)) + (aset key 1 (logior + (lsh (logand (aref str 0) 1) 6) + (lsh (aref str 1) -2))) + (aset key 2 (logior + (lsh (logand (aref str 1) 3) 5) + (lsh (aref str 2) -3))) + (aset key 3 (logior + (lsh (logand (aref str 2) 7) 4) + (lsh (aref str 3) -4))) + (aset key 4 (logior + (lsh (logand (aref str 3) 15) 3) + (lsh (aref str 4) -5))) + (aset key 5 (logior + (lsh (logand (aref str 4) 31) 2) + (lsh (aref str 5) -6))) + (aset key 6 (logior + (lsh (logand (aref str 5) 63) 1) + (lsh (aref str 6) -7))) + (aset key 7 (logand (aref str 6) 127)) + (while (>= i 0) + (aset key i (lsh (aref key i) 1)) + (setq i (1- i))) + key)) + +(defconst smb-perm1 [57 49 41 33 25 17 9 + 1 58 50 42 34 26 18 + 10 2 59 51 43 35 27 + 19 11 3 60 52 44 36 + 63 55 47 39 31 23 15 + 7 62 54 46 38 30 22 + 14 6 61 53 45 37 29 + 21 13 5 28 20 12 4]) + +(defconst smb-perm2 [14 17 11 24 1 5 + 3 28 15 6 21 10 + 23 19 12 4 26 8 + 16 7 27 20 13 2 + 41 52 31 37 47 55 + 30 40 51 45 33 48 + 44 49 39 56 34 53 + 46 42 50 36 29 32]) + +(defconst smb-perm3 [58 50 42 34 26 18 10 2 + 60 52 44 36 28 20 12 4 + 62 54 46 38 30 22 14 6 + 64 56 48 40 32 24 16 8 + 57 49 41 33 25 17 9 1 + 59 51 43 35 27 19 11 3 + 61 53 45 37 29 21 13 5 + 63 55 47 39 31 23 15 7]) + +(defconst smb-perm4 [32 1 2 3 4 5 + 4 5 6 7 8 9 + 8 9 10 11 12 13 + 12 13 14 15 16 17 + 16 17 18 19 20 21 + 20 21 22 23 24 25 + 24 25 26 27 28 29 + 28 29 30 31 32 1]) + +(defconst smb-perm5 [16 7 20 21 + 29 12 28 17 + 1 15 23 26 + 5 18 31 10 + 2 8 24 14 + 32 27 3 9 + 19 13 30 6 + 22 11 4 25]) + +(defconst smb-perm6 [40 8 48 16 56 24 64 32 + 39 7 47 15 55 23 63 31 + 38 6 46 14 54 22 62 30 + 37 5 45 13 53 21 61 29 + 36 4 44 12 52 20 60 28 + 35 3 43 11 51 19 59 27 + 34 2 42 10 50 18 58 26 + 33 1 41 9 49 17 57 25]) + +(defconst smb-sc [1 1 2 2 2 2 2 2 1 2 2 2 2 2 2 1]) + +(defconst smb-sbox [[[14 4 13 1 2 15 11 8 3 10 6 12 5 9 0 7] + [ 0 15 7 4 14 2 13 1 10 6 12 11 9 5 3 8] + [ 4 1 14 8 13 6 2 11 15 12 9 7 3 10 5 0] + [15 12 8 2 4 9 1 7 5 11 3 14 10 0 6 13]] + [[15 1 8 14 6 11 3 4 9 7 2 13 12 0 5 10] + [ 3 13 4 7 15 2 8 14 12 0 1 10 6 9 11 5] + [ 0 14 7 11 10 4 13 1 5 8 12 6 9 3 2 15] + [13 8 10 1 3 15 4 2 11 6 7 12 0 5 14 9]] + [[10 0 9 14 6 3 15 5 1 13 12 7 11 4 2 8] + [13 7 0 9 3 4 6 10 2 8 5 14 12 11 15 1] + [13 6 4 9 8 15 3 0 11 1 2 12 5 10 14 7] + [ 1 10 13 0 6 9 8 7 4 15 14 3 11 5 2 12]] + [[ 7 13 14 3 0 6 9 10 1 2 8 5 11 12 4 15] + [13 8 11 5 6 15 0 3 4 7 2 12 1 10 14 9] + [10 6 9 0 12 11 7 13 15 1 3 14 5 2 8 4] + [ 3 15 0 6 10 1 13 8 9 4 5 11 12 7 2 14]] + [[ 2 12 4 1 7 10 11 6 8 5 3 15 13 0 14 9] + [14 11 2 12 4 7 13 1 5 0 15 10 3 9 8 6] + [ 4 2 1 11 10 13 7 8 15 9 12 5 6 3 0 14] + [11 8 12 7 1 14 2 13 6 15 0 9 10 4 5 3]] + [[12 1 10 15 9 2 6 8 0 13 3 4 14 7 5 11] + [10 15 4 2 7 12 9 5 6 1 13 14 0 11 3 8] + [ 9 14 15 5 2 8 12 3 7 0 4 10 1 13 11 6] + [ 4 3 2 12 9 5 15 10 11 14 1 7 6 0 8 13]] + [[ 4 11 2 14 15 0 8 13 3 12 9 7 5 10 6 1] + [13 0 11 7 4 9 1 10 14 3 5 12 2 15 8 6] + [ 1 4 11 13 12 3 7 14 10 15 6 8 0 5 9 2] + [ 6 11 13 8 1 4 10 7 9 5 0 15 14 2 3 12]] + [[13 2 8 4 6 15 11 1 10 9 3 14 5 0 12 7] + [ 1 15 13 8 10 3 7 4 12 5 6 11 0 14 9 2] + [ 7 11 4 1 9 12 14 2 0 6 10 13 15 3 5 8] + [ 2 1 14 7 4 10 8 13 15 12 9 0 3 5 6 11]]]) + +(defsubst string-permute (in perm n) + "Return a string of length N for a string IN and a permutation vector +PERM of size N. The length of IN should be height of PERM." + (let ((i 0) (out (make-string n 0))) + (while (< i n) + (aset out i (aref in (- (aref perm i) 1))) + (setq i (1+ i))) + out)) + +(defsubst string-lshift (str count len) + "Return a string by circularly shifting a string STR by COUNT to the left. +length of STR is LEN." + (let ((c (% count len))) + (concat (substring str c len) (substring str 0 c)))) + +(defsubst string-xor (in1 in2 n) + "Return exclusive-or of sequences in1 and in2" + (let ((w (make-string n 0)) (i 0)) + (while (< i n) + (aset w i (logxor (aref in1 i) (aref in2 i))) + (setq i (1+ i))) + w)) + +(defun smb-dohash (in key forw) + "Return the hash value for a string IN and a string KEY. +Length of IN and KEY are 64. FORW non nill means forward, nil means +backward." + (let (pk1 ;string of length 56 + c ;string of length 28 + d ;string of length 28 + cd ;string of length 56 + (ki (make-vector 16 0)) ;vector of string of length 48 + pd1 ;string of length 64 + l ;string of length 32 + r ;string of length 32 + rl ;string of length 64 + (i 0) (j 0) (k 0)) + (setq pk1 (string-permute key smb-perm1 56)) + (setq c (substring pk1 0 28)) + (setq d (substring pk1 28 56)) + + (setq i 0) + (while (< i 16) + (setq c (string-lshift c (aref smb-sc i) 28)) + (setq d (string-lshift d (aref smb-sc i) 28)) + (setq cd (concat (substring c 0 28) (substring d 0 28))) + (aset ki i (string-permute cd smb-perm2 48)) + (setq i (1+ i))) + + (setq pd1 (string-permute in smb-perm3 64)) + + (setq l (substring pd1 0 32)) + (setq r (substring pd1 32 64)) + + (setq i 0) + (let (er ;string of length 48 + erk ;string of length 48 + (b (make-vector 8 0)) ;vector of strings of length 6 + cb ;string of length 32 + pcb ;string of length 32 + r2 ;string of length 32 + jj m n bj sbox-jmn) + (while (< i 16) + (setq er (string-permute r smb-perm4 48)) + (setq erk (string-xor er + (aref ki (if forw i (- 15 i))) + 48)) + (setq j 0) + (while (< j 8) + (setq jj (* 6 j)) + (aset b j (substring erk jj (+ jj 6))) + (setq j (1+ j))) + (setq j 0) + (while (< j 8) + (setq bj (aref b j)) + (setq m (logior (lsh (aref bj 0) 1) (aref bj 5))) + (setq n (logior (lsh (aref bj 1) 3) + (lsh (aref bj 2) 2) + (lsh (aref bj 3) 1) + (aref bj 4))) + (setq k 0) + (setq sbox-jmn (aref (aref (aref smb-sbox j) m) n)) + (while (< k 4) + (aset bj k + (if (zerop (logand sbox-jmn (lsh 1 (- 3 k)))) + 0 1)) + (setq k (1+ k))) + (setq j (1+ j))) + + (setq j 0) + (setq cb nil) + (while (< j 8) + (setq cb (concat cb (substring (aref b j) 0 4))) + (setq j (1+ j))) + + (setq pcb (string-permute cb smb-perm5 32)) + (setq r2 (string-xor l pcb 32)) + (setq l r) + (setq r r2) + (setq i (1+ i)))) + (setq rl (concat r l)) + (string-permute rl smb-perm6 64))) + +(defun ntlm-md4hash (passwd) + "Return the 16 bytes MD4 hash of a string PASSWD after converting it +into a Unicode string. PASSWD is truncated to 128 bytes if longer." + (let (len wpwd) + ;; Password cannot be longer than 128 characters + (setq len (length passwd)) + (if (> len 128) + (setq len 128)) + ;; Password must be converted to NT unicode + (setq wpwd (ntlm-ascii2unicode passwd len)) + ;; Calculate length in bytes + (setq len (* len 2)) + (md4 wpwd len))) + +(provide 'ntlm) + +;;; ntlm.el ends here diff --git a/sasl-ntlm.el b/sasl-ntlm.el new file mode 100644 index 0000000..67b4c96 --- /dev/null +++ b/sasl-ntlm.el @@ -0,0 +1,65 @@ +;;; sasl-ntlm.el --- NTLM (NT Lan Manager) module for the SASL client framework + +;; Copyright (C) 2000 Free Software Foundation, Inc. + +;; Author: Taro Kawagishi +;; Keywords: SASL, NTLM +;; Version: 1.00 +;; Created: February 2001 + +;; This program 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 2, or (at your option) +;; any later version. +;; +;; This program 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 this program; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, +;; Boston, MA 02111-1307, USA. + +;;; Commentary: + +;; This is a SASL interface layer for NTLM authentication message +;; generation by ntlm.el + +;;; Code: + +(require 'sasl) +(require 'ntlm) + +(defconst sasl-ntlm-steps + '(ignore ;nothing to do before making + sasl-ntlm-request ;authentication request + sasl-ntlm-response) ;response to challenge + "A list of functions to be called in sequnece for the NTLM +authentication steps. Ther are called by 'sasl-next-step.") + +(defun sasl-ntlm-request (client step) + "SASL step function to generate a NTLM authentication request to the server. +Called from 'sasl-next-step. +CLIENT is a vector [mechanism user service server sasl-client-properties] +STEP is a vector [ ]" + (let ((user (sasl-client-name client))) + (ntlm-build-auth-request user))) + +(defun sasl-ntlm-response (client step) + "SASL step function to generate a NTLM response against the server +challenge stored in the 2nd element of STEP. Called from 'sasl-next-step." + (let* ((user (sasl-client-name client)) + (passphrase + (sasl-read-passphrase (format "NTLM passphrase for %s: " user))) + (challenge (sasl-step-data step))) + (ntlm-build-auth-response challenge user + (ntlm-get-password-hashes passphrase)))) + +(put 'sasl-ntlm 'sasl-mechanism + (sasl-make-mechanism "NTLM" sasl-ntlm-steps)) + +(provide 'sasl-ntlm) + +;;; sasl-ntlm.el ends here diff --git a/sasl-scram.el b/sasl-scram.el new file mode 100644 index 0000000..bcd46a9 --- /dev/null +++ b/sasl-scram.el @@ -0,0 +1,260 @@ +;;; sasl-scram.el --- Compute SCRAM-MD5. + +;; Copyright (C) 1999 Shuhei KOBAYASHI + +;; Author: Shuhei KOBAYASHI +;; Kenichi OKADA +;; Keywords: SCRAM-MD5, HMAC-MD5, SASL, IMAP, POP, ACAP + +;; This file is part of FLIM (Faithful Library about Internet Message). + +;; This program 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 2, or +;; (at your option) any later version. + +;; This program 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 this program; see the file COPYING. If not, write to +;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +;; Boston, MA 02111-1307, USA. + +;;; Commentary: + +;; This program is implemented from draft-newman-auth-scram-03.txt. +;; +;; It is caller's responsibility to base64-decode challenges and +;; base64-encode responses in IMAP4 AUTHENTICATE command. +;; +;; Passphrase should be longer than 16 bytes. (See RFC 2195) + +;; Examples. +;; +;; (sasl-scram-md5-make-security-info nil t 0) +;; => "^A^@^@^@" +;; +;; (base64-encode-string +;; (sasl-scram-md5-make-client-msg-2 +;; (base64-decode-string "dGVzdHNhbHQBAAAAaW1hcEBlbGVhbm9yLmlubm9zb2Z0LmNvbQBqaGNOWmxSdVBiemlGcCt2TFYrTkN3") +;; (base64-decode-string "AGNocmlzADx0NG40UGFiOUhCMEFtL1FMWEI3MmVnQGVsZWFub3IuaW5ub3NvZnQuY29tPg==") +;; (sasl-scram-md5-make-salted-pass +;; "secret stuff" "testsalt") +;; (sasl-scram-md5-make-security-info nil t 0))) +;; => "AQAAAMg9jU8CeB4KOfk7sUhSQPs=" +;; +;; (base64-encode-string +;; (sasl-scram-md5-make-server-msg-2 +;; (base64-decode-string "dGVzdHNhbHQBAAAAaW1hcEBlbGVhbm9yLmlubm9zb2Z0LmNvbQBqaGNOWmxSdVBiemlGcCt2TFYrTkN3") +;; (base64-decode-string "AGNocmlzADx0NG40UGFiOUhCMEFtL1FMWEI3MmVnQGVsZWFub3IuaW5ub3NvZnQuY29tPg==") +;; (sasl-scram-md5-make-security-info nil t 0) +;; "testsalt" +;; (sasl-scram-md5-make-salted-pass +;; "secret stuff" "testsalt"))) +;; => "U0odqYw3B7XIIW0oSz65OQ==" + +;;; Code: + +(require 'sasl) +(require 'hmac-md5) + +(defvar sasl-scram-md5-unique-id-function + sasl-unique-id-function) + +(defconst sasl-scram-md5-steps + '(ignore ;no initial response + sasl-scram-md5-response-1 + sasl-scram-md5-response-2 + sasl-scram-md5-authenticate-server)) + +(defmacro sasl-scram-md5-security-info-no-security-layer (security-info) + `(eq (logand (aref ,security-info 0) 1) 1)) +(defmacro sasl-scram-md5-security-info-integrity-protection-layer (security-info) + `(eq (logand (aref ,security-info 0) 2) 2)) +(defmacro sasl-scram-md5-security-info-buffer-size (security-info) + `(let ((ssecinfo ,security-info)) + (+ (lsh (aref ssecinfo 1) 16) + (lsh (aref ssecinfo 2) 8) + (aref ssecinfo 3)))) + +(defun sasl-scram-md5-make-security-info (integrity-protection-layer + no-security-layer buffer-size) + (let ((csecinfo (make-string 4 0))) + (when integrity-protection-layer + (aset csecinfo 0 2)) + (if no-security-layer + (aset csecinfo 0 (logior (aref csecinfo 0) 1)) + (aset csecinfo 1 + (lsh (logand buffer-size (lsh 255 16)) -16)) + (aset csecinfo 2 + (lsh (logand buffer-size (lsh 255 8)) -8)) + (aset csecinfo 3 (logand buffer-size 255))) + csecinfo)) + +(defun sasl-scram-md5-make-unique-nonce () ; 8*OCTET, globally unique. + ;; For example, concatenated string of process-identifier, system-clock, + ;; sequence-number, random-number, and domain-name. + (let* ((sasl-unique-id-function sasl-scram-md5-unique-id-function) + (id (sasl-unique-id))) + (unwind-protect + (concat "<" id "@" (system-name) ">") + (fillarray id 0)))) + +(defun sasl-scram-md5-xor-string (str1 str2) + ;; (length str1) == (length str2) == (length dst) == 16 (in SCRAM-MD5) + (let* ((len (length str1)) + (dst (make-string len 0)) + (pos 0)) + (while (< pos len) + (aset dst pos (logxor (aref str1 pos) (aref str2 pos))) + (setq pos (1+ pos))) + dst)) + +(defun sasl-scram-md5-make-client-msg-1 (authenticate-id &optional authorize-id nonce) + "Make an initial client message from AUTHENTICATE-ID and AUTHORIZE-ID. +If AUTHORIZE-ID is the same as AUTHENTICATE-ID, it may be omitted." + (concat authorize-id "\0" authenticate-id "\0" + (or nonce + (sasl-scram-md5-make-unique-nonce)))) + +(defun sasl-scram-md5-parse-server-msg-1 (server-msg-1) + "Parse SERVER-MSG-1 and return a list of (SALT SECURITY-INFO SERVICE-ID)." + (if (and (> (length server-msg-1) 16) + (eq (string-match "[^@]+@[^\0]+\0" server-msg-1 12) 12)) + (list (substring server-msg-1 0 8) ; salt + (substring server-msg-1 8 12) ; server-security-info + (substring server-msg-1 ; service-id + 12 (1- (match-end 0)))) + (sasl-error (format "Unexpected response: %s" server-msg-1)))) + +(defun sasl-scram-md5-server-salt (server-msg-1) + (car (sasl-scram-md5-parse-server-msg-1 server-msg-1))) + +(defun sasl-scram-md5-make-salted-pass (passphrase salt) + (hmac-md5 salt passphrase)) + +(defun sasl-scram-md5-make-client-key (salted-pass) + (md5-binary salted-pass)) + +(defun sasl-scram-md5-make-client-verifier (client-key) + (md5-binary client-key)) + +(defun sasl-scram-md5-make-shared-key (server-msg-1 + client-msg-1 + client-security-info + client-verifier) + (let (buff) + (unwind-protect + (hmac-md5 + (setq buff + (concat server-msg-1 client-msg-1 client-security-info)) + client-verifier) + (fillarray buff 0)))) + +(defun sasl-scram-md5-make-client-proof (client-key shared-key) + (sasl-scram-md5-xor-string client-key shared-key)) + +(defun sasl-scram-md5-make-client-msg-2 (server-msg-1 + client-msg-1 + salted-pass + client-security-info) + (let (client-proof client-key shared-key client-verifier) + (setq client-key + (sasl-scram-md5-make-client-key salted-pass)) + (setq client-verifier + (sasl-scram-md5-make-client-verifier client-key)) + (setq shared-key + (unwind-protect + (sasl-scram-md5-make-shared-key + server-msg-1 + client-msg-1 + client-security-info + client-verifier) + (fillarray client-verifier 0))) + (setq client-proof + (unwind-protect + (sasl-scram-md5-make-client-proof + client-key shared-key) + (fillarray client-key 0) + (fillarray shared-key 0))) + (unwind-protect + (concat + client-security-info + client-proof) + (fillarray client-proof 0)))) + +(defun sasl-scram-md5-make-server-msg-2 (server-msg-1 + client-msg-1 + client-security-info + salt salted-pass) + (let ((server-salt + (hmac-md5 salt salted-pass)) + buff) + (unwind-protect + (hmac-md5 + (setq buff + (concat + client-msg-1 + server-msg-1 + client-security-info)) + server-salt) + (fillarray server-salt 0) + (fillarray buff 0)))) + +(defun sasl-scram-md5-response-1 (client step) + (sasl-client-set-property + client 'client-msg-1 + (sasl-scram-md5-make-client-msg-1 + (sasl-client-name client) + (sasl-client-property client 'authorize-id) + (sasl-client-property client 'nonce)))) + +(defun sasl-scram-md5-response-2 (client step) + (let* ((server-msg-1 + (sasl-client-set-property + client 'server-msg-1 + (sasl-step-data step))) + (salted-pass + (sasl-client-set-property + client 'salted-pass + (sasl-scram-md5-make-salted-pass + (sasl-read-passphrase + (format "SCRAM-MD5 passphrase for %s: " + (sasl-client-name client))) + (sasl-scram-md5-server-salt server-msg-1))))) + (sasl-client-set-property + client 'client-msg-2 + (sasl-scram-md5-make-client-msg-2 + server-msg-1 + (sasl-client-property client 'client-msg-1) + salted-pass + (or (sasl-client-property client 'client-security-info) + (sasl-scram-md5-make-security-info nil t 0)))))) + +(defun sasl-scram-md5-authenticate-server (client step) + (let ((server-msg-2 + (sasl-client-set-property + client 'server-msg-2 + (sasl-step-data step))) + (server-msg-1 + (sasl-client-property client 'server-msg-1))) + (if (string= server-msg-2 + (sasl-scram-md5-make-server-msg-2 + server-msg-1 + (sasl-client-property client 'client-msg-1) + (or (sasl-client-property client 'client-security-info) + (sasl-scram-md5-make-security-info nil t 0)) + (sasl-scram-md5-server-salt server-msg-1) + (sasl-client-property client 'salted-pass))) + " " + (sasl-error "SCRAM-MD5: authenticate server failed.")))) + +(put 'sasl-scram 'sasl-mechanism + (sasl-make-mechanism "SCRAM-MD5" sasl-scram-md5-steps)) + +(provide 'sasl-scram) + +;;; sasl-scram.el ends here diff --git a/sasl.el b/sasl.el index 8528898..593f46b 100644 --- a/sasl.el +++ b/sasl.el @@ -37,14 +37,17 @@ ;;; Code: (defvar sasl-mechanisms - '("CRAM-MD5" "DIGEST-MD5" "PLAIN" "LOGIN" "ANONYMOUS")) + '("CRAM-MD5" "DIGEST-MD5" "PLAIN" "LOGIN" "ANONYMOUS" + "NTLM" "SCRAM-MD5")) (defvar sasl-mechanism-alist '(("CRAM-MD5" sasl-cram) ("DIGEST-MD5" sasl-digest) ("PLAIN" sasl-plain) ("LOGIN" sasl-login) - ("ANONYMOUS" sasl-anonymous))) + ("ANONYMOUS" sasl-anonymous) + ("NTLM" sasl-ntlm) + ("SCRAM-MD5" sasl-scram))) (defvar sasl-unique-id-function #'sasl-unique-id-function) diff --git a/smtp.el b/smtp.el index 9eca1f8..4706bff 100644 --- a/smtp.el +++ b/smtp.el @@ -58,6 +58,12 @@ called from `smtp-via-smtp' with arguments SENDER and RECIPIENTS." (function :tag "Function")) :group 'smtp) +(defcustom smtp-send-by-myself nil + "If non-nil, smtp.el send a mail by myself without smtp-server. +This option requires \"dig.el\"." + :type 'boolean + :group 'smtp) + (defcustom smtp-service "smtp" "SMTP service port number. \"smtp\" or 25." :type '(choice (integer :tag "25" 25) @@ -91,6 +97,11 @@ don't define this value." :type 'boolean :group 'smtp-extensions) +(defcustom smtp-use-starttls-ignore-error nil + "If non-nil, do not use STARTTLS if STARTTLS is not available." + :type 'boolean + :group 'smtp-extensions) + (defcustom smtp-use-sasl nil "If non-nil, use SMTP Authentication (RFC2554) if available." :type 'boolean @@ -268,6 +279,51 @@ of the host to connect to. SERVICE is name of the service desired." smtp-connection-alist)) connection))) +(eval-and-compile + (autoload 'dig-invoke "dig") + (autoload 'dig-extract-rr "dig")) + +(defun smtp-find-mx (domain &optional doerror) + (let (server) + ;; dig.el resolves only primally MX. + (cond ((setq server (smtp-dig domain "MX")) + (progn (string-match " \\([^ ]*\\)$" server) + (match-string 1 server))) + ((smtp-dig domain "A") + domain) + (t + (if doerror + (error (format "SMTP cannot resolve %s" domain))))))) + +(defun smtp-dig (domain type) + (let (dig-buf) + (set-buffer + (setq dig-buf (dig-invoke domain type))) + (prog1 + (dig-extract-rr domain type) + (kill-buffer dig-buf)))) + +(defun smtp-find-server (recipients) + (save-excursion + (let ((rec + (mapcar (lambda (recipient) + (let (server) + (if (and (string-match "@\\([^\t\n ]*\\)" recipient) + (setq server + (smtp-find-mx + (match-string 1 recipient)))) + (cons server (list recipient)) + (error (format "cannot find server for %s." recipient))))) + recipients)) + ret rets rlist) + (while (setq rets (pop rec)) + (if (setq ret (assoc (car rets) rec)) + (setcdr ret + (append (cdr ret) (cdr rets))) + (setq rlist + (append rlist (list rets))))) + rlist))) + ;;;###autoload (defun smtp-via-smtp (sender recipients buffer) "Like `smtp-send-buffer', but sucks in any errors." @@ -285,27 +341,29 @@ of the host to connect to. SERVICE is name of the service desired." SENDER is an envelope sender address. RECIPIENTS is a list of envelope recipient addresses. BUFFER may be a buffer or a buffer name which contains mail message." - (let ((server - (if (functionp smtp-server) - (funcall smtp-server sender recipients) - smtp-server)) - (package - (smtp-make-package sender recipients buffer)) - (smtp-open-connection-function - (if smtp-use-starttls - #'starttls-open-stream - smtp-open-connection-function))) - (save-excursion - (set-buffer - (get-buffer-create - (format "*trace of SMTP session to %s*" server))) - (erase-buffer) - (buffer-disable-undo) - (unless (smtp-find-connection (current-buffer)) - (smtp-open-connection (current-buffer) server smtp-service)) - (make-local-variable 'smtp-read-point) - (setq smtp-read-point (point-min)) - (funcall smtp-submit-package-function package)))) + (if smtp-send-by-myself + (smtp-send-buffer-by-myself sender recipients buffer) + (let ((server + (if (functionp smtp-server) + (funcall smtp-server sender recipients) + smtp-server)) + (package + (smtp-make-package sender recipients buffer)) + (smtp-open-connection-function + (if smtp-use-starttls + #'starttls-open-stream + smtp-open-connection-function))) + (save-excursion + (set-buffer + (get-buffer-create + (format "*trace of SMTP session to %s*" server))) + (erase-buffer) + (buffer-disable-undo) + (unless (smtp-find-connection (current-buffer)) + (smtp-open-connection (current-buffer) server smtp-service)) + (make-local-variable 'smtp-read-point) + (setq smtp-read-point (point-min)) + (funcall smtp-submit-package-function package))))) (defun smtp-submit-package (package) (unwind-protect @@ -316,9 +374,14 @@ BUFFER may be a buffer or a buffer name which contains mail message." (smtp-response-error (smtp-primitive-helo package))) (if smtp-use-starttls - (progn - (smtp-primitive-starttls package) - (smtp-primitive-ehlo package))) + (if (assq 'starttls + (smtp-connection-extensions-internal + (smtp-find-connection (current-buffer)))) + (progn + (smtp-primitive-starttls package) + (smtp-primitive-ehlo package)) + (unless smtp-use-starttls-ignore-error + (error "STARTTLS is not supported on this server")))) (if smtp-use-sasl (smtp-primitive-auth package)) (smtp-primitive-mailfrom package) @@ -329,6 +392,42 @@ BUFFER may be a buffer or a buffer name which contains mail message." (smtp-primitive-quit package) (smtp-close-connection connection))))) +(defun smtp-send-buffer-by-myself (sender recipients buffer) + "Send a message by myself. +SENDER is an envelope sender address. +RECIPIENTS is a list of envelope recipient addresses. +BUFFER may be a buffer or a buffer name which contains mail message." + (let ((servers + (smtp-find-server recipients)) + (smtp-open-connection-function + (if smtp-use-starttls + #'starttls-open-stream + smtp-open-connection-function)) + server package) + (while (car servers) + (setq server (caar servers)) + (setq recipients (cdar servers)) + (if (not (and server recipients)) + ;; MAILER-DAEMON is required. :) + (error (format "Cannot send <%s>" + (mapconcat 'concat recipients ">,<")))) + (setq package + (smtp-make-package sender recipients buffer)) + (save-excursion + (set-buffer + (get-buffer-create + (format "*trace of SMTP session to %s*" server))) + (erase-buffer) + (buffer-disable-undo) + (unless (smtp-find-connection (current-buffer)) + (smtp-open-connection (current-buffer) server smtp-service)) + (make-local-variable 'smtp-read-point) + (setq smtp-read-point (point-min)) + (let ((smtp-use-sasl nil) + (smtp-use-starttls-ignore-error t)) + (funcall smtp-submit-package-function package))) + (setq servers (cdr servers))))) + ;;; @ hook methods for `smtp-submit-package' ;;; diff --git a/smtpmail.el b/smtpmail.el index dae1378..cdc396c 100644 --- a/smtpmail.el +++ b/smtpmail.el @@ -154,8 +154,12 @@ This is relative to `smtpmail-queue-dir'.") ;;; (insert "Sender: " (user-login-name) "\n"))) ;; Don't send out a blank subject line (goto-char (point-min)) - (if (re-search-forward "^Subject:[ \t]*\n" delimline t) - (replace-match "")) + (if (re-search-forward "^Subject:\\([ \t]*\n\\)+\\b" delimline t) + (replace-match "") + ;; This one matches a Subject just before the header delimiter. + (if (and (re-search-forward "^Subject:\\([ \t]*\n\\)+" delimline t) + (= (match-end 0) delimline)) + (replace-match ""))) ;; Put the "From:" field in unless for some odd reason ;; they put one in themselves. (goto-char (point-min)) diff --git a/std11.el b/std11.el index 4523043..9cef3e2 100644 --- a/std11.el +++ b/std11.el @@ -1,6 +1,6 @@ ;;; std11.el --- STD 11 functions for GNU Emacs -;; Copyright (C) 1995,1996,1997,1998,1999,2000 Free Software Foundation, Inc. +;; Copyright (C) 1995,96,97,98,99,2000,01,02 Free Software Foundation, Inc. ;; Author: MORIOKA Tomohiko ;; Keywords: mail, news, RFC 822, STD 11 @@ -303,6 +303,11 @@ be the result." ) ;; (defconst std11-spaces-regexp ;; (eval-when-compile (concat "[" std11-space-char-list "]+"))) + +(defconst std11-non-atom-regexp + (eval-when-compile + (concat "[" std11-special-char-list std11-space-char-list "]"))) + (defconst std11-atom-regexp (eval-when-compile (concat "[^" std11-special-char-list std11-space-char-list "]+"))) @@ -327,13 +332,21 @@ be the result." )) (defun std11-analyze-atom (string start) - (if (and (string-match std11-atom-regexp string start) - (= (match-beginning 0) start)) - (let ((end (match-end 0))) - (cons (cons 'atom (substring string start end)) - ;;(substring string end) - end) - ))) + (if (string-match std11-non-atom-regexp string start) + (if (> (match-beginning 0) start) + (cons (cons 'atom (substring string start (match-beginning 0))) + (match-beginning 0)) + nil) + (cons (cons 'atom (substring string start)) + (length string))) + ;; (if (and (string-match std11-atom-regexp string start) + ;; (= (match-beginning 0) start)) + ;; (let ((end (match-end 0))) + ;; (cons (cons 'atom (substring string start end)) + ;; ;;(substring string end) + ;; end) + ;; )) + ) (defun std11-check-enclosure (string open close &optional recursive from) (let ((len (length string)) @@ -776,7 +789,7 @@ represents addr-spec of RFC 822." "Return string of address part from parsed ADDRESS of RFC 822." (cond ((eq (car address) 'group) (mapconcat (function std11-address-string) - (car (cdr address)) + (nth 2 address) ", ") ) ((eq (car address) 'mailbox) diff --git a/tests/test-rfc2231.el b/tests/test-rfc2231.el new file mode 100644 index 0000000..62a3b4b --- /dev/null +++ b/tests/test-rfc2231.el @@ -0,0 +1,218 @@ +(require 'lunit) +(require 'mime) + +(luna-define-class test-rfc2231 (lunit-test-case)) + +;;; +;;; Parameter Value Continuations +;;; + +;; The content-type field +;; +;; Content-Type: message/external-body; access-type=URL; +;; URL*0="ftp://"; +;; URL*1="cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar" +;; +;; is semantically identical to +;; +;; Content-Type: message/external-body; access-type=URL; +;; URL="ftp://cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar" +;; +(luna-define-method test-rfc2231-continuation-1 ((case test-rfc2231)) + (lunit-assert + (eq + (mime-content-type-primary-type + (mime-parse-Content-Type "message/external-body; access-type=URL; + URL*0=\"ftp://\"; + URL*1=\"cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar\"")) + (mime-content-type-primary-type + (mime-parse-Content-Type "message/external-body; access-type=URL; + URL=\"ftp://cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar\""))))) + +(luna-define-method test-rfc2231-continuation-2 ((case test-rfc2231)) + (lunit-assert + (eq + (mime-content-type-subtype + (mime-parse-Content-Type "message/external-body; access-type=URL; + URL*0=\"ftp://\"; + URL*1=\"cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar\"")) + (mime-content-type-subtype + (mime-parse-Content-Type "message/external-body; access-type=URL; + URL=\"ftp://cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar\""))))) + +(luna-define-method test-rfc2231-continuation-3 ((case test-rfc2231)) + (lunit-assert + (string= + (mime-content-type-parameter + (mime-parse-Content-Type "message/external-body; access-type=URL; + URL*0=\"ftp://\"; + URL*1=\"cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar\"") + "access-type") + (mime-content-type-parameter + (mime-parse-Content-Type "message/external-body; access-type=URL; + URL=\"ftp://cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar\"") + "access-type")))) + +(luna-define-method test-rfc2231-continuation-4 ((case test-rfc2231)) + (lunit-assert + (string= + (mime-content-type-parameter + (mime-parse-Content-Type "message/external-body; access-type=URL; + URL*0=\"ftp://\"; + URL*1=\"cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar\"") + "url") + (mime-content-type-parameter + (mime-parse-Content-Type "message/external-body; access-type=URL; + URL=\"ftp://cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar\"") + "url")))) + +;;; +;;; Parameter Value Character Set and Language Information +;;; + +;; Content-Type: application/x-stuff; +;; title*=us-ascii'en-us'This%20is%20%2A%2A%2Afun%2A%2A%2A +(luna-define-method test-rfc2231-charset-language-1 ((case test-rfc2231)) + (lunit-assert + (string= + (mime-content-type-parameter + (mime-parse-Content-Type "application/x-stuff; + title*=us-ascii'en-us'This%20is%20%2A%2A%2Afun%2A%2A%2A") + "title") + "This is ***fun***"))) + +(luna-define-method test-rfc2231-charset-language-2 ((case test-rfc2231)) + (lunit-assert + (string= + (mime-content-type-parameter + (mime-parse-Content-Type "application/x-stuff; + title*=''This%20is%20%2A%2A%2Afun%2A%2A%2A") + "title") + "This is ***fun***"))) + +;;; +;;; Combining Character Set, Language, and Parameter Continuations +;;; + +;; Content-Type: application/x-stuff; +;; title*0*=us-ascii'en'This%20is%20even%20more%20; +;; title*1*=%2A%2A%2Afun%2A%2A%2A%20; +;; title*2="isn't it!" +(luna-define-method test-rfc2231-charset-language-continuation-1 ((case test-rfc2231)) + (lunit-assert + (string= + (mime-content-type-parameter + (mime-parse-Content-Type "application/x-stuff; + title*0*=us-ascii'en'This%20is%20even%20more%20; + title*1*=%2A%2A%2Afun%2A%2A%2A%20; + title*2=\"isn't it!\"") + "title") + "This is even more ***fun*** isn't it!"))) + +;; MIME states that parameters are not order sensitive. +(luna-define-method test-rfc2231-charset-language-continuation-2 ((case test-rfc2231)) + (lunit-assert + (string= + (mime-content-type-parameter + (mime-parse-Content-Type "application/x-stuff; + title*2=\"isn't it!\"; + title*1*=%2A%2A%2Afun%2A%2A%2A%20; + title*0*=us-ascii'en'This%20is%20even%20more%20") + "title") + "This is even more ***fun*** isn't it!"))) + +;; ABNF states that `ext-octet' is case-insensitive. +(luna-define-method test-rfc2231-charset-language-continuation-3 ((case test-rfc2231)) + (lunit-assert + (let ((case-fold-search nil)) + (string= + (mime-content-type-parameter + (mime-parse-Content-Type "application/x-stuff; + title*=us-ascii'en-us'This%20is%20%2a%2a%2afun%2a%2a%2a") + "title") + "This is ***fun***")))) + +;; unencoded segments MUST NOT be decoded. +(luna-define-method test-rfc2231-charset-language-continuation-4 ((case test-rfc2231)) + (lunit-assert + (string= + (mime-content-type-parameter + (mime-parse-Content-Type "application/x-stuff; + title*0*=us-ascii'en'This%20is%20even%20more%20; + title*1*=%2A%2A%2Afun%2A%2A%2A%20; + title*2=\"isn%27t%20it!\"") + "title") + "This is even more ***fun*** isn%27t%20it!"))) + +;;; +;;; Language specification in Encoded Words +;;; + +(luna-define-method test-rfc2231-encoded-word-1 ((case test-rfc2231)) + (lunit-assert + (string= + (eword-decode-encoded-word "=?US-ASCII?Q?Keith_Moore?=") + "Keith Moore"))) + +(luna-define-method test-rfc2231-encoded-word-2 ((case test-rfc2231)) + (lunit-assert + (string= + (eword-decode-encoded-word "=?US-ASCII*EN?Q?Keith_Moore?=") + "Keith Moore"))) + +(luna-define-method test-rfc2231-encoded-word-3 ((case test-rfc2231)) + (lunit-assert + (eq + (get-text-property + 0 'mime-language + (eword-decode-encoded-word "=?US-ASCII*EN?Q?Keith_Moore?=")) + 'en))) + +;;; +;;; Language specification in FLIM +;;; + +;; both flim-1_13-rfc2231 and flim-1_14-rfc2231 choose to put language +;; info to the `mime-language' text-property of the parameter value. + +(luna-define-method test-rfc2231-mime-language-1 ((case test-rfc2231)) + (lunit-assert + (eq + (get-text-property + 0 'mime-language + (mime-content-type-parameter + (mime-parse-Content-Type "application/x-stuff; + title*=us-ascii'en-us'This%20is%20%2A%2A%2Afun%2A%2A%2A") + "title")) + 'en-us))) + +(luna-define-method test-rfc2231-mime-language-2 ((case test-rfc2231)) + (lunit-assert + (eq + (get-text-property + 0 'mime-language + (mime-content-type-parameter + (mime-parse-Content-Type "application/x-stuff; + title*=US-ASCII'EN-US'This%20is%20%2A%2A%2Afun%2A%2A%2A") + "title")) + 'en-us))) + +(luna-define-method test-rfc2231-mime-language-3 ((case test-rfc2231)) + (lunit-assert + (null + (get-text-property + 0 'mime-language + (mime-content-type-parameter + (mime-parse-Content-Type "application/x-stuff; + title*=us-ascii''This%20is%20%2A%2A%2Afun%2A%2A%2A") + "title"))))) + +(luna-define-method test-rfc2231-mime-language-4 ((case test-rfc2231)) + (lunit-assert + (null + (get-text-property + 0 'mime-language + (mime-content-type-parameter + (mime-parse-Content-Type "application/x-stuff; + title*=''This%20is%20%2A%2A%2Afun%2A%2A%2A") + "title"))))) diff --git a/tests/test-sasl.el b/tests/test-sasl.el index 07bcaa1..75452ef 100644 --- a/tests/test-sasl.el +++ b/tests/test-sasl.el @@ -58,3 +58,61 @@ algorithm=md5-sess,charset=utf-8") (lunit-assert (string= (plist-get response 'response) "6084c6db3fede7352c551284490fd0fc")))) + +(luna-define-method test-sasl-scram-md5-imap ((case test-sasl)) + (let* ((sasl-mechanisms '("SCRAM-MD5")) + (mechanism + (sasl-find-mechanism '("SCRAM-MD5"))) + (client + (sasl-make-client mechanism "chris" "imap" "eleanor.innosoft.com")) + (sasl-read-passphrase + #'(lambda (prompt) + "secret stuff")) + step + response) + (sasl-client-set-property client 'nonce + "") + (setq step (sasl-next-step client nil)) + (sasl-step-set-data step "") + (setq step (sasl-next-step client step)) + (sasl-step-set-data + step + (base64-decode-string + "dGVzdHNhbHQBAAAAaW1hcEBlbGVhbm9yLmlubm9zb2Z0LmNvbQBqaGNOWmxSdVBiemlGcCt2TFYrTkN3")) + (setq step (sasl-next-step client step)) + (lunit-assert + (string= (sasl-step-data step) + (base64-decode-string "AQAAAMg9jU8CeB4KOfk7sUhSQPs="))))) + +(luna-define-method test-sasl-ntlm-imap ((case test-sasl)) + (let* ((sasl-mechanisms '("NTLM")) + (mechanism + (sasl-find-mechanism '("NTLM"))) + (client + (sasl-make-client mechanism "kawagish@nokiaseap" "imap" "xxx.yyy.com")) + (sasl-read-passphrase + #'(lambda (passphrase) + "!\"#456secret")) + step + response) + ;; init + (setq step (sasl-next-step client nil)) + ;; generate authentication request + (sasl-step-set-data step "") + (setq step (sasl-next-step client step)) + (sasl-step-data step) + ;; (base64-encode-string (sasl-step-data step) t) is sent to server + ;; generate response to challenge + (sasl-step-set-data + step + (string-as-unibyte + (base64-decode-string + "TlRMTVNTUAACAAAADAAMADAAAAAFggEApmEjGvh9M8YAAAAAAAAAAAAAAAA8AAAATgBPAEsARQBYAEMA"))) + (setq step (sasl-next-step client step)) + (sasl-step-data step) + (setq response (base64-encode-string (sasl-step-data step) t)) + (lunit-assert + (string= + response "TlRMTVNTUAADAAAAGAAYAEAAAAAYABgAWAAAABIAEgBwAAAAEAAQAIIAAAAQABAAkgAAAAAAAABiAAAABYIBAIwN9i7qK/9Y31dIDR6JQTaBbjcLJm8Sc6VogMe7fnHP96+eQ5Yf3ys2nIY4rx+iQG4AbwBrAGkAYQBzAGUAYQBwAGsAYQB3AGEAZwBpAHMAaABrAGEAdwBhAGcAaQBzAGgA")) +;;response +)) -- 1.7.10.4