@verb #80:"parse_multipart" this none this rxdo #60 @program #80:"parse_multipart" this none this "$www:parse_multipart(multipart stream, boundary)" " => {form data, datatypes}" "Takes a stream of MIME Multipart data (usually multipart/form-data) and splits" "it up into standard {{name, value}, {name, value}, ...} pairs. Also returns a" "list (of equal length) to give the content-type for each of the values, ie" "{\"text/plain\", \"application/octet-stream\", ...}" {stream, boundary} = args "Get the first boundary, and start after that." boundary = "--" + boundary if (!(i = index(stream, boundary))) return {{}, {}} else stream = stream[i + length(boundary)..$] endif formdata = datatypes = {} while (i = index(stream, boundary)) chunk = stream[1..i - 1] name = value = content_type = "" if (!(j = index(chunk, "~0D~0A~0D~0A"))) continue endif chunk_headers = $string_utils:explode_all(chunk[1..j - 1], "~0D~0A") for h in (chunk_headers) try if (h[1..20] == "Content-disposition:") disp = $string_utils:explode(h[21..$], ";") for dispy in (disp) dispy = $string_utils:trim(dispy) dispy_parts = $string_utils:explode(dispy, "=") if (dispy_parts[1] == "name") name = `dispy_parts[2][2..$ - 1] ! E_RANGE => ""' endif $cmd_utils:suspend_if_needed(0) endfor elseif (h[1..13] == "Content-type:") content_type = $string_utils:trim(h[15..$]) endif except (ANY) endtry $cmd_utils:suspend_if_needed(0) endfor value = chunk[j + 12..$] content_type = content_type || "text/plain" if (`content_type[1..4] ! E_RANGE' == "text") value = value[1..$ - 6] lf = index(value, "~0A", 1) cr = index(value, "~0D", 1) "Make sure that all line breaks are just ~0D" if (lf && cr) value = strsub(value, lf < cr ? "~0A~0D" | "~0D~0A", "~0D") elseif (lf) value = strsub(value, "~0A", "~0D") endif value = $string_utils:explode_all(value, "~0D") if (length(value) == 1) value = value[1] endif endif formdata = {@formdata, {name, value}} datatypes = {@datatypes, content_type} stream = stream[i + length(boundary)..$] endwhile return {formdata, datatypes} "Last modified by Cecil (#7407) on Wed Apr 2 00:04:29 2003 MST." .