55502f40dc8b7c769880b10874abc9d0

I would like to use header-encode without needing to squeeze out the whitespace, as in better-mail-headers

(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 !

D41d8cd98f00b204e9800998ecf8427e

Aaron

October 2, 2007, October 02, 2007 12:10, permalink

1 rating. Login to rate!

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/

(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))
55502f40dc8b7c769880b10874abc9d0

luser.myopenid.com/

October 3, 2007, October 03, 2007 09:01, permalink

No rating. Login to rate!

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.

Your refactoring





Format Copy from initial code

or Cancel