diff options
author | Kenjiro NAKAYAMA <nakayamakenjiro@gmail.com> | 2014-11-10 22:33:55 +0100 |
---|---|---|
committer | Lars Magne Ingebrigtsen <larsi@gnus.org> | 2014-11-10 22:33:55 +0100 |
commit | fca2f70380dcb054497470aaf8eda6173063928e (patch) | |
tree | af195d71b9833dc0e47488aa7402bd541330cad0 /lisp/gnus/mm-url.el | |
parent | 14fe3679c9b26b29872525c85f3278ecb50c8eac (diff) | |
download | emacs-fca2f70380dcb054497470aaf8eda6173063928e.tar.gz |
Allow uploading files from eww
2014-11-10 Kenjiro NAKAYAMA <nakayamakenjiro@gmail.com>
* net/eww.el(eww-form-file(defface)): New defface of file upload form.
(eww-submit-file): New key map of file upload.
(eww-form-file): New file upload button and file name context.
(eww-select-file): Select file and display selected file name.
(eww-tag-input): Handle input tag of file type.
(eww-update-field): Add point offset.
(eww-submit): Add submit with multipart/form-data.
* gnus/mm-url.el (mm-url-encode-multipart-form-data):
Restore to handle "multipart/form-data" by eww.
Diffstat (limited to 'lisp/gnus/mm-url.el')
-rw-r--r-- | lisp/gnus/mm-url.el | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/lisp/gnus/mm-url.el b/lisp/gnus/mm-url.el index bb342d6b8b1..bbeb1d85374 100644 --- a/lisp/gnus/mm-url.el +++ b/lisp/gnus/mm-url.el @@ -414,13 +414,51 @@ spaces. Die Die Die." (autoload 'mml-compute-boundary "mml") +(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) + (cond ((equal (car data) "file") + ;; For each pair + (format + ;; Encode the name + "Content-Disposition: form-data; name=%S; filename=%S\r\nContent-Type: text/plain; charset=utf-8\r\nContent-Transfer-Encoding: binary\r\n\r\n%s" + (cdr (assoc "name" (cdr data))) (cdr (assoc "filename" (cdr data))) + (cond ((stringp (cdr (assoc "filedata" (cdr data)))) + (cdr (assoc "filedata" (cdr data)))) + ((integerp (cdr (assoc "filedata" (cdr data)))) + (number-to-string (cdr (assoc "filedata" (cdr data)))))))) + ((equal (car data) "submit") + "Content-Disposition: form-data; name=\"submit\"\r\n\r\nSubmit\r\n") + (t + (format + "Content-Disposition: form-data;name=%S\r\n\r\n%s\r\n" + (car data) (concat (mm-url-form-encode-xwfu (cdr data))) + )))) + pairs)) + ;; use the boundary as a separator + (concat "\r\n--" boundary "\r\n")) + ;; put a boundary at the end. + "--" boundary "--\r\n")) + (defun mm-url-remove-markup () "Remove all HTML markup, leaving just plain text." (goto-char (point-min)) (while (search-forward "<!--" nil t) (delete-region (match-beginning 0) - (or (search-forward "-->" nil t) - (point-max)))) + (or (search-forward "-->" nil t) + (point-max)))) (goto-char (point-min)) (while (re-search-forward "<[^>]+>" nil t) (replace-match "" t t))) |