-- MySQL dump 9.11 -- -- Host: localhost Database: mylist -- ------------------------------------------------------ -- Server version 4.0.24_Debian-2-log -- -- Dumping data for table `mylist_administrators` -- INSERT INTO `mylist_administrators` VALUES (4); INSERT INTO `mylist_administrators` VALUES (7); -- -- Dumping data for table `mylist_list_stats` -- INSERT INTO `mylist_list_stats` VALUES (9,'2005-03-22 03:47:31','2005-03-22 03:47:31',0); INSERT INTO `mylist_list_stats` VALUES (10,'2005-03-22 03:58:21','2005-03-22 03:58:21',0); -- -- Dumping data for table `mylist_list_users` -- INSERT INTO `mylist_list_users` VALUES (10,2,'',0); INSERT INTO `mylist_list_users` VALUES (10,3,'',0); INSERT INTO `mylist_list_users` VALUES (13,6,'rajo@platon.sk',1); INSERT INTO `mylist_list_users` VALUES (9,6,'rajo@platon.sk',0); INSERT INTO `mylist_list_users` VALUES (13,5,'nepto@platon.sk',0); INSERT INTO `mylist_list_users` VALUES (9,5,'nepto@platon.sk',0); INSERT INTO `mylist_list_users` VALUES (13,7,'majo.tt@pobox.sk',0); -- -- Dumping data for table `mylist_lists` -- INSERT INTO `mylist_lists` VALUES (9,4,'test1@lists.platon.sk','testovaci ml1 uprava','dlhsi popis, \r\nlalalalaa\r\n\r\n uprava',1,1,1,1,1,1,1,100,100,1,1,'Platon2','___________________________________\ntoto je testovacia signatura'); INSERT INTO `mylist_lists` VALUES (10,0,'test2@lists.platon.sk','testovaci2','',1,1,1,1,0,1,1,100,0,1,1,'Test2','___________________________________\ntoto je testovacia signatura'); INSERT INTO `mylist_lists` VALUES (11,5,'test3@lists.platon.sk','test3','',1,1,1,1,1,1,1,0,0,1,1,'','___________________________________\ntoto je testovacia signatura'); INSERT INTO `mylist_lists` VALUES (12,0,'test4@platon.sk','','',1,1,1,1,0,1,1,0,0,1,1,'','___________________________________\ntoto je testovacia signatura'); INSERT INTO `mylist_lists` VALUES (13,0,'prilohy@platon.sk','','',1,1,1,1,0,1,0,0,0,1,1,'Test Priloh','___________________________________\r\ntoto je testovacia signatura'); INSERT INTO `mylist_lists` VALUES (14,5,'platon@pobox.sk','testujem online','dfdsafd',0,0,1,1,0,1,0,10000,10000,1,0,'','___________________________________\r\ntoto je testovacia signatura'); -- -- Dumping data for table `mylist_message_atts` -- INSERT INTO `mylist_message_atts` VALUES (23,307,'application/octet-stream','','1113050812_1894056334','avgun.log'); INSERT INTO `mylist_message_atts` VALUES (24,307,'image/jpeg','','1113050812_499357718','corner_t.jpg'); INSERT INTO `mylist_message_atts` VALUES (25,308,'application/octet-stream','','1113050817_1098994806','mylist.config.php'); INSERT INTO `mylist_message_atts` VALUES (26,308,'application/x-zip-compressed','','1113050817_281890025','mylist.config.zip'); INSERT INTO `mylist_message_atts` VALUES (27,309,'text/plain','lalala\r\nkde bolo tam bolo\r\nbolo i tam kde nic nebolo?\r\ntam nemohlo byt :o)\r\nsi ty ale trubka, Majo','','a.txt'); INSERT INTO `mylist_message_atts` VALUES (28,310,'application/octet-stream','','1113050828_1209434566','žiadosť.doc'); INSERT INTO `mylist_message_atts` VALUES (29,311,'text/html','\r\n\r\n
| \r\n | ||||
| \r\n You are in: Home \r\n > Articles \r\n > PHP: PEAR mimeDecode Module | ||||
| \r\n \r\n \r\n Free \r\n Web Design Quotation \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\nArticles & Tutorials\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\nOther Resources\r\n \r\n \r\n | \r\n \r\n PHP: PEAR mimeDecode Module\r\n
While most MIME email is totally useless, it would be better if it was \r\n sent as a plain text message, MIME sometimes is useful. When sending \r\n attachments, for example. In this article, we will see how we can decode \r\n MIME messages with PHP. \r\nWe will use the mimeDecode module to do the actual decoding for us. \r\n mimeDecode is part of the PEAR library. \r\n PEAR is already installed if you have a newer version of PHP, but if you \r\n don\'t it\'s also easy to install. \r\nHow to get PEAR and mimeDecode\r\nBefore trying to install PEAR and the mimeDecode module, you should \r\n first make sure that you don\'t yet have it. If you have a recent version \r\n of PHP (> 4.3.0pre1), the PEAR base installation is already installed \r\n on your system. Since the mimeDecode module is part of the PEAR core, \r\n that\'s also installed. To check whether you have to install the mimeDecode \r\n or not, you can run the following PHP script: <?php\r\ninclude(\'Mail/mimeDecode.php\');\r\n?>\r\n\r\n If this doesn\'t give an error, you the mimeDecode module is installed \r\n on your system. If it does, you\'ll have to install PEAR (or upgrade your \r\n version of PHP). Read the PEAR manual for \r\n instructions. \r\nMIME: an introduction\r\nBefore you can successfully write a script that decodes MIME email, \r\n you\'ll have to know a little about the anatomy of a MIME message. I\'ll \r\n give you a short introduction to MIME. If you want to read more about the \r\n details of MIME, there is a chapter \r\n available from O\'Reilly. \r\nA tradition email\r\nThe source of a basic, non-MIME email looks like this: From: Gijs van Tulder <gvtulder@example.com>\r\nTo: thelist@lists.evolt.org\r\nSubject: Decoding MIME mail\r\nDate: Wed, 12 Mar 2003 10:26:59 +0100\r\n\r\nHi, this is my message.\r\n\r\n The first lines of this email contain headers, data about this message. \r\n These headers consist of a header name, before the colon, and some data, \r\n after the colon. (If you are familiar with the HTTP headers, you\'ll notice \r\n that email headers use the same syntax.) There are actually many more \r\n possible headers that I didn\'t include in this example, but all headers \r\n are in the form The body of the message, in our example A MIME email\r\nWe\'ll now see what happens with our message when we add a MIME \r\n attachment to it. From: Gijs van Tulder <gvtulder@example.com>\r\nTo: thelist@lists.evolt.org\r\nSubject: Decoding MIME mail\r\nDate: Wed, 12 Mar 2003 10:26:59 +0100\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"MyBoundary\"\r\n\r\nThis is a multi-part message in MIME format.\r\n\r\n--MyBoundary\r\nContent-Type: text/plain; charset=\"iso-8859-1\"\r\nContent-Transfer-Encoding: 7bit\r\n\r\nHi, this is my message. See the attached image!\r\n\r\n--MyBoundary\r\nContent-Type: image/gif; name=\"myimage.gif\"\r\nContent-Transfer-Encoding: base64\r\nContent-Disposition: attachment; filename=\"myimage.gif\"\r\n\r\nR0lGODlhogBrAPcAAAAAAP///zwKC2UhIrdPUKU0OMmLjagEDJIEDZEmLduztW8HD64YJlUJEXkX\r\n...omitted many lines like the above...\r\ngahQUgx4n5kQWQQJ0sqEREAAADs=\r\n\r\n--MyBoundary--\r\n\r\n As you can see, our message now contains two different parts: the \r\n message body, Note that this boundary can be set to any possible string. It\'s fairly \r\n obvious that normal mail programs don\'t use \'MyBoundary\' as the boundary \r\n string, but take a longer random string. It still has the same effect, \r\n though. \r\nThe MIME parts\r\nNow, let\'s take a look at the MIME parts. You\'ll notice that these \r\n parts look a lot like the email message: it starts with a number of \r\n headers, followed by an empty line and then there is the body. Content-Type: image/gif; name=\"myimage.gif\"\r\nContent-Transfer-Encoding: base64\r\nContent-Disposition: attachment; filename=\"myimage.gif\"\r\n\r\nR0lGODlhogBrAPcAAAAAAP///zwKC2UhIrdPUKU0OMmLjagEDJIEDZEmLduztW8HD64YJlUJEXkX\r\n...omitted many lines like the above...\r\ngahQUgx4n5kQWQQJ0sqEREAAADs=\r\n\r\n This is the MIME part containing the attached image. You see the \r\n The body of this part looks very strange. Many similar lines followed \r\n the first line of characters, but I deleted them except from the last \r\n line. What you see here is an encoded version of the original file. Since \r\n an email message can only contain normal text, the binary form of the \r\n image had to be translated to a text form. This is called MIME encoding. \r\n The Decoding the message\r\nNow that we know a little about MIME email, we can almost start writing \r\n the script. But wait, you\'ll first have to get a message that your script \r\n can parse. If you\'re using Linux/Unix, you can send yourself a MIME email \r\n and copy your mbox file to get the source of that message. You can also \r\n set up a email \r\n to PHP script to get the message source. If you just want to test the \r\n mimeDecode module, you can also just download the source of my example \r\n message. In this example script, I will assume that the source email \r\n is saved as Initialising mimeDecode\r\nTo load the mimeDecode module, we just have to include \r\n include(\'mail/mimeDecode\');\r\n\r\n Setting the parameters\r\nThe mimeDecode module accepts five parameters. \r\n The fourth parameter, $params[\'include_bodies\'] = true;\r\n$params[\'decode_bodies\'] = true;\r\n$params[\'decode_headers\'] = true;\r\n$params[\'input\'] = $input;\r\n\r\n Running decode()\r\nIt\'s time to run mimeDecode\'s $structure = Mail_mimeDecode::decode($params);\r\n\r\n The decoded message is saved in The mimeDecode output\r\nWe\'ve now got the decoded message in the
Saving all attached files\r\nWe can now walk through the foreach ($structure->parts as $part) {\r\n // only save if an attachment\r\n if (isset($part->disposition) and\r\n ($part->disposition==\'attachment\') {\r\n // open file\r\n $fp = fopen($part->ctype_parameters[\'filename\'], \'w\');\r\n // write body\r\n fwrite($fp, $part->body);\r\n // close file\r\n fclose($fp);\r\n }\r\n}\r\n\r\n For each part, we check if it has a Listing all images\r\nIn the same way, we can list all images and their sizes by checking the \r\n $list = \'\';\r\nforeach ($structure->parts as $part) {\r\n // is this an image?\r\n if ($part->ctype_primary==\'image\') {\r\n $list .= $part->ctype_parameters[\'filename\'].\': \'.\r\n strlen($part->body).\" bytes\\n\";\r\n }\r\n}\r\n// send this list\r\n$to = $structure->headers[\'from\'];\r\n$subject = \'Re: \'.$structure->headers[\'subject\'];\r\n$body = \"You sent us these images:\\n\\n$list\\n\\nThank you very much!\";\r\n$headers = \'From: \'.$structure->headers[\'to\'];\r\nmail($to, $subject, $body, $headers);\r\n\r\n If the What\'s next?\r\nBy now, you should be able to write your own scripts using the \r\n mimeDecode module. You could, for example, write a script that lets you \r\n just email images and get them published on your web log. In the rare \r\n event that you are a teacher, you could save all documents that your \r\n students send you in your \'incoming files\' directory, without having to \r\n open each message first. \r\n\r\n \r\n \r\n\r\n \r\n \r\n\r\n \r\n Gijs is a full time Dutch student in economics and a spare time Web \r\n developer. He spends his time developing scripts using PHP, MySQL and \r\n other external programs. \r\nVisit his site at: http://gvtulder.f2o.org/ \r\n\r\n | \r\n \r\n \r\n \r\n
Logo Design Works Logo \r\n Design Discussweb web design forum is a great place for you to discuss \r\n anything and everything about web development. Info Creek Website Development Company Professional web design company \r\n at great rates A2 \r\n Hosting Web Hosting from $4.95/m PHP4&5/MySQL 4.1 / PostgreSQL / \r\n cPanel / Shell & more! 30 day money back guarantee. Iniquinet Web Hosting Web Design Directory\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n | ||
| \r\n \r\n Web Design Companies, Web Design Services, Web Design \r\n ResourcesCopyright The UK Web Design Company (UKWDC), London, UK \r\n 2003-2005 All rights reserved | ||||