------------------------- Week 09 Notes for CST8165 ------------------------- -Ian! D. Allen - idallen@idallen.ca Remember - knowing how to find out an answer is more important than memorizing the answer. Learn to fish! RTFM! (Read The Fine Manual) Keep up on your readings (Course Outline: average 4 hours/week homework) [************************************************************] [************************************************************] [*** Students should be taking their own notes in class ***] [*** and updating them with my published summaries. ***] [************************************************************] [************************************************************] http://teaching.idallen.com/cst8165/07w/notes/smtp_session.txt http://teaching.idallen.com/cst8165/07w/notes/perl_net_telnet.txt http://teaching.idallen.com/cst8165/07w/notes/smtpclient_v1.pl.txt http://teaching.idallen.com/cst8165/07w/notes/read_stdin.pl.txt http://teaching.idallen.com/cst8165/07w/notes/lab06.txt http://teaching.idallen.com/cst8165/07w/notes/autotest_smtp.sh.txt http://teaching.idallen.com/cst8165/07w/notes/sample_smtp_test_out.txt http://teaching.idallen.com/cst8165/07w/notes/sample_smtp_README.txt Review of SMTP: - http://tools.ietf.org/html/rfc2821 - Sample SMTP session (long and short) in Notes: smtp_session.txt - SMTP controls the "envelope" TO/FROM, not the message To:/From: - a text-based protocol, easily run using netcat. - 3-digit numeric response codes (know these five groups) - 1yz Positive Preliminary reply (not used in standard SMTP) - 2yz Positive Completion reply - 3yz Positive Intermediate reply - 4yz Transient Negative Completion reply - 5yz Permanent Negative Completion reply Q: Name the five main categories of SMTP server responses Q: T/F SMTP clients can figure out how to proceed based on just the first digit of an SMTP reply code; they can usually ignore the rest. (RFC 2821 Section 4.2, 4.2.1, 4.3.2) Review of Perl Net::Telnet: - high-level access to socket() and connect() system calls - handles LF to CR+LF for you Q: Does Net::Telnet translate LF to CR+LF for SMTP? SMTP MX records --------------- How does a mail client know to which SMTP server to connect when sending mail to a userid at some domain? It looks up the domain MX records in the DNS. An SMTP client queries the DNS for a domain to obtain "MX" (mail exchange) records that tell which machines accept SMTP mail for the domain: $ host -t mx algonquincollege.com algonquincollege.com mail is handled by 30 mailgate10.algonquincollege.com. algonquincollege.com mail is handled by 20 mailgate11.algonquincollege.com. $ host hotmail.com hotmail.com has address 64.4.32.7 hotmail.com has address 64.4.33.7 hotmail.com mail is handled by 5 mx2.hotmail.com. hotmail.com mail is handled by 5 mx3.hotmail.com. hotmail.com mail is handled by 5 mx4.hotmail.com. hotmail.com mail is handled by 5 mx1.hotmail.com. $ host idallen.ca idallen.ca has address 72.18.159.15 idallen.ca mail is handled by 0 idallen.ca. Q: How does an SMTP mailer know which computer to contact when sending mail to someone@domain.ca ? * SMTP Walk-Through (old RFC 821 version) with comments by Dan Bernstein http://cr.yp.to/smtp.html - comments based on original RFC 821 not RFC 2821 (but often relevant) RFC2822 - message format - http://cr.yp.to/immhf.html - "If you're a new implementor, you'll be shocked at how badly 822 was designed." - RFC2821 standards process "incompetence" by editor Klensin http://cr.yp.to/smtp/klensin.html - group concensus about HELO/EHLO didn't make the final draft! - "What an incredible display of incompetence!" Q: T/F RFC standards development has been a very organized process. Perl smtpclient_v1.pl.txt template code review ---------------------------------------------- http://teaching.idallen.com/cst8165/07w/notes/smtpclient_v1.pl.txt http://teaching.idallen.com/cst8165/07w/notes/perl_net_telnet.txt http://teaching.idallen.com/cst8165/07w/notes/read_stdin.pl.txt http://teaching.idallen.com/cst8165/07w/notes/programming_style.txt The symbol XXX flags things that need fixing, adjusting, or removing. Comments labelled "Perl:" are teacher comments explaining how Perl works to students learning the language. The "Perl:" comments would never appear as comments in a production Perl program, since they have nothing to do with how the program works. Don't write comments like these in your submitted Perl programs. Comments in your code must explain why the program is doing what it is doing, and what is happening in the overall algorithm. Comments will not explain how the language works; unless, your use of the language is complex or tricky and requires explanation! For full marks, remove all the XXX and "Perl:" comments from the template file before you submit it! Topics covered this week: - conversion between Unix LF and Internet CR+LF - mandatory use of the exit codes (documented in ) - programs that send email need to signal to other programs whether or not they worked - if the program failed, was the failure permanent or temporary? - use of Perl: warn(), die(), join(), push(), split(), undef - use of Perl: arrays, $#arrayname, @arrayname - use of Perl: regular expressions - commenting style - no "magic numbers" - no duplicated code - make your programs easy to maintain and update - flushing output to remote servers - Perl uses: $| = 1 - don't want to buffer SMTP lines! - error messages in this course must have four characteristics. - See note file "programming_style.txt". * Comment style Notes file: programming_style.txt - see the pair of example programs at the end of the file - if you wish to use an alternate commenting and indenting style, please provide me with a link to it and we'll discuss it - I'm open to you using any popular real-world programming style; I don't want you inventing your *own* style Q: Why should you turn off output buffering when sending protocol lines to a remote server? Q: T/F In Perl, warn() prints a message on standard error and exits the program with a good (zero) return code. Q: Why must a client program that sends email return one of the values documented in sysexits.h? Q: Explain the two broad categories of errors documented in sysexits.h - what is the major feature that distinguishes the two types? Q: T/F In sysexits.h, we see many numbers indicating permanent failure codes; but, only a single number for a temporary failure code. Perl has a module that will parse command line options for you. I recommend using it rather than trying to write a lot of Perl code that duplicates its function.