CGI and Perl

MIME attachment

From - Mon Jan 13 01:50:26 1997
 Return-Path: <ckemp@ro.com>
 Received: from chris (ts8p1.ro.com [205.216.92.168])
           by sh1.ro.com (8.8.4/8.8.4) with SMTP
   id CAA12517 for <ckemp@ro.com>; Mon, 13 Jan 1997 02:50:08 -0600
 Message-ID: <32DA04C3.75E@ro.com>
 Date: Mon, 13 Jan 1997 01:47:47 -0800
 From: Chris Kemp <ckemp@ro.com>
 Reply-To: ckemp@ro.com
 Organization: Silicon Graphics
 X-Mailer: Mozilla 3.01 (Win95; I)
 MIME-Version: 1.0
 To: ckemp@ro.com
 Subject: MIME Test
 Content-Type: multipart/mixed; boundary="------------6B797646304"
 X-UIDL: 48f2146a82b1f706edbd5e7c350b352a
 X-Mozilla-Status: 0001
 This is a multi-part message in MIME format.
 --------------6B797646304
 Content-Type: text/plain; charset=us-ascii
 Content-Transfer-Encoding: 7bit
 Chris,
 I have attached a picture of the Boeing F-22 to this message.
 --------------6B797646304
 Content-Type: image/jpeg; name="F22.jpg"
 Content-Transfer-Encoding: base64
 Content-Disposition: inline; filename="F22.jpg"
 /9j/4AAQSkZJRgABAgEASABIAAD/7QG4UGhvdG9zaG9wIDMuMAA4QklNA+kAAAAAAHgAAwAA
 AEgASAAAAAAC2gIo/+H/4gL5AkYDRwUoA/wAAgAAAEgASAAAAAAC2AIoAAEAAABkAAAAAQAD
 AwMAAAABJw8AAQABAAAAAAAAAAAAAAAAYAgAGQGQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
 AAAAAAAAAAA4QklNA+0AAAAAABAASAAAAAEAAQBIAAAAAQABOEJJTQPzAAAAAAAIAAAAAAAA
 AAA4QklNJxAAAAAAAAoAAQAAAAAAAAACOEJJTQP1AAAAAABIAC9mZgABAGxmZgAGAAAAAAAB
 AC9mZgABAKGZmgAGAAAAAAABADIAAAABAFoAAAAGAAAAAAABADUAAAABAC0AAAAGAAAAAAAB
 OEJJTQP4AAAAAABwAAD/////////////////////////////A+gAAAAA////////////////
 /////////////wPoAAAAAP////////////////////////////8D6AAAAAD/////////////
 ////////////////A+gAADhCSU0EBgAAAAAAAgAG/+4ADkFkb2JlAGQAAAAAAf/bAIQAAgIC
 AgICAgICAgMCAgIDBAMCAgMEBQQEBAQEBQYFBQUFBQUGBgcHCAcHBgkJCgoJCQwMDAwMDAwM
 DAwMDAwMDAEDAwMFBAUJBgYJDQoJCg0PDg4ODg8PDAwMDAwPDwwMDAwMDA8MDAwMDAwMDAwM
 DAwMDAwMDAwMDAwMDAwMDAwM/8AAEQgCWAMYAwERAAIRAQMRAf/EAaIAAAAHAQEBAQEAAAAA
 AAAAAAQFAwIGAQAHCAkKCwEAAgIDAQEBAQEAAAAAAAAAAQACAwQFBgcICQoLEAACAQMDAgQC
 BgcDBAIGAnMBAgMRBAAFIRIxQVEGE2EicYEUMpGhBxWxQiPBUtHhMxZi8CRygvElQzRTkqKy
 Y3PCNUQnk6OzNhdUZHTD0uIIJoMJChgZhJRFRqS0VtNVKBry4/PE1OT0ZXWFlaW1xdXl9WZ2
 hpamtsbW5vY3R1dnd4eXp7fH1+f3OEhYaHiImKi4yNjo+Ck5SVlpeYmZqbnJ2en5KjpKWmp6
 ipqqusra6voRAAICAQIDBQUEBQYECAMDbQEAAhEDBCESMUEFURNhIgZxgZEyobHwFMHR4SNC
 FVJicvEzJDRDghaSUyWiY7LCB3PSNeJEgxdUkwgJChgZJjZFGidkdFU38qOzwygp0+PzhJSk
 tMTU5PRldYWVpbXF1eX1RlZmdoaWprbG1ub2R1dnd4eXp7fH1+f3OEhYaHiImKi4yNjo+DlJ
 WWl5iZmpucnZ6fkqOkpaanqKmqq6ytrq+v/dAAQAY//aAAwDAQACEQMRAD8A/P8A4q7FXYq7
 <a few hundred K of encoded data removed>
 sS+TZPzi8xpdeS/Jmoana6tf6VYteahqd8v1ixlmto4bi91KSRI45P8AX4tir9CMVdirsVdi
 rsVdirsVdirsVdirsVdirsVdirsVdirsVdirsVdirsVdirsVdirsVdirsVdirsVdirsVdirs
 VdirsVdirsVdirsVeRfn5y/5UX+dHH7X+BPMVP8AuGXGLCX0v//Z
 --------------6B797646304--

Notice the MIME content type declarations throughout the message. A practical application of the Mime::Base64 decode_base64 function would be extracting the encoded data to a file. Using this method, you could allow users to submit pictures via e-mail of items that could be integrated into a Web page.

Using MIME::QuotedPrint

Mime::QuotedPrint includes the functions encode_qp and decode_qp that function in the same way as their Base64 counterparts. The syntax is as follows:

$encoded = encode_yp($decoded);
 $decoded = decode_yp($encoded);

MIME is significant to the Web programmer in two main ways. MIME and its different data types define standard types of data that can be transmitted as part of a document. MIME headers are used in every HTTP transaction, thus a familiarity with them is essential in advanced applications where your program must generate headers. MIME encoding schemes allow binary data to be included in text messages that can be transported over older e-mail (not HTTP) gateways.

Simple PleasuresExamples

  • Guest Book
  • Hit Counter
  • Clickable Maps
  • Text File Search
  • E-Mail Notification

This chapter will provide several examples of things that all Webmasters might want to incorporate into their Web sites. It will, hopefully, illustrate the power of Perl and prove why Perl has become the de facto standard when it comes to CGI programming. All of these examples involve server-side CGI programs, and they are ubiquitous real-world programs out on the World Wide Web.

You have already learned the basics of Perl5 and how the WWW libraries are used. It is now time to put what you've learned to practical use. You will see how to implement a guest book, a page hit counter, a clickable image map, a text file searching program, and an automatic e-mail notification script.