• No results found

Enhancing the Download Manager

In document The Art Of Java pdf (Page 134-137)

The Download Manager as it stands is fully functional, with the ability to pause and resume downloads as well as download multiple files at once; however, there are several enhancements that you may want to try on your own. Here are some ideas: proxy server support, FTP and HTTPS support, and drag-and-drop support. A particularly appealing enhancement is a scheduling feature that lets you schedule a download at a specific time, perhaps in the middle of the night when system resources are plentiful.

Note that the techniques illustrated in this chapter are not limited to downloading files in the typical sense. There are many other practical uses for the code. For example, many software programs distributed over the Internet come in two pieces. The first piece is a small, compact application that can be downloaded quickly. This small application contains a mini download manager for downloading the second piece, which is generally much larger. This concept is quite useful, especially as the size of applications increases, which typically leads to an increase in the potential for download interruptions. You might want to try adapting the Download Manager for this purpose.

CHAPTER

5

Implementing an E-mail

Client in Java

By James Holmes

121

ApDev TIGHT /The Art of Java / Schildt/Holmes / 222971-3 /

P:\010Comp\ApDev\971-3\ch05.vp Monday, July 07, 2003 5:18:53 PM

Color profile: Generic CMYK printer profile Composite Default screen

A

s all readers know, there are two primary uses of the Internet: web browsing and e-mail. Although browsing the Web is certainly the more glamorous of the two, it is e-mail that many users have come to rely on. Because e-mail offers a low-cost, high-speed alternative to regular mail and flexibility that is not available with telephone calls, it has become the communication means of choice for many today.

Despite the pervasiveness of e-mail and its importance to the Internet, few programmers know much about how it actually works or how to write applications that use it. Frankly, the ability to send and receive e-mail messages under your direct program control is potentially very valuable. For example, consider an application that monitors the temperature of a commercial freezer. You might want this application to send an e-mail to the plant manager automatically if the temperature rises above zero. Furthermore, you might want to create a specialized e-mail client for the plant manager that monitors all e-mail and sounds an alarm if an e-mail from the freezer is seen.

In addition to dedicated uses of e-mail, such as that just described, there is another reason why you might want the ability to take direct control of e-mail: security. E-mail has evolved significantly from its beginnings where it consisted solely of plaintext messages. Today, e-mail supports much richer formats such as HTML laden with graphics and sounds. It also supports file attachments for transporting data with messages. The trouble is that these extra features and formats have been exploited by malicious programmers who see e-mail as a convenient means of delivering computer viruses, Trojan horses, and the like.

Although today’s commercial e-mail programs offer up solutions to combat viruses, with each countermeasure comes a new threat. An alternative approach to the problem is to use an e-mail application that simply receives e-mail but does not take any further action involving its contents. A simple e-mail client that does not render HTML, does not display a graphic, does not preview a photo, and does not play a sound file removes much of the potential for exploitation or threat. Of course, such a solution is not acceptable for the world at large, but such an e-mail client might be quite useful in certain cases—especially in situations in which a cyberattack is ongoing.

Whatever the purpose, the ability to take full control over e-mail is a valuable skill that will find its way into a wide array of applications. Although programming an e-mail application can be difficult, Java—and the JavaMail API—make it easier. In this chapter a simple, text-only e-mail client is developed. The e-mail client serves two purposes. First, it is a fully functional e-mail application that can send and receive text-based messages. It takes no action with other types of content. Thus, it is usable “as is” when such a minimalist e-mail program is required. Second, it demonstrates the techniques needed to send and receive e-mail. You can adapt these techniques for use in your own code.

E-mail Behind the Scenes

Behind the scenes, e-mail is little more than standard client/server networking; there are e-mail clients that communicate with e-mail servers for sending and receiving e-mail messages. E-mail clients come in several varieties, from stand-alone computer applications like the one in this chapter to cell phones that have the ability to receive e-mail messages. Regardless

what client is used, it will connect to an e-mail server to transfer e-mail messages, be it to or from the server. Communications between e-mail clients and servers follow defined protocols so that virtually all clients and servers are compatible with one another. There are two protocols for receiving e-mail messages: POP3 and IMAP. SMTP is the dominant protocol for sending e-mail. Each of these protocols is explained in the following sections.

POP3

Post Office Protocol version 3 (POP3) is the dominant protocol for retrieving e-mail from e-mail servers on the Internet. POP3 is very basic, allowing e-mail clients to access only mail in a default “Inbox” folder.

IMAP

Internet Message Access Protocol (IMAP) is another protocol for retrieving e-mail from e-mail servers on the Internet. IMAP has more features than POP and supports retrieving messages from multiple accounts and folders. IMAP also supports the use of public folders where messages are shared.

SMTP

Simple Mail Transfer Protocol (SMTP) is a protocol for sending e-mail on the Internet. When you send a message with SMTP, a server receives the message and then routes it to the recipient’s mail server. The message is then available for reading with POP3 or IMAP.

In document The Art Of Java pdf (Page 134-137)