summaryrefslogtreecommitdiff
path: root/lisp/gnus
diff options
context:
space:
mode:
authorMark A. Hershberger <mah@everybody.org>2010-06-22 12:48:53 -0400
committerMark A. Hershberger <mah@everybody.org>2010-06-22 12:48:53 -0400
commit04c23739823fecd98cbc06ad627b36e5bd8e482e (patch)
tree743c052ea388d68d0ed259cf1e4fee7c94b6fbbe /lisp/gnus
parentbc869eca8c91810c66ead464b57630ccebabaf29 (diff)
downloademacs-04c23739823fecd98cbc06ad627b36e5bd8e482e.tar.gz
Add in some useful convenience functions for handling HTTP.
Diffstat (limited to 'lisp/gnus')
-rw-r--r--lisp/gnus/ChangeLog5
-rw-r--r--lisp/gnus/mm-url.el42
2 files changed, 47 insertions, 0 deletions
diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog
index e50bdb58575..d25caf70347 100644
--- a/lisp/gnus/ChangeLog
+++ b/lisp/gnus/ChangeLog
@@ -1,3 +1,8 @@
+2010-06-22 Mark A. Hershberger <mah@everybody.org>
+
+ * mm-url.el (mm-url-encode-multipart-form-data): New function to handle
+ the *other* type of HTML form submission.
+
2010-06-15 Michael Albinus <michael.albinus@gmx.de>
* auth-source.el (auth-source-pick): If choice does not contain a
diff --git a/lisp/gnus/mm-url.el b/lisp/gnus/mm-url.el
index c5a8d9f7fdc..c72f520d60a 100644
--- a/lisp/gnus/mm-url.el
+++ b/lisp/gnus/mm-url.el
@@ -418,6 +418,48 @@ spaces. Die Die Die."
(mm-url-form-encode-xwfu (cdr data))))
pairs "&"))
+(defun mm-url-encode-multipart-form-data (pairs &optional boundary)
+ "Return PAIRS encoded in multipart/form-data."
+ ;; RFC1867
+
+ ;; Get a good boundary
+ (unless boundary
+ (setq boundary (mml-compute-boundary '())))
+
+ (concat
+
+ ;; Start with the boundary
+ "--" boundary "\r\n"
+
+ ;; Create name value pairs
+ (mapconcat
+ 'identity
+ ;; Delete any returned items that are empty
+ (delq nil
+ (mapcar (lambda (data)
+ (when (car data)
+ ;; For each pair
+ (concat
+
+ ;; Encode the name
+ "Content-Disposition: form-data; name=\""
+ (car data) "\"\r\n"
+ "Content-Type: text/plain; charset=utf-8\r\n"
+ "Content-Transfer-Encoding: binary\r\n\r\n"
+
+ (cond ((stringp (cdr data))
+ (cdr data))
+ ((integerp (cdr data))
+ (int-to-string (cdr data))))
+
+ "\r\n")))
+ pairs))
+ ;; use the boundary as a separator
+ (concat "--" boundary "\r\n"))
+
+ ;; put a boundary at the end.
+ "--" boundary "--\r\n"))
+
(defun mm-url-fetch-form (url pairs)
"Fetch a form from URL with PAIRS as the data using the POST method."
(mm-url-load-url)