View script | License | Download documentation as: HTML or editable | Download script | History |
[0.045] 32.395k
Documentation for: websend.rUsage document for %websend.r1. Introduction to %websend.rwebsend.r is an introduction to the ease and simplicity of accessing the internet, and sending email. 2. websend At a GlanceSome setup is required. This script sends an email to luke@rebol.com, so you will need to edit this to a real email! address. It is also set to read the index page at www.rebol.com. You will need to edit the url! to read a page you are interested in sending to the email address you changed. 3. Using %websend.rRequires REBOL/Core or REBOL/View console mode. 3.1. Standard REBOL settingsThere is a standard utility that holds some basic REBOL configuration information. set-net takes a block of information so that REBOL knows how to route mail and for other internet connections. The REBOL/View Viewtop main User menu allows access to these settings or you can edit the default %user.r file and change the set-net information. >> help set-net USAGE: SET-NET settings DESCRIPTION: Network setup. All values after default are optional. Words OK for server names. SET-NET is a function value. ARGUMENTS: settings -- [email-addr default-server pop-server proxy-server proxy-port-id proxy-type esmtp-user esmtp-pass] (Type: block) The first two setting are for sending mail, the third is for reading mail, then there are proxy connection settings and then two settings for authenticated mail username and password. 3.2. Running %websend.rMake a copy from the library with: >> write %websend.r read http://www.rebol.org/cgi-bin/cgiwrap/rebol/download-a-script.r?script-name=websend.rThe line above may look split, there is no carriage return if you type this in the console. Edit this copy with your favourite editor, or if you are running REBOL/View use the builtin editor feature. Once you have changed the email! address and url! you are good to go. Just do it. >> do %websend.r 4. What you can learn4.1. One of the many datatypes built into REBOL is email!. The REBOL systemknows that something @ something is a email address. The library script uses luke@rebol.com, but you'll want to change that to your own address.Some early versions of REBOL do not directly support the newer ESMTP. The internal SEND utility in these older versions of REBOL may fail if your ISP requires Authenticated email transmission.
ESMTP is now in widespread use to fight spam. Older versions of REBOL fully support SMTP, but things have changed since mail servers started using the Extended AUTH verb to require password authentication before relaying mail. This is a good thing, and as of March 2007, most platforms have a REBOL release that supports ESMTP. 4.2. Powerful builtin Internet AccessREBOL has fantastically simple builtin procedures for accessing the internet. 4.3. URLshttp://www.rebol.com is actually a value with a special datatype. In REBOL this is a url!. Very powerful. No quotes needed. REBOL just knows. 4.4. Web Server defaultsWeb Servers have default files that are returned. http://www.rebol.com is actually returned as http://www.rebol.com/index.html. This is not always the case. Some sites return default.htm, or index.php, or index.cgi. No need to worry, the REBOL read function and the web server will work that all out for you. If REBOL Technologies ever changes its web server setup, a different file may be returned and this script will still work. 4.5. Changing the page that is emailedChanging the website or page that is sent is as easy as changing the text after the http:// part following the read command. 4.6. Getting REBOLBoth REBOL/Core and REBOL/View are available 4.7. Compare the complexity to the simplicityPlease compare the print read http://www.rebol.com 31 character sequence to this D language program. 4.7.1. D Language sample for printing HTML as text/* HTMLget written by Christopher E. Miller This code is public domain. You may use it for any purpose. This code has no warranties and is provided 'as-is'. */ //debug = HTMLGET; import std.string, std.conv, std.stream; import std.socket, std.socketstream; int main(char[][] args) { if(args.length < 2) { printf("Usage:\n htmlget <web-page>\n"); return 0; } char[] url = args[1]; int i; i = std.string.find(url, "://"); if(i != -1) { if(icmp(url[0 .. i], "http")) throw new Exception("http:// expected"); } i = std.string.find(url, '#'); if(i != -1) // Remove anchor ref. url = url[0 .. i]; i = std.string.find(url, '/'); char[] domain; if(i == -1) { domain = url; url = "/"; } else { domain = url[0 .. i]; url = url[i .. url.length]; } uint port; i = std.string.find(domain, ':'); if(i == -1) { port = 80; // Default HTTP port. } else { port = std.conv.toUshort(domain[i + 1 .. domain.length]); domain = domain[0 .. i]; } debug(HTMLGET) printf("Connecting to " ~ domain ~ " on port " ~ std.string.toString(port) ~ "...\n"); auto Socket sock = new TcpSocket(new InternetAddress(domain, port)); Stream ss = new SocketStream(sock); debug(HTMLGET) printf("Connected!\nRequesting URL \" ~ url ~ "\"...\n"); if(port != 80) domain = domain ~ ":" ~ std.string.toString(port); ss.writeString("GET " ~ url ~ " HTTP/1.1\r\n" "Host: " ~ domain ~ "\r\n" "\r\n"); // Skip HTTP header. char[] line; for(;;) { line = ss.readLine(); if(!line.length) break; const char[] CONTENT_TYPE_NAME = "Content-Type: "; if(line.length > CONTENT_TYPE_NAME.length && !icmp(CONTENT_TYPE_NAME, line[0 .. CONTENT_TYPE_NAME.length])) { char[] type; type = line[CONTENT_TYPE_NAME.length .. line.length]; if(type.length <= 5 || icmp("text/", type[0 .. 5])) throw new Exception("URL is not text"); } } print_lines: while(!ss.eof()) { line = ss.readLine(); printf("%.*s\n", line); //if(std.string.ifind(line, "</html>") != -1) // break; size_t iw; for(iw = 0; iw != line.length; iw++) { if(!icmp("</html>", line[iw .. line.length])) break print_lines; } } return 0; }What would you rather type? The above or print read join http:// ask "Web site? " What will be easier to remember 6 months from now? 5. What can breakYou will need access to the internet and rebol.com will have to be up and running for this script to work. Don't worry, http://www.rebol.com is always up and running. 6. Some Definitions
7. Also worth a lookThere is a full suite of scripts that demonstrate how easy it is to use the HTTP url! (or "the web" ) features in REBOL. These features are one of the central design goals of the REBOL scripting environment. These sample scripts highlight the ease of using internet resources with REBOL. 8. List of tutorial scripts in the web category
9. A script you have to check out
10. More in-depth scripts
10.1. Other web related scriptsdealing with web related REBOL programming that you can find in the rebol.org library. There are also complete suites for FTP, HTML, CGI, and many others.
11. Credits
|