WebSiphon 2 Guide: TCP/IP Internet Functions
contents prev next

These high-level functions enable implementation of custom Internet clients such as Webmail or web-based FTP services, information gathering agents, server farm synchronization daemons, or any other type of TCP/IP services you can dream up.

See the Web and Session Utilities library if you need to work with HTTP client services like sessions, cookies, or file uploads.

E-Mail
parseMail
POP3Connect
POP3CountMessages
POP3DeleteMessage
POP3Disconnect
POP3GetMessage
POP3ListMessages
sendEmail
HTTP
HTTPGet
HTTPPost
FTP
FTPConnect
FTPDeleteFile
FTPDeleteDir
FTPDisconnect
FTPGetFile
FTPListDir
FTPPutFile

E-Mail Function Suite

parseMail (rfc822-string)
Returns: list Location: NetworkLib
ParameterDescription
rfc822-stringRFC822-formatted mail message

If given an RFC822-formatted e-mail message in CRLF format (returned from POP3GetMessage(), read from an archived mail file, or from another srouce), this function returns a structured list containing the various elements of the message data.

The following items are in the returned list:

  1. Subject
  2. From address
  3. To Addresses (list of strings)
  4. CC Addresses (list of strings)
  5. Reply-To address
  6. Formatted Date string
  7. Date, in seconds since Jan. 1, 1904 GMT.
  8. Message-ID
  9. Reply-ID
  10. Body of Message (or the string "MIME Enclosure" if the body is a non-text MIME type.)

See Also:

POP3Connect ( host, pop3-user, pop3-password )
Returns: pop3-link Location: NetworkLib
ParameterDescription
hosthost name or IP address of POP3 server
pop3-userPOP3 account username
pop3-passwordPOP3 accountpassword

Initiates a connection to the POP3 server running on the host specified by hostname to the mailbox specified by pop3-user and pop3-password.

Returns a POP3 connection link which may be used with other functions in the POP3 function suite.

Example:

pop3_link = POP3Connect("mail.mydomain.com", mail_user, mail_pass);
// you'll get a 0 for this value if the connect fails!
if (pop3_link != 0) then
  print "# of listsucker msgs: " & POP3CountMessages(pop3_link));
end if;

See Also:

POP3CountMessages ( pop3-link )
Returns: integer Location: NetworkLib
ParameterDescription
pop3-linkPOP3 server connection reference

Returns the number of messages in the mailbox specified by pop3-link.

See Also:

POP3DeleteMessage ( pop3-link, message-index )
Returns: null Location: NetworkLib
ParameterDescription
pop3-linkPOP3 server connection reference
message-indexserver message index

Marks the message with index message-index for deletion. The message is no longer available to other POP3 functions, and will be erased once POP3Disconnect() is called on the connection and the mailbox is closed.

See Also:

POP3Disconnect ( pop3-link )
Returns: null Location: NetworkLib
ParameterDescription
pop3-linkPOP3 server connection reference

Closes the connection specified by pop3-link.

See Also:

POP3GetMessage ( pop3-link, message-index )
Returns: string Location: NetworkLib
ParameterDescription
pop3-linkPOP3 server connection reference
message-indexserver messageindex

Returns the text of the email message specified by message-index, which refers to the index of the desired item in the remote mailbox (1 for the first email, 2 for the second, etc.).

The returned text is an RFC822-formatted message, using CRLF formatting.

See Also:

POP3ListMessages ( pop3-link )
Returns: list Location: NetworkLib
ParameterDescription
pop3-linkPOP3 server connection reference

Returns a list of sub-lists, one item for each message in the mailbox specified by pop3-link.

Each sub-list contains the following items:

  1. Server Message Index value
  2. Message Size, in bytes

See Also:

sendEmail ( host, to-address, from-address, message-subject, message-body )
Returns: null or list Location: NetworkLib
ParameterDescription
hosthost name or IP address of SMTP mail server
to-addresse-mail to address (may be a list of addresses)
from-addresse-mail from address
message-subjecte-mail subject
message-bodye-mail message body

This function will send an Internet e-mail message using the SMTP server specified by the mail-host parameter. The to-address parameter may be a single string or a list of addresses.

If the mail is successfully sent, the function will return null. If the e-mail cannot be sent due to an error, a list will be returned as [error-number, error-message].

If you require logging of unsent mail, script a conditional routine to log any mail messages that can not be sent.

Examples:

  1. sendEmail("mail.domain.com", "sales@purity.com", "you@domain.com", 
              "Purchase", "I would like to purchase WebSiphon!");
  2. address_list = ["sales@domain.com" "shipping@domain.com"];
    sendEmail("mail.domain.com", address_list, "webmaster@domain.com", 
              "Web Order #1042 Received", "");

The NetworkLib library provides some preferences which may be set to control how this function is used in a shared server environment. These options may be set by choosing "NetworkLib Prefs..." from the Edit menu within the WebSiphon application. Using the preferences panel, you can set a default mail host to use for all e-mail, overriding the one specified in the mail-host parameter. A maximum number of allowed addresses in the to-address parameter may also be specified.

HTTP Function Suite

HTTPGet ( host, uri [, auth-user, auth-password, user-agent ])
Returns: list Location: NetworkLib
ParameterDescription
hosthost name or IP address of HTTP server
uriuri request
[auth-user]HTTP basic authentication username [optional]
[auth-password]HTTP basic authentication password [optional]
[user-agent]user-agent string [optional]

Retrieves the specified uri from host using the standard HTTP GET method. The optional parameters auth-user and auth-password are used to access pages protected by basic authenticated realms. If you wish to set a custom user agent string in the HTTP request, use the optional user-agent parameter.

Returns a structured list describing the results:

1. HTTP Result Code
the response code for the transaction (200 = success, 404 not found, etc.)
2. MIME Type
the MIME Type of the response data, as reported in the headers
3. URI Data
the binary response data
4. HTTP Response Headers
the binary HTTP header data

Note: URI Data and HTTP Response Headers are each returned as a binary data type. Use binaryToString() to convert to string if you need to work directly with this data.

Example:

// retrieve default page from the Purity server
remote_host = "www.purity.com";
user_string = "CheesyPoofs/1.0 (WebSiphon 2; Mac; PPC)";
the_result = HTTPGet(remote_host, "/", null, null, user_string);

// display results
setMIMEType("text/plain");
print "Result Code: " & the_result'1 & "\r";
print "MIME Type: " & the_result'2 & "\r";
print "Response Headers: " & binaryToString(the_result'4) & "\r";
print "Response Data: \r\r" & binaryToString(the_result'3);
HTTPPost (host, uri, post-arguments [, auth-user, auth-password, user-agent ])
Returns: list Location: NetworkLib
ParameterDescription
hosthost name or IP address of HTTP server
uriuri request (the POST action attribute)
post-argumentspost arguments, as a list of name/value pairs
[auth-user]HTTP basic authentication username [optional]
[auth-password]HTTP basic authenication password [optional]
[user-agent]user-agent string [optional]

HTTPPost() retrieves the results using the specified URI form POST action at host using the standard HTTP POST method. Pass POST arguments as a list of name/value pairs. The optional parameters auth-user and auth-password are used to access pages protected by HTTP basic authenticated realms. If you wish to set a custom user agent string in the HTTP request, use the optional user-agent parameter.

Returns a structured list describing the results:

  1. HTTP Result Code- the response code for the transaction (200 = success, 404 not found, etc.)
  2. MIME Type- the MIME Type of the response data, as reported in the headers
  3. URI Data - the binary response data
  4. HTTP Response Headers- the binary HTTP header data

Note: URI Data and HTTP Response Headers are each returned as a binary data type. Use binaryToString() to convert to string if you need to work directly with this data.

Example:

post_args = [["name" "Mark Holtz"]
             ["site" "www.intermag.com"]
             ["package" "Babel 1.0a1"]];
the_result = HTTPPost("www.intermag.com", "/", post_args, null, null, 
                      "CheesyPoofs/1.0 (WebSiphon 2; Macintosh; PPC)");
setMIMEType("text/plain");
print "Result Code: " & the_result'1 & "\r";
print "MIME Type: " & the_result'2 & "\r";
print "Response Headers: " & binaryToString(the_result'4) & "\r";
print "Response Data: \r\r" & binaryToString(the_result'3);

FTP Function Suite

FTPConnect (host, ftp-user, ftp-pass [, ftp-account, server-port, use-passive ])
Returns: ftp-link Location: NetworkLib
ParameterDescription
hosthost name or IP address of FTP server
ftp-userftp account username
ftp-passftp acccount password
[ftp-account]ftp account name [optional]
[server-port]connect with special port number [optional]
[use-passive]use FTP passive mode? (true/false) [optional]

Initiates a connection to the FTP server running on host, given the login credentials ftp-user, ftp-pass and the optional ftp-account parameters. If the server is running on a port other than the default port 21, this is specified using the server-port parameter. Finally, the boolean value use-passive specifies whether or not this connection should use active or passive mode in handling future FTP calls.

Returns an FTP connection link which may be used by other functions in the FTP suite.

Example:

// connect to FTP server and output contents of home directory
ftp_link = FTPConnect("ftp.mydomain.com", ftp_login, ftp_pass);
if (ftp_link != 0) then
  printList(FTPListDir(ftp_link, "/"));
end if;

See Also:

FTPDeleteFile ( ftp-link, object-path )
Returns: null Location: NetworkLib
ParameterDescription
ftp-linkFTP server connection reference
object-pathpath to the object being expunged

Permanently removes the remote object specified by object-path. Use this function with caution, as it is irreversible.

FTPDeleteDir ( ftp-link, directory-path )
Returns: null Location: NetworkLib
ParameterDescription
ftp-linkFTP server connection reference
directory-pathpath to the directory being expunged

Permanently removes the remote directory specified by del-dir-path. Use this function with caution, as it is irreversible.

FTPDisconnect ( ftp-link )
Returns: null Location: NetworkLib
ParameterDescription
ftp-linkFTP server connection reference

Closes the FTP session specified by ftp-link.

See Also:

FTPGetFile ( ftp-link, remote-path, destination-path )
Returns: null Location: NetworkLib
ParameterDescription
ftp-linkFTP server connection reference
remote-pathpath to source file on FTP server
destination-pathpath to local destination file

Retrieves the file specified by remote-path and archives locally to the file specified by destination-path. Transfers are performed using FTP binary mode, and the destination file is either created or overwritten depending on conditions.

The remote-path may be relative to the current working FTP directory, or a full path to the file on the FTP server.

FTPListDir ( ftp-link [, directory-path ])
Returns: list Location: NetworkLib
ParameterDescription
ftp-linkFTP server connection reference
[directory-path] path to FTP subdirectory [optional]

Returns a list containing one string item for each item in the specified directory (or in the current directory iff none is specified). This string may vary depending on the remote FTP server, but usually contains filename, permission, size, and mod-date data.

FTPPutFile ( ftp-link, local-path, destination-path )
Returns: null Location: NetworkLib
ParameterDescription
ftp-linkFTP server connection reference
local-pathpath to local source file
destination-pathFTP destination path

Puts the local file specified by local-path to the remote FTP location specified by destination-path. Transfers are performed using FTP binary mode.

contents prev next

Copyright (c)1996-2003 Purity Software