- (setq c (char-after)))))
- ;; See if we have any previous continuations.
- (when (and prev-attribute
- (not (eq prev-attribute attribute)))
- (push (cons prev-attribute prev-value) parameters)
- (setq prev-attribute nil
- prev-value ""))
- (unless (eq c ?=)
- (error "Invalid header: %s" string))
- (forward-char 1)
- (setq c (char-after))
- (cond
- ((eq c ?\")
- (setq value
- (buffer-substring (1+ (point))
- (progn (forward-sexp 1) (1- (point))))))
- ((and (memq c ttoken)
- (not (memq c stoken)))
- (setq value (buffer-substring
- (point) (progn (forward-sexp 1) (point)))))
- (t
- (error "Invalid header: %s" string)))
- (when encoded
- (setq value (rfc2231-decode-encoded-string value)))
- (if number
- (setq prev-attribute attribute
- prev-value (concat prev-value value))
- (push (cons attribute value) parameters)))
-
- ;; Take care of any final continuations.
- (when prev-attribute
- (push (cons prev-attribute prev-value) parameters))
-
- (when type
- `(,type ,@(nreverse parameters)))))))
+ ;; If c in nil, then this is an invalid header, but
+ ;; since elm generates invalid headers on this form,
+ ;; we allow it.
+ (when (setq c (char-after))
+ (if (and (memq c ttoken)
+ (not (memq c stoken)))
+ (setq attribute
+ (intern
+ (downcase
+ (buffer-substring
+ (point) (progn (forward-sexp 1) (point))))))
+ (error "Invalid header: %s" string))
+ (setq c (char-after))
+ (if (eq c ?*)
+ (progn
+ (forward-char 1)
+ (setq c (char-after))
+ (if (not (memq c ntoken))
+ (setq encoded t
+ number nil)
+ (setq number
+ (string-to-number
+ (buffer-substring
+ (point) (progn (forward-sexp 1) (point)))))
+ (setq c (char-after))
+ (when (eq c ?*)
+ (setq encoded t)
+ (forward-char 1)
+ (setq c (char-after)))))
+ (setq number nil
+ encoded nil))
+ ;; See if we have any previous continuations.
+ (when (and prev-attribute
+ (not (eq prev-attribute attribute)))
+ (setq vals
+ (mapconcat 'cdr (sort vals 'car-less-than-car) ""))
+ (push (cons prev-attribute
+ (if prev-encoded
+ (rfc2231-decode-encoded-string vals)
+ vals))
+ parameters)
+ (setq prev-attribute nil
+ vals nil
+ prev-encoded nil))
+ (unless (eq c ?=)
+ (error "Invalid header: %s" string))
+ (forward-char 1)
+ (setq c (char-after))
+ (cond
+ ((eq c ?\")
+ (setq value (buffer-substring (1+ (point))
+ (progn
+ (forward-sexp 1)
+ (1- (point)))))
+ (when encoded
+ (setq value (mapconcat (lambda (c) (format "%%%02x" c))
+ value ""))))
+ ((and (or (memq c ttoken)
+ ;; EXTENSION: Support non-ascii chars.
+ (> c ?\177))
+ (not (memq c stoken)))
+ (setq value
+ (buffer-substring
+ (point)
+ (progn
+ (forward-sexp)
+ ;; We might not have reached at the end of
+ ;; the value because of non-ascii chars,
+ ;; so we should jump over them if any.
+ (while (and (not (eobp))
+ (> (char-after) ?\177))
+ (forward-char 1)
+ (forward-sexp))
+ (point)))))
+ (t
+ (error "Invalid header: %s" string)))
+ (if number
+ (progn
+ (push (cons number value) vals)
+ (setq prev-attribute attribute
+ prev-encoded encoded))
+ (push (cons attribute
+ (if encoded
+ (rfc2231-decode-encoded-string value)
+ value))
+ parameters))))
+
+ ;; Take care of any final continuations.
+ (when prev-attribute
+ (setq vals (mapconcat 'cdr (sort vals 'car-less-than-car) ""))
+ (push (cons prev-attribute
+ (if prev-encoded
+ (rfc2231-decode-encoded-string vals)
+ vals))
+ parameters)))
+ (error
+ (setq parameters nil)
+ (if signal-error
+ (signal (car err) (cdr err))
+ ;;(message "%s" (error-message-string err))
+ )))
+
+ (cons type (nreverse parameters))))))