1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
(defun header-encode (string) (if (find-if (lambda (c) (> (char-code c) 127)) string) (format nil "~{ =?utf-8?B?~A?=~%~}" (cl-ppcre:split #\Newline (cl-base64:usb8-array-to-base64-string (portable-string-to-octets string) :columns 40))) (format nil " ~A~%" string))) (defun mail-headers (to from subject mime-type) (format nil "To: ~A From: ~A Subject:~AContent-Type: ~A;charset=utf-8 " to from (header-encode subject) mime-type)) (defun better-mail-headers (to from subject mime-type) (format nil "To: ~A From: ~A Subject: ~A Content-Type: ~A;charset=utf-8 " to from (header-encode subject) mime-type))
Refactorings
No refactoring yet !
Aaron
October 2, 2007, October 02, 2007 12:10, permalink
Is this what you want? I have to warn you, it's not tested with the full code. I had to look it up here:
http://cybertiggyr.com/gene/fmt/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
(defun header-encode (string) (if (find-if (lambda (c) (> (char-code c) 127)) string) (format nil "~{=?utf-8?B?~A?=~#[~:;~% ~]~}" (cl-ppcre:split #\Newline (cl-base64:usb8-array-to-base64-string (portable-string-to-octets string) :columns 40))) (format nil " ~A~%" string))) (defun mail-headers (to from subject mime-type) (format nil "To: ~A From: ~A Subject:~AContent-Type: ~A;charset=utf-8 " to from (header-encode subject) mime-type)) (defun better-mail-headers (to from subject mime-type) (format nil "To: ~A From: ~A Subject: ~A Content-Type: ~A;charset=utf-8 " to from (header-encode subject) mime-type))
luser.myopenid.com/
October 3, 2007, October 03, 2007 09:01, permalink
YES! Although "~^~% " seems to be more straightforward in this case.
~^... means unconditionally print ... until there are no more elements remaining to be printed
~#[~:;...~] means print an empty string when the number of elements remaining is 0, and ... otherwise.
I would like to use header-encode without needing to squeeze out the whitespace, as in better-mail-headers