root/MIME/MIMEMultipart.lua

Revision 816 (checked in by rsz, 3 years ago)

cleanup

Line 
1 --------------------------------------------------------------------------------
2 -- Title:               MIMEMultipart.lua
3 -- Description:         Like a square peg in a round hole
4 -- Author:              Raphaël Szwarc http://alt.textdrive.com/lua/
5 -- Creation Date:       February 1, 2005
6 -- Legal:               Copyright (C) 2005 Raphaël Szwarc
7 --------------------------------------------------------------------------------
8
9 -- import dependencies
10 local MIME = require( "MIME" )
11 local LUList = require( "LUList" )
12
13 -- define the class
14 local super = MIME
15 local self = super()
16
17 function self:headers()
18         return self:parent():headers()
19 end
20
21 function self:boundary()
22         local someHeaders = self:headers()
23         local anHeader = someHeaders:getHeader( "content-type" )
24         local someParameters = anHeader:parameters()
25
26         return someParameters:get( "boundary" )
27 end
28
29 function self:content()
30         if self._content == nil then
31                 local someParts = LUList()
32                 local aRawContent = self:rawContent()
33                 local aBoundary = "\r\n--" .. self:boundary()
34                 local aLength = aBoundary:len()
35                 local aStart = self:startIndex()
36                 local anEnd = self:endIndex()
37                
38                 while true do
39                         aStart = aRawContent:find( aBoundary, aStart, true )
40                        
41                         if aStart ~= nil then
42                                 aStart = aStart + aLength
43                                 anEnd = aRawContent:find( aBoundary, aStart, true )
44                                
45                                 if anEnd ~= nil then
46                                         aStart = aRawContent:find( "\r\n", aStart, true ) + 2
47                                
48                                         someParts:add( MIME( aRawContent, aStart, anEnd - 1, self ) )
49
50                                         aStart = anEnd
51                                 else
52                                         break
53                                 end
54                         else
55                                 break
56                         end
57                 end
58
59                 self._content = someParts
60         end
61
62         return self._content
63 end
64
65 return self
Note: See TracBrowser for help on using the browser.