Monthly Archives: January 2013

Connect to IMAP server with telnet

Every so often I need to be able to check IMAP account settings. This can be done by manually connecting to the IMAP server with telnet.

Once connected, all IMAP commands are preceded with a word of your own choosing, which the server will respond with. This is to enable the client to recognise the reply to each command which it has sent (this would be useful where a real mail client sends various commands to the server without waiting for a reply after each one, and can later identify the reply to each command).

Some useful commands are:

LOGIN [username] [password]
LIST [flags] [folder separator] [search term]
STATUS [mailbox] [flags]
SELECT [mailbox]
FETCH [first]:[last] flags
FETCH [mail number] body[header]
FETCH [mail number] body[text]
LOGOUT

Here is an example of an IMAP conversation between telnet and the server:

telnet: > open imapserver.example.com imap
telnet: Trying 192.0.2.2...
telnet: Connected to imapserver.example.com.
telnet: Escape character is '^]'.
server: * OK Dovecot ready.
client: a1 LOGIN MyUsername MyPassword
server: a1 OK Logged in.
client: a2 LIST "" "*"
server: * LIST (\HasNoChildren) "." "INBOX"
server: a2 OK List completed.
client: a3 EXAMINE INBOX
server: * FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
server: * OK [PERMANENTFLAGS ()] Read-only mailbox.
server: * 1 EXISTS
server: * 1 RECENT
server: * OK [UNSEEN 1] First unseen.
server: * OK [UIDVALIDITY 1257842737] UIDs valid
server: * OK [UIDNEXT 2] Predicted next UID
server: a3 OK [READ-ONLY] Select completed.
client: a4 FETCH 1 BODY[]
server: * 1 FETCH (BODY[] {405}
server: Return-Path: [email protected]
server: Received: from client.example.com ([192.0.2.1])
server:         by mx1.example.com with ESMTP
server:         id <[email protected]>
server:         for <[email protected]>; Tue, 20 Jan 2004 22:34:24 +0200
server: From: [email protected]
server: Subject: Test message
server: To: [email protected]
server: Message-Id: <[email protected]>
server: 
server: This is a test message.
server: )
server: a4 OK Fetch completed.
client: a5 LOGOUT
server: * BYE Logging out
server: a5 OK Logout completed.

This post gives you more details on syntax and examples of more of the IMAP commands:
http://wiki.mediatemple.net/w/Email_via_IMAP_using_Telnet

CloudFlare

I came across a service called CloudFlare the other day when I was investigating Content Delivery Networks (CDNs). They seem to, at the basic level, offer a high-performance, CDN for websites with no coding required, and also give you protection from Distributed Denial Of Service (DDOS) attacks. There is a paid model to use too, but the basic free service looks like something that many websites could benefit from.

I’m still trying out the service, but at first glance it seems to be pretty good. I’ve already got www.andrewc.com running with it and I’m hoping to move some over sites over in the next few days.

Classic ASP with UTF-8

I had a problem today with a very old Classic ASP page which wasn’t dealing with accented characters properly. A quick StackOverflow question came up with this:

Put the following ASP code in your page:

Response.ContentType = "text/html"
Response.AddHeader "Content-Type", "text/html;charset=UTF-8"
Response.CodePage = 65001
Response.CharSet = "UTF-8"

And make sure that the charset in the meta tag on the page also specifies UTF-8:

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />