indexing
	description: "Objects that ..."
	author: ""
	date: "$Date$"
	revision: "$Revision$"

class interface
	SMTP_PROTOCOL

create 

	make (host: STRING; user: STRING)
			-- Create an smtp protocol with 'host, 'user' and default port.

feature -- Initialization

	make (host: STRING; user: STRING)
			-- Create an smtp protocol with 'host, 'user' and default port.
	
feature -- Access

	header (h: STRING): HEADER
			-- Retrieve the content of the header 'h'
			-- (from EMAIL_RESOURCE)

	headers: HASH_TABLE [HEADER, STRING]
			-- All information concerning each headers
			-- (from EMAIL_RESOURCE)

	hostname: STRING
			-- hostname .. ex: smtp
			-- (from EMAIL_PROTOCOL)

	memory_resource: MEMORY_RESOURCE
			-- Memory resource to be send
			-- (from SENDING_PROTOCOL)

	pipelining: BOOLEAN
			-- Does the connection use pipeline?

	smtp_code_number: INTEGER
			-- Code number of the reply

	smtp_reply: STRING
			-- Replied message from SMTP protocol
	
feature -- Status report

	error: BOOLEAN
			-- Is there an error?
			-- (from EMAIL_RESOURCE)

	is_connected: BOOLEAN
			-- Is the connection done?
			-- (from EMAIL_PROTOCOL)

	is_header_valid: BOOLEAN
			-- Is the email resource's header valid?
			-- (from EMAIL_RESOURCE)

	is_initiated: BOOLEAN
			-- Has the connection has been initiated?
			-- (from EMAIL_RESOURCE)

	transfer_error: TRANSFER_ERROR
			-- Transfer error handling
			-- (from EMAIL_RESOURCE)
	
feature -- Status setting

	disable_initiated
			-- Unset is_initiated.
			-- (from EMAIL_RESOURCE)

	disable_transfer_error
			-- Disable transfer error.
			-- (from EMAIL_RESOURCE)

	enable_initiated
			-- Set is_initiated.
			-- (from EMAIL_RESOURCE)

	enable_transfer_error
			-- Enable transfer error.
			-- (from EMAIL_RESOURCE)

	set_transfer_error_message (s: STRING)
			-- Set transfer error message to 's'.
			-- (from EMAIL_RESOURCE)
	
feature -- Access EMAIL_PROTOCOL

	Default_port: INTEGER is 25
			-- Smtp default port
	
feature -- Basic operations.

	close_protocol
			-- Terminate the connection.
		require -- from  PROTOCOL_RESOURCE
			True
		require else
			connection_exists: is_connected
		ensure -- from PROTOCOL_RESOURCE
			protocol_not_initiated: not is_initiated

	initiate_protocol
			-- Initiate the smtp connection
			-- It can be a helo or a ehlo connection.
		ensure -- from PROTOCOL_RESOURCE
			protocol_initiated: is_initiated
	
feature -- Constants for SMTP Protocol

	Ack_begin_connection: INTEGER is 220
			-- (from EMAIL_CONSTANTS)

	Ack_end_connection: INTEGER is 221
			-- (from EMAIL_CONSTANTS)

	Data: STRING is "DATA"
			-- (from EMAIL_CONSTANTS)

	Data_code: INTEGER is 354
			-- (from EMAIL_CONSTANTS)

	Ehlo: STRING is "EHLO "
			-- (from EMAIL_CONSTANTS)

	Helo: STRING is "HELO "
			-- (from EMAIL_CONSTANTS)

	Mail_bcc: STRING is "RCPT BCC:"
			-- (from EMAIL_CONSTANTS)

	Mail_cc: STRING is "RCPT CC:"
			-- (from EMAIL_CONSTANTS)

	Mail_from: STRING is "MAIL FROM: "
			-- (from EMAIL_CONSTANTS)

	Mail_reply_to: STRING is "RCPT REPLY TO:"
			-- (from EMAIL_CONSTANTS)

	Mail_to: STRING is "RCPT TO: "
			-- (from EMAIL_CONSTANTS)

	No_valid_recipient: INTEGER is 554
			-- (from EMAIL_CONSTANTS)

	Ok: INTEGER is 250
			-- (from EMAIL_CONSTANTS)

	Quit: STRING is "QUIT"
			-- (from EMAIL_CONSTANTS)

	Remote_error: INTEGER is 550
			-- (from EMAIL_CONSTANTS)

	Size_error: INTEGER is 500
			-- (from EMAIL_CONSTANTS)

	Struct_error: INTEGER is 552
			-- (from EMAIL_CONSTANTS)
	
feature -- Constants for email headers (Authorized keys for the Hashtables)

	default_headers: ARRAY [STRING]
			-- (from EMAIL_CONSTANTS)

	H_bcc: STRING is "Bcc"
			-- (from EMAIL_CONSTANTS)

	H_cc: STRING is "Cc"
			-- (from EMAIL_CONSTANTS)

	H_from: STRING is "From"
			-- (from EMAIL_CONSTANTS)

	H_reply_to: STRING is "Reply-to"
			-- (from EMAIL_CONSTANTS)

	H_subject: STRING is "Subject"
			-- (from EMAIL_CONSTANTS)

	H_to: STRING is "To"
			-- (from EMAIL_CONSTANTS)
	
feature -- Implemantation (EMAIL_RESOURCE)

	Can_send: BOOLEAN is True
			--Can a sending protocol send?
			-- (from SENDING_PROTOCOL)
	
feature -- Implementation (EMAIL_RESOURCE)

	Can_be_received: BOOLEAN is False
			-- Can a protocol be received?
			-- (from PROTOCOL_RESOURCE)

	Can_be_sent: BOOLEAN is False
			-- Can a protocol resource be send?
			-- (from PROTOCOL_RESOURCE)

	Can_receive: BOOLEAN is False
			-- Can the Smtp protocolreceive?

	initialize
			-- Initialize the protocol to send a new email.
	
feature -- Implementation (EMAIL_RESOURCE).

	transfer (resource: MEMORY_RESOURCE)
			-- Send the email and add a . at the end of the message.
		require -- from EMAIL_RESOURCE
			resource_exists: resource /= void
			is_valid_transfer: (resource.can_be_sent and can_send) or (resource.can_receive and can_be_received)
			connection_is_initiated: (can_be_sent and resource.is_initiated) or (is_initiated and resource.can_be_received)
	
feature -- Setting

	disable_pipelining
			-- Unset pipelining.

	enable_pipelining
			-- Set pipelining.
	
feature -- Settings

	disable_connected
			-- Unset is_connected.
			-- (from EMAIL_PROTOCOL)

	enable_connected
			-- Set is_connected.
			-- (from EMAIL_PROTOCOL)

	set_default_port (new_port: INTEGER)
			-- Set the default port to 'new_port'.
			-- (from EMAIL_PROTOCOL)
	
invariant

		-- from ANY
	reflexive_equality: standard_is_equal (Current)
	reflexive_conformance: conforms_to (Current)

end -- class SMTP_PROTOCOL