root/SMTP/SMTPData.lua

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

cleanup

Line 
1 --------------------------------------------------------------------------------
2 -- Title:               SMTPData.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 SMTPCommand = require( "SMTPCommand" )
11 local LUList = require( "LUList" )
12
13 -- define the class
14 local super = SMTPCommand
15 local self = super()
16
17 -- method to run this command
18 function self:run( aSession, someTokens )
19         if super.run( self, aSession, someTokens ) == true then
20                 if aSession:sender() ~= nil and aSession:recipients():hasData() == true then
21                         local aDelegate = aSession:delegate()
22
23                         if aDelegate ~= nil and aDelegate:respondsTo( "smtpWillAddData" ) == true then
24                                 local aReader = aSession:reader()
25                                 local aBuffer = LUList()
26                                 local aLine = nil
27                
28                                 aSession:writer():writeln( "354 Start mail input; end with <CRLF>.<CRLF>" )
29                                
30                                 aLine = aReader:read()
31                                
32                                 while aLine ~= "." do
33                                         if aLine:byte() == 46 then
34                                                 aLine = aLine:sub( 2 )
35                                         end
36                                
37                                         aBuffer:add( aLine )
38                
39                                         aLine = aReader:read()
40                                 end
41                                
42                                 if aDelegate:smtpWillAddData( aSession, aBuffer:join( aSession:writer():eol() ) ) == true then
43                                         aSession:reset()
44                                         aSession:writer():writeln( "250 Message accepted for delivery" )
45                                 else
46                                         aSession:writer():writeln( "554 Transaction failed" )
47                                 end
48                         else
49                                 aSession:writer():writeln( "554 Transaction failed" )
50                         end
51                 else
52                         aSession:writer():writeln( "503 Bad sequence of commands" )
53                 end
54         end
55
56         return true
57 end
58
59 return self
Note: See TracBrowser for help on using the browser.