Browse code
SSL now uses cl+ssl
Alexander Artemenko authored on 15/09/2018 16:49:47
Showing 1 changed files
Showing 1 changed files
... | ... |
@@ -293,28 +293,36 @@ |
293 | 293 |
;; keyword identifying the error (or :unknown) |
294 | 294 |
:reader po-condition-identifier |
295 | 295 |
:initform :unknown |
296 |
- :initarg :identifier |
|
297 |
- ) |
|
296 |
+ :initarg :identifier) |
|
298 | 297 |
(server-string |
299 | 298 |
;; message from the imap server |
300 | 299 |
:reader po-condition-server-string |
301 | 300 |
:initform "" |
302 |
- :initarg :server-string |
|
303 |
- )) |
|
301 |
+ :initarg :server-string) |
|
302 |
+ (message |
|
303 |
+ :reader po-condition-message |
|
304 |
+ :initform "" |
|
305 |
+ :initarg :message) |
|
306 |
+ (arguments |
|
307 |
+ :reader po-condition-arguments |
|
308 |
+ :initform nil |
|
309 |
+ :initarg :arguments)) |
|
310 |
+ |
|
304 | 311 |
(:report |
305 | 312 |
(lambda (con stream) |
306 | 313 |
(with-slots (identifier server-string) con |
307 | 314 |
;; a condition either has a server-string or it has a |
308 | 315 |
;; format-control string |
309 | 316 |
(format stream "Post Office condition: ~s~%" identifier) |
310 |
- (if* (and (excl::simple-condition-format-control con)) |
|
311 |
- then (apply #'format stream |
|
312 |
- (excl::simple-condition-format-control con) |
|
313 |
- (excl::simple-condition-format-arguments con))) |
|
314 |
- (if* server-string |
|
315 |
- then (format stream |
|
316 |
- "~&Message from server: ~s" |
|
317 |
- (string-left-trim " " server-string))))))) |
|
317 |
+ (unless (string= (po-condition-message con) |
|
318 |
+ "") |
|
319 |
+ (apply #'format stream |
|
320 |
+ (po-condition-message con) |
|
321 |
+ (po-condition-arguments con))) |
|
322 |
+ (when server-string |
|
323 |
+ (format stream |
|
324 |
+ "~&Message from server: ~s" |
|
325 |
+ (string-left-trim " " server-string))))))) |
|
318 | 326 |
|
319 | 327 |
|
320 | 328 |
|
... | ... |
@@ -331,17 +339,16 @@ |
331 | 339 |
(signal (make-instance 'po-condition |
332 | 340 |
:identifier identifier |
333 | 341 |
:server-string server-string |
334 |
- :format-control format-control |
|
335 |
- :format-arguments format-arguments |
|
336 |
- ))) |
|
342 |
+ :message format-control |
|
343 |
+ :arguments format-arguments))) |
|
337 | 344 |
|
338 | 345 |
(defun po-error (identifier &key server-string |
339 | 346 |
format-control format-arguments) |
340 | 347 |
(error (make-instance 'po-error |
341 | 348 |
:identifier identifier |
342 | 349 |
:server-string server-string |
343 |
- :format-control format-control |
|
344 |
- :format-arguments format-arguments))) |
|
350 |
+ :message format-control |
|
351 |
+ :arguments format-arguments))) |
|
345 | 352 |
|
346 | 353 |
|
347 | 354 |
|
... | ... |
@@ -372,12 +379,16 @@ |
372 | 379 |
(ssl-args (cdr server-info)) |
373 | 380 |
ssl port starttls sock) |
374 | 381 |
(setq ssl (pop-keyword :ssl ssl-args)) |
375 |
- (setq port (or (pop-keyword :port ssl-args) (server-port ssl server-type))) |
|
382 |
+ (setq port (or (pop-keyword :port ssl-args) |
|
383 |
+ (server-port ssl server-type))) |
|
376 | 384 |
(setq starttls (pop-keyword :starttls ssl-args)) |
377 | 385 |
(setq sock (socket:make-socket :remote-host server |
378 | 386 |
:remote-port port)) |
379 | 387 |
(when ssl |
380 |
- (setq sock (apply #'socket:make-ssl-client-stream sock ssl-args))) |
|
388 |
+ (setq sock (apply #'cl+ssl:make-ssl-client-stream |
|
389 |
+ sock |
|
390 |
+ :external-format :iso-8859-1 |
|
391 |
+ ssl-args))) |
|
381 | 392 |
|
382 | 393 |
(values sock starttls))) ) |
383 | 394 |
|
... | ... |
@@ -533,22 +544,23 @@ |
533 | 544 |
"~a ~a~a" tag command *crlf*) |
534 | 545 |
(force-output (post-office-socket mb)) |
535 | 546 |
|
536 |
- (if* *debug-imap* |
|
537 |
- then (format t |
|
538 |
- "~a ~a~a" tag command *crlf*) |
|
539 |
- (force-output)) |
|
547 |
+ (when *debug-imap* |
|
548 |
+ (format t |
|
549 |
+ "~a ~a~a" tag command *crlf*) |
|
550 |
+ (force-output)) |
|
551 |
+ |
|
540 | 552 |
(loop |
541 |
- (multiple-value-bind (got-tag cmd count extra comment) |
|
542 |
- (get-and-parse-from-imap-server mb) |
|
543 |
- (if* (eq got-tag :untagged) |
|
544 |
- then (funcall untagged-handler mb cmd count extra comment) |
|
545 |
- elseif (equal tag got-tag) |
|
546 |
- then (funcall tagged-handler mb cmd count extra comment) |
|
547 |
- (return) |
|
548 |
- else (po-error :error-response |
|
549 |
- :format-control "received tag ~s out of order" |
|
550 |
- :format-arguments (list got-tag) |
|
551 |
- :server-string comment)))))) |
|
553 |
+ (multiple-value-bind (got-tag cmd count extra comment) |
|
554 |
+ (get-and-parse-from-imap-server mb) |
|
555 |
+ (if* (eq got-tag :untagged) |
|
556 |
+ then (funcall untagged-handler mb cmd count extra comment) |
|
557 |
+ elseif (equal tag got-tag) |
|
558 |
+ then (funcall tagged-handler mb cmd count extra comment) |
|
559 |
+ (return) |
|
560 |
+ else (po-error :error-response |
|
561 |
+ :format-control "received tag ~s out of order" |
|
562 |
+ :format-arguments (list got-tag) |
|
563 |
+ :server-string comment)))))) |
|
552 | 564 |
|
553 | 565 |
|
554 | 566 |
(defun get-next-tag () |
... | ... |
@@ -1945,6 +1957,7 @@ |
1945 | 1957 |
;; The character count includes up to but excluding the cr lf that |
1946 | 1958 |
;; was read from the socket. |
1947 | 1959 |
;; |
1960 |
+ ;; TODO: make it able to read from ssl socket |
|
1948 | 1961 |
(let* ((buff (get-line-buffer 0)) |
1949 | 1962 |
(len (length buff)) |
1950 | 1963 |
(i 0) |
... | ... |
@@ -1969,87 +1982,87 @@ |
1969 | 1982 |
;; with-timeout form to expire. |
1970 | 1983 |
(loop |
1971 | 1984 |
|
1972 |
- (if* whole-count |
|
1973 |
- then ; we should now read in this may bytes and |
|
1974 |
- ; append it to this buffer |
|
1975 |
- (multiple-value-bind (ans this-count) |
|
1976 |
- (get-block-of-data-from-server mailbox whole-count) |
|
1977 |
- ; now put this data in the current buffer |
|
1978 |
- (if* (> (+ i whole-count 5) len) |
|
1979 |
- then ; grow the initial buffer |
|
1980 |
- (grow-buffer (+ i whole-count 100))) |
|
1981 |
- |
|
1982 |
- (dotimes (ind this-count) |
|
1983 |
- (setf (schar buff i) (schar ans ind)) |
|
1984 |
- (incf i)) |
|
1985 |
- (setf (schar buff i) #\^b) ; end of inset string |
|
1986 |
- (incf i) |
|
1987 |
- (free-line-buffer ans) |
|
1988 |
- (setq whole-count nil) |
|
1989 |
- ) |
|
1990 |
- elseif ch |
|
1991 |
- then ; we're growing the buffer holding the line data |
|
1992 |
- (grow-buffer (+ len 200)) |
|
1993 |
- (setf (schar buff i) ch) |
|
1994 |
- (incf i)) |
|
1995 |
- |
|
1996 |
- |
|
1997 |
- (block timeout |
|
1998 |
- (mp:with-timeout ((timeout mailbox) |
|
1999 |
- (po-error :timeout |
|
2000 |
- :format-control "imap server failed to respond")) |
|
2001 |
- ;; read up to lf (lf most likely preceeded by cr) |
|
2002 |
- (loop |
|
2003 |
- (setq ch (read-char p)) |
|
2004 |
- (if* (eq #\linefeed ch) |
|
2005 |
- then ; end of line. Don't save the return |
|
2006 |
- (if* (and (> i 0) |
|
2007 |
- (eq (schar buff (1- i)) #\return)) |
|
2008 |
- then ; remove #\return, replace with newline |
|
2009 |
- (decf i) |
|
2010 |
- (setf (schar buff i) #\newline) |
|
2011 |
- ) |
|
2012 |
- ;; must check for an extended return value which |
|
2013 |
- ;; is indicated by a {nnn} at the end of the line |
|
2014 |
- (block count-check |
|
2015 |
- (let ((ind (1- i))) |
|
2016 |
- (if* (and (>= i 0) (eq (schar buff ind) #\})) |
|
2017 |
- then (let ((count 0) |
|
2018 |
- (mult 1)) |
|
2019 |
- (loop |
|
2020 |
- (decf ind) |
|
2021 |
- (if* (< ind 0) |
|
2022 |
- then ; no of the form {nnn} |
|
2023 |
- (return-from count-check)) |
|
2024 |
- (setf ch (schar buff ind)) |
|
2025 |
- (if* (eq ch #\{) |
|
2026 |
- then ; must now read that many bytes |
|
2027 |
- (setf (schar buff ind) #\^b) |
|
2028 |
- (setq whole-count count) |
|
2029 |
- (setq i (1+ ind)) |
|
2030 |
- (return-from timeout) |
|
2031 |
- elseif (<= #.(char-code #\0) |
|
2032 |
- (char-code ch) |
|
2033 |
- #.(char-code #\9)) |
|
2034 |
- then ; is a digit |
|
2035 |
- (setq count |
|
2036 |
- (+ count |
|
2037 |
- (* mult |
|
2038 |
- (- (char-code ch) |
|
2039 |
- #.(char-code #\0))))) |
|
2040 |
- (setq mult (* 10 mult)) |
|
2041 |
- else ; invalid form, get out |
|
2042 |
- (return-from count-check))))))) |
|
2043 |
- |
|
2044 |
- |
|
2045 |
- (return-from get-line-from-server |
|
2046 |
- (values buff i)) |
|
2047 |
- else ; save character |
|
2048 |
- (if* (>= i len) |
|
2049 |
- then ; need bigger buffer |
|
2050 |
- (return)) |
|
2051 |
- (setf (schar buff i) ch) |
|
2052 |
- (incf i))))))) |
|
1985 |
+ (if* whole-count |
|
1986 |
+ then ; we should now read in this may bytes and |
|
1987 |
+ ; append it to this buffer |
|
1988 |
+ (multiple-value-bind (ans this-count) |
|
1989 |
+ (get-block-of-data-from-server mailbox whole-count) |
|
1990 |
+ ; now put this data in the current buffer |
|
1991 |
+ (if* (> (+ i whole-count 5) len) |
|
1992 |
+ then ; grow the initial buffer |
|
1993 |
+ (grow-buffer (+ i whole-count 100))) |
|
1994 |
+ |
|
1995 |
+ (dotimes (ind this-count) |
|
1996 |
+ (setf (schar buff i) (schar ans ind)) |
|
1997 |
+ (incf i)) |
|
1998 |
+ (setf (schar buff i) #\^b) ; end of inset string |
|
1999 |
+ (incf i) |
|
2000 |
+ (free-line-buffer ans) |
|
2001 |
+ (setq whole-count nil) |
|
2002 |
+ ) |
|
2003 |
+ elseif ch |
|
2004 |
+ then ; we're growing the buffer holding the line data |
|
2005 |
+ (grow-buffer (+ len 200)) |
|
2006 |
+ (setf (schar buff i) ch) |
|
2007 |
+ (incf i)) |
|
2008 |
+ |
|
2009 |
+ |
|
2010 |
+ (block timeout |
|
2011 |
+ (mp:with-timeout ((timeout mailbox) |
|
2012 |
+ (po-error :timeout |
|
2013 |
+ :format-control "imap server failed to respond")) |
|
2014 |
+ ;; read up to lf (lf most likely preceeded by cr) |
|
2015 |
+ (loop |
|
2016 |
+ (setq ch (read-char p)) |
|
2017 |
+ (if* (eq #\linefeed ch) |
|
2018 |
+ then ; end of line. Don't save the return |
|
2019 |
+ (if* (and (> i 0) |
|
2020 |
+ (eq (schar buff (1- i)) #\return)) |
|
2021 |
+ then ; remove #\return, replace with newline |
|
2022 |
+ (decf i) |
|
2023 |
+ (setf (schar buff i) #\newline) |
|
2024 |
+ ) |
|
2025 |
+ ;; must check for an extended return value which |
|
2026 |
+ ;; is indicated by a {nnn} at the end of the line |
|
2027 |
+ (block count-check |
|
2028 |
+ (let ((ind (1- i))) |
|
2029 |
+ (if* (and (>= i 0) (eq (schar buff ind) #\})) |
|
2030 |
+ then (let ((count 0) |
|
2031 |
+ (mult 1)) |
|
2032 |
+ (loop |
|
2033 |
+ (decf ind) |
|
2034 |
+ (if* (< ind 0) |
|
2035 |
+ then ; no of the form {nnn} |
|
2036 |
+ (return-from count-check)) |
|
2037 |
+ (setf ch (schar buff ind)) |
|
2038 |
+ (if* (eq ch #\{) |
|
2039 |
+ then ; must now read that many bytes |
|
2040 |
+ (setf (schar buff ind) #\^b) |
|
2041 |
+ (setq whole-count count) |
|
2042 |
+ (setq i (1+ ind)) |
|
2043 |
+ (return-from timeout) |
|
2044 |
+ elseif (<= #.(char-code #\0) |
|
2045 |
+ (char-code ch) |
|
2046 |
+ #.(char-code #\9)) |
|
2047 |
+ then ; is a digit |
|
2048 |
+ (setq count |
|
2049 |
+ (+ count |
|
2050 |
+ (* mult |
|
2051 |
+ (- (char-code ch) |
|
2052 |
+ #.(char-code #\0))))) |
|
2053 |
+ (setq mult (* 10 mult)) |
|
2054 |
+ else ; invalid form, get out |
|
2055 |
+ (return-from count-check))))))) |
|
2056 |
+ |
|
2057 |
+ |
|
2058 |
+ (return-from get-line-from-server |
|
2059 |
+ (values buff i)) |
|
2060 |
+ else ; save character |
|
2061 |
+ (if* (>= i len) |
|
2062 |
+ then ; need bigger buffer |
|
2063 |
+ (return)) |
|
2064 |
+ (setf (schar buff i) ch) |
|
2065 |
+ (incf i))))))) |
|
2053 | 2066 |
(error (con) |
2054 | 2067 |
;; most likely error is that the server went away |
2055 | 2068 |
(ignore-errors (close p)) |