-------------------------------------------------------------------------------- -- Title: MIMEMultipartFormData.lua -- Description: Like a square peg in a round hole -- Author: Raphaël Szwarc http://alt.textdrive.com/lua/ -- Creation Date: February 1, 2005 -- Legal: Copyright (C) 2005 Raphaël Szwarc -------------------------------------------------------------------------------- -- import dependencies local MIMEMultipart = require( "MIMEMultipart" ) local LUObject = require( "LUObject" ) local LUList = require( "LUList" ) local LUMap = require( "LUMap" ) -- define the class local super = MIMEMultipart local self = super() function self:data() if self._data == nil then local someData = LUMap() for anIndex, aPart in self:content():iterator() do local aDisposition = aPart:disposition() or "" if aDisposition:lower() == "form-data" then local anHeader = aPart:headers():getHeader( "content-disposition" ) local someParameters = anHeader:parameters() local aKey = someParameters:get( "name" ) if aKey ~= nil then local aName = someParameters:get( "filename" ) local aValue = aPart:content() if someData:hasKey( aKey ) == true then local aList = someData:get( aKey ) if LUObject:isObject( aList ) == false then aList = LUList() aList:add( someData:get( aKey ) ) someData:put( aKey, aList ) end aList:add( aValue ) else someData:put( aKey, aValue ) end if aName ~= nil then local aType = aPart:type() someData:put( aKey .. ".name", aName ) if aType ~= nil then someData:put( aKey .. ".type", aType ) end end end end end self._data = someData end return self._data end return self