diff options
author | Mark A. Hershberger <mah@everybody.org> | 2010-06-22 12:48:53 -0400 |
---|---|---|
committer | Mark A. Hershberger <mah@everybody.org> | 2010-06-22 12:48:53 -0400 |
commit | 04c23739823fecd98cbc06ad627b36e5bd8e482e (patch) | |
tree | 743c052ea388d68d0ed259cf1e4fee7c94b6fbbe /lisp/gnus/mm-url.el | |
parent | bc869eca8c91810c66ead464b57630ccebabaf29 (diff) | |
download | emacs-04c23739823fecd98cbc06ad627b36e5bd8e482e.tar.gz |
Add in some useful convenience functions for handling HTTP.
Diffstat (limited to 'lisp/gnus/mm-url.el')
-rw-r--r-- | lisp/gnus/mm-url.el | 42 |
1 files changed, 42 insertions, 0 deletions
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) |