Unix Mages

Of Mages and Mail, Part Two

The two mages returned from their break and the Admin continued his explanation of the Unix mail system.

“There are a few different ways a mage can read his mail on a Unix system. The first, and simplest, is with the mail spell.

“When the mail spell is cast, it will either tell the mage they have no mail, or if they do, place them in a new mail shell.

“Here’s what it looks like when the mage has no mail:”

$ mail
No mail for joe

“And here’s what it looks like when there’s actually mail:

$ mail
Mail version 8.1 6/6/93.  
Type ? for help.

"/var/spool/mail/joe": 1 message 1 new
>N  1 admin@unixmages.com  Sun Dec 11 11:54  14/565   "hi" 
N  2 admin@unixmages.com  Sun Dec 11 12:26  14/604   "hi again"
&

“The ampersand (&) is the prompt in the mail shell. Above that, mail tells us what messages the mage has in their inbox. N stands for “new” and the number next to it is that messages position in the inbox.

“To read a message, we simply type the messages number at the prompt:”

& 1
Message 1:
From admin@unixmages.com  Sun Dec 11 12:25:59 2005
X-Original-To: joe
Delivered-To: joe@unixmages.com
To: joe@unixmages.com
Subject: hi
Date: Sun, 11 Dec 2005 12:25:59 -0500 (EST)
From: admin@unixmages.com

hello, this is a test message

&

“To delete a message, use the d command:”

& d 1

“To quit, type q.”

& q
$

“You can also send new mail and reply to messages with the mail spell. For more information on it, type help at the mail prompt.”

Acre said, “So basically, the mail spell is just a fancy spell that does the same thing as casting cat and less manually in the mailbox.”

“Yep, mail just provides a nice shell. And don’t forget, you can send mail with mail, too.”

“OK, but to use the mail spell, doesn’t the mage have to be in the Tower where the mail is kept?”, Acre asked.

“Yes, that’s correct.” The Admin replied.

Acre said, “So what if the mage is at their house or away from the Tower?”

“Mages can still check their mail, but they’ll need help from some daemons.”

“Which ones?”

“Two actually: imapd and popd

“What are the differences?”, Acre asked.

popd (also known as popd3, since that’s the current version of the protocol) is more simple than imapd. It takes less resources in the Tower to use, and has been around longer. imapd, on the other hand, might be more complex, but provides more features in return.”

“What kind of features?”

“Well, when a mage checks their mail with pop3, all the mail is transferred to where the mage is, and is then removed from the Towers mail department. If the mage somehow loses their mail, it’s lost forever — the Tower has no record of it anymore. imap can fix that problem by allowing the mage to check their mail from a different location while still having the mail stored at the Tower. imap can also handle shared mailboxes and multiple mailboxes easily. While it is possible to leave mail at the Tower using pop, it doesn’t work as smoothly as imap and still creates a 2nd copy at the mage’s location, taking up space.”

Acre asked, “I see. So imap is more preferred?”

“It’s very easy for a Tower to use both pop and imap and let the mage decide. From the mage’s perspective, imap provides more features and is really the better choice — unless they’re in a situation where pop is the only option.”

“So how does each one work?” Acre asked.

The Admin replied, “The mage will have to set up a mail program wherever they are. Once he tells the mail program some information about himself, the Tower to get the mail from, and whether to use pop or imap, the program will do the rest of the dirty work. We can actually see some of that work here.

“Here’s what a pop session looks like:”

$ telnet pop3.unixmages.com 110

Trying 127.0.0.1...Connected to pop3.unixmages.com
Escape character is '^]'.
+OK POP3 ready.
user joe
+OK
pass p4ssw0rd
+OK Logged in.
list
1 44582 38183 16574 15348
quit
+OK Logging out.

“And here’s an imap session:”

$ telnet imap.unixmages.com 143
Trying 127.0.0.1...
Connected to imap.unixmages.com
* OK IMAP ready.
a1 login joe p4ssw0rd
a1 OK Logged in.
a2 select INBOX
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft \*)]  Flags permitted.
* 26 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1086774200] UIDs valid
* OK [UIDNEXT 10400] Predicted next UID
a2 OK [READ-WRITE] Select completed.
a3 logout
* BYE Logging out
a3 OK Logout completed.

“As you can see, they work in two completely different ways.” the Admin said.”

“What’s all that telnet stuff?” Acre asked.

telnet is a spell to let us talk to Towers remotely. pop3.unixmages.com and imap.unixmages.com are the two places we’re talking to. The number at the end is a port. We’ll learn about ports later — but just for now, remember that 110 and 143 are the port numbers for popd and imapd.”

“So popd and imapd — these two daemons allow a mage to connect to a remote Tower to check their mail. Basically, what they’re doing is teleporting over to the Tower and allowing the mage’s mail program to use fancy versions of the cat or less spells to read those text files in their mailbox. Right?”

“You got it.” The Admin said.

Acre said, “OK, I get it. Now what about mail services like gmail and yahoo that let you check your mail over the web. How do those work?”

“Basically the same way as using a full mail program. Those services still use mailboxes and popd and imapd, but they output all the mail to a webpage.”

“Got it.”, Acre said, “Now how does someone send me mail and how does it get to my mailbox?”

“We’ll go over that topic next.”