Mail_Mbox
[ class tree: Mail_Mbox ] [ index: Mail_Mbox ] [ all elements ]

Source for file modify.php

Documentation is available at modify.php

  1. <?php
  2. //modify an mbox file
  3. require_once 'Mail/Mbox.php';
  4.  
  5. //This function just lists all subjects
  6. function listSubjects($mbox) {
  7.     echo 'Mbox has ' . $mbox->size() . ' messages.' . "\n";
  8.  
  9.     for ($n = 0; $n < $mbox->size(); $n++) {
  10.         $message = $mbox->get($n);
  11.         preg_match('/Subject: (.*)$/m', $message, $matches);
  12.         $subject = $matches[1];
  13.         echo 'Mail #' . $n . ': ' . $subject . "\n";
  14.     }
  15.     echo "\n";
  16. }
  17.  
  18.  
  19. //make a copy of the demo file
  20. $original = dirname(__FILE__) . '/demobox';
  21. $file = tempnam('/tmp', 'mbox-copy-');
  22. copy($original, $file);
  23. echo 'Using file ' . $file . "\n";
  24.  
  25. $mbox = new Mail_Mbox($file);
  26. $mbox->open();
  27. listSubjects($mbox);
  28.  
  29.  
  30. echo 'append a message to the end of the box' . "\n";
  31. $message = $mbox->get(0) . "\n" . 'This is a copy of the mail';
  32. $mbox->insert($message);
  33. listSubjects($mbox);
  34.  
  35.  
  36. echo 'insert a message before the second message' . "\n";
  37. $message = $mbox->get(0) . "\n" . 'This is another copy of the mail';
  38. $mbox->insert($message, 1);
  39. listSubjects($mbox);
  40.  
  41.  
  42. echo 'remove the last message' . "\n";
  43. $mbox->remove(
  44.     $mbox->size() - 1
  45. );
  46. listSubjects($mbox);
  47.  
  48.  
  49. echo 'remove the first two messages' . "\n";
  50. $mbox->remove(array(0, 1));
  51. listSubjects($mbox);
  52.  
  53.  
  54. $mbox->close();
  55.  
  56. //remove the tmp file
  57. unlink($file);
  58. ?>

Documentation generated on Mon, 11 Mar 2019 15:35:10 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.