git.fiddlerwoaroof.com
Browse code

2006-02-03 Ahmon Dancy <dancy@dancy>

layer authored on 03/02/2006 23:25:17
Showing 3 changed files
... ...
@@ -1,3 +1,12 @@
1
+2006-02-03  Ahmon Dancy  <dancy@dancy>
2
+
3
+	* imap-api.cl: Export mime-part-constructed class.  
4
+
5
+	* smtp.cl: send-letter: Avoid modifying user-provided mime-part
6
+	(if provided).  It will still be modified if the user provides an
7
+	attachments as well (which is a semi-strange thing to do), but the
8
+	change will be reverted after the operation is complete.
9
+
1 10
 2006-02-02  Kevin Layer  <layer@gemini>
2 11
 
3 12
 	* smtp.cl: add defpatch for 7.0
... ...
@@ -10,7 +10,7 @@
10 10
   :type :system
11 11
   :post-loadable t)
12 12
 
13
-;; $Id: mime-api.cl,v 1.1 2006/02/02 17:46:01 layer Exp $
13
+;; $Id: mime-api.cl,v 1.2 2006/02/03 23:25:17 layer Exp $
14 14
 
15 15
 (defpackage :net.post-office
16 16
   (:use #:lisp #:excl)
... ...
@@ -24,6 +24,9 @@
24 24
    ;; macros
25 25
    #:mime-get-header
26 26
    #:with-mime-part-constructed-stream
27
+
28
+   ;; classes
29
+   #:mime-part-constructed
27 30
    
28 31
    ;; slot accessors
29 32
    #:mime-part-type
... ...
@@ -36,7 +36,7 @@
36 36
 ;; Suite 330, Boston, MA  02111-1307  USA
37 37
 ;;
38 38
 ;;
39
-;; $Id: smtp.cl,v 1.14 2006/02/03 18:02:26 layer Exp $
39
+;; $Id: smtp.cl,v 1.15 2006/02/03 23:25:17 layer Exp $
40 40
 
41 41
 ;; Description:
42 42
 ;;   send mail to an smtp server.  See rfc821 for the spec.
... ...
@@ -150,7 +150,8 @@ message must be a string, stream, or mime-part-constructed, not ~s" message))))
150 150
 		 then (make-mime-part :subparts (list part))
151 151
 		 else part))))
152 152
   
153
-  (let ((user-header "")
153
+  (let ((hdrs nil)
154
+	(user-headers "")
154 155
 	(tos (if* (stringp to) 
155 156
 		then (list to) 
156 157
 	      elseif (consp to)
... ...
@@ -172,20 +173,26 @@ message must be a string, stream, or mime-part-constructed, not ~s" message))))
172 173
 		 then bcc
173 174
 		 else (error "bcc should be a string or list, not ~s" bcc))))
174 175
     
175
-    (push (cons "From" from) (mime-part-headers message))
176
-    (push (cons "To" (list-to-delimited-string tos ", ")) 
177
-	  (mime-part-headers message))
178
-    
179
-    (if* ccs 
180
-       then 
181
-	    (push (cons "Cc" (list-to-delimited-string ccs ", ")) 
182
-		  (mime-part-headers message)))
183
-    
184
-    (if* subject
185
-       then (push (cons "Subject" subject) (mime-part-headers message)))
186
-    
187
-    (if* reply-to
188
-       then (push (cons "Reply-To" reply-to) (mime-part-headers message)))
176
+    (setf hdrs
177
+      (with-output-to-string (hdrs)
178
+	(macrolet ((already-have (name) 
179
+		     `(mime-get-header ,name message)))
180
+	  
181
+	  ;; Give priority to headers already provided in a mime-part.
182
+	  (if* (not (already-have "From"))
183
+	     then (format hdrs "From: ~a~%" from))
184
+	
185
+	  (if* (not (already-have "To"))
186
+	     then (format hdrs "To: ~a~%" (list-to-delimited-string tos ", ")))
187
+	
188
+	  (if* (and ccs (not (already-have "Cc")))
189
+	     then (format hdrs "Cc: ~a~%" (list-to-delimited-string ccs ", ")))
190
+	
191
+	  (if* (and subject (not (already-have "Subject")))
192
+	     then (format hdrs "Subject: ~a~%" subject))
193
+	
194
+	  (if* (and reply-to (not (already-have "Reply-To")))
195
+	     then (format hdrs "Reply-To: ~a~%" reply-to)))))
189 196
     
190 197
     (if* headers
191 198
        then (if* (stringp headers)
... ...
@@ -193,31 +200,40 @@ message must be a string, stream, or mime-part-constructed, not ~s" message))))
193 200
 	     elseif (consp headers)
194 201
 	       thenret
195 202
 	       else (error "Unknown headers format: ~s." headers))
196
-	    (setf user-header 
203
+	    (setf user-headers
197 204
 	      (with-output-to-string (header)
198 205
 		(dolist (h headers) 
199 206
 		  (format header "~a~%" h)))))
200 207
 
201
-    (if* attachments
202
-       then (if (not (consp attachments))
203
-		(setf attachments (list attachments)))
208
+    ;; Temporarily modifies 'message', which may be user-provided.
209
+    (let ((parts-save (mime-part-parts message)))
210
+      (if* attachments
211
+	 then (if (not (consp attachments))
212
+		  (setf attachments (list attachments)))
204 213
 	    
205
-	    (dolist (attachment attachments)
206
-	      (if* (mime-part-constructed-p attachment)
207
-		 thenret
208
-	       elseif (or (streamp attachment) (stringp attachment)
209
-			  (pathnamep attachment))
210
-		 then (setf attachment (make-mime-part :file attachment))
211
-		 else (error "~
214
+	      (let (res)
215
+		(dolist (attachment attachments)
216
+		  (if* (mime-part-constructed-p attachment)
217
+		     thenret
218
+		   elseif (or (streamp attachment) (stringp attachment)
219
+			      (pathnamep attachment))
220
+		     then (setf attachment (make-mime-part :file attachment))
221
+		     else (error "~
212 222
 Attachments must be filenames, streams, or mime-part-constructed, not ~s"
213
-			     attachment))
214
-	      (nconc (mime-part-parts message) (list attachment))))
215
-    
216
-    (with-mime-part-constructed-stream (s message)
217
-      (send-smtp-auth server from (append tos ccs bccs)
218
-		      login password
219
-		      user-header
220
-		      s))))
223
+				 attachment))
224
+		  (push attachment res))
225
+	      
226
+		(setf (mime-part-parts message) (append parts-save res))))
227
+      
228
+      (with-mime-part-constructed-stream (s message)
229
+	(send-smtp-auth server from (append tos ccs bccs)
230
+			login password
231
+			hdrs
232
+			user-headers
233
+			s))
234
+      
235
+      (setf (mime-part-parts message) parts-save)
236
+      t)))
221 237
     
222 238
     
223 239
 (defun send-smtp (server from to &rest messages)