Email Services with File System Example

This example contains basic functionality test on email APIs and allows user to send
authenticated email with a file attachment from the file system.

This example should work on all platforms.

HTTP server and FTP Server are included so that user can download a file into 
the file system.

HTML pages are provided for user to upload a file in to the file system, to start email 
basic functionality test and to send an email with file attachment.

The basic functionality test includes sending an email with a simple test file attachment
which is created during startup, saving email message and any attachment file in the 
file system, and reading email message. This test is run as a separate thread (see
email_test_start() in teststatus_v.c file). 

User can send an email by accessing the email.htm link. It allows user to specify 
single or multiple recipient's address (use ; to separate each address with space). 
Same as CC address and file attachment. The file attachment must be given in full
path name (i.e. /RAM0/DIR0/test.txt). 

The example also demonstrates how authentication can be used to access email. Some
server doesn't allow user to access unless authenticated. The following options
are added in the email configuration page
None:       No authentication
Digest MD5: If server supports Digest MD5 then client will use Digest MD5 to 
            authenticate (requires username and password)
Any:        Client uses one of the following (requires username and password) 
            DIGEST MD5
			CRAM MD5
            LOGIN
            PLAIN 
									  
This "namail_fs" example will set up 2 volumes ("FLASH0" and "RAM0") in RAM if BSP 
is not configured to initialize the volumes. Please see BSP. 

If BSP is configured to initialize the file system, make sure it creates two volumes 
with the name of "FLASH0" and "RAM0".

This example starts and creates:

1. A test file in \RAM0 (root directory) with group id 1.
2. "DIR0" directory in \RAM0 with group id 1.
3. "DIR1" directory in \RAM0 with group id 2.
4. "dir0" username & "dir0" password for accessing group id 1 files/directories.
5. "dir1" username & "dir1" password for accessing group id 2 files/directories.
6. "user" username & "password" password for accessing both group id 1 & 2.


APP_USE_NETWORK_TIME_PROTOCOL is defined in appconf.h to include time.

APP_FILE_SYSTEM is defined in the build files to include the file system interface for 
the HTTP Server.

To update a file:

1. Goto the home page by typing the ip address in the URL. 
2. Click on the upload link and a upload page will be displayed.
3. Select a directory where a file will be created.
4. Click the <Browser> button to select a file from the PC
5. Click the <Upload> button to start uploading.

To download or view a file:

1. Type http://ip_address/FS/full_path_filename to retrieve a file.

   The HTTP server uses "FS" to identify a file in the file system.
   HTTP server will prompt username and password entries if a file is not accessible by
   the default group id. 

All the HTML pages are generated by Page Builder.

To start email basic functionality test:

1. Goto the home page by typing the ip address in the URL. 
2. Click on the Mail Services link. 
3. Enter POP3 Address, SMTP address and the port of SMTP.
4. Click "Basic Test" button.
5. Enter username & password for retriving email message.
6. Enter recipient's email address and sender's email address for sending a 
   email with a simple test file.
7. .001 file will be created in RAM0\ directory for retrieving an email message.
8. .txt file will be created in RAM0\ directory for any file attachment when 
   retrieving an email message.
9. mailfile.001 will be created in RAM0\DIR0 directory for retrieving an email message.

To send an email:
1. Goto the home page by typing the ip address in the URL. 
2. Click on the Mail Services link. 
3. Enter POP3 Address, SMTP address and the port of SMTP.
4. username & password is required for accessing the file attachment
5. Enter recipient's address (use ; for multiple address without any space).
6. Enter cc address (user ; for multiple address without any space).
7. Enter sender's address 
8. Enter subject
9. Enter file name (use ; for mutliple file without any space). Files must be
   uploaded in the file system. 
10. Type body message.
11. Click <Send> button. It will start sending the email.  

Three MULTI build files are provided if the option to install Green Hills
support is selected.  The build file project.gpj is used to control how
application specific files are built.  All updates to the build should be
made to this file.  Project.gpj is a subproject to the other build files
image.gpj and rom.gpj.  Image.gpj is used to generate a debuggable version
of the application, and also creates the file image.bin that can be written
into ROM if the bootloader is used.  Rom.gpj is used to generate a 
ROM image of the application if the bootloader is not used.

One GNU make file is provided.  Build the target 'image' to
generate an image that can be debugged with gdb, and the file 
image.bin which can be written to flash if the bootloader is used.
Build the target 'rom.bin' to create the file rom.bin which 
can be written to ROM if the bootloader is not used.

The following files are provided with this example:

appconf.h         sets application configuration settings
.\32b\image.gpj   used to build the big endian Green Hills version of the
                  application.  The build script creates a version that
                  can be debugged with Multi, and the file image.bin 
                  which can be written into a ROM that uses the bootloader.
makefile          Make file for the GNU toolset.
project.gpj       contains application specific build settings
readme            this file
.\32b\rom.gpj     used to build the big endian ROM image of application

root.c            			contains applicationStart() function
naftpapp.c		  			contains function to setup and start FTP server
fileinit.c		  			contains function to initialize the file system and creates a test
security.c					Setup access realm for username & password
pbuilder\RpUsrDct.c   		Phrases used in html pages that HTTP server needs.
pbuilder\RpPages.c	  		Contains links of all html pages. 
pbuilder\html\index.c 		Home page generated.
pbuilder\index_v.c			Contains functions for index.c
pbuilder\html\upload.c		HTML page to upload a file
pbuilder\upload_v.c			Contains functions for upload.c
pbuilder\html\delete.c		HTML page to empty a directory
pbuilder\delete_v.c			Contains functions for delete.c
pbuilder\html\groupid.c		HTML page to set default group id for HTTP server
pbuilder\groupid_v.c		Contains functions for groupid.c
pbuilder\html\filelist.c	HTML page to display a list of files in the file system.
pbuilder\filelist_v.c 		Contains functions for filelist.c
pbuilder\html\statusmsg.c	Status message HTML page
pbuilder\statusmsg_v.c		Contains functions for statusmsg.c
pbuilder\html\sendmail.c   	HTML page to send email message
pbuilder\sendmail_v.c		Contains functions for sendmail.c
pbuilder\html\emailtest.c	HTML page to setup email basic functionality test
pbuilder\emailtest_v.c		Contains functions for emailtest.c
pbuilder\html\teststatus.c	HTML page to start email basic functionality test
pbuilder\teststatus_v.c		Contains functions for teststartus.c
pbuilder\html\email.c		HTML page to setup email server 
pbuilder\email_v.c			Contains functions for email.c
pbuilder\html\emailstatus.c	HTML page to display email status
pbuilder\emailstatus_v.c	Contains functions for emailstatus.c
..\..\..\src\rphttpd\cgi.c	User defined CGI support
..\..\..\src\rphttpd\file.c Contains interface between the file system and HTTP server.
..\..\..\src\fs_intf\ftpsvrfs.c	Contains interface between the file system and FTP server.
..\..\..\src\fs_intf\mailfile.c	Contains interface between the file system and email services.

In addition, the following files in the BSP directory are built as part of this 
example:

reset.s         contains the reset code
appconf_api.c   contains code used to read settings in appconf.h


The build file links in the following libraries:

libbsp.a             
libtcpip.a           
tx.a              
libposix.lib		  
libflash.lib		  
libsnmpd.lib
libmanapi.lib
libftpsvr.lib
ghs.o
libfilesys.a
libsntp.a
librphttpd.a


The application uses the following files located in the
netos\src\linkerScripts directory.

bootldr.dat     bootloader configuration file used to generate the
                file image.bin.  It controls the information placed
                in the bootloader header of the image.

customize.lx	customerize linker script

image.lx		linker script used to build an image that can be debugged


