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

Class: Mail_Mbox

Source Location: /Mail_Mbox-0.3.0/mbox.php

Class Overview

PEAR
   |
   --Mail_Mbox

Mbox PHP class to Unix MBOX parsing and using


Author(s):

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 146]
Mbox PHP class to Unix MBOX parsing and using

METHODS: int resource mbox->open(string file) open a mbox and return a resource id

bool mbox->close(resource) close a mbox resource id

int mbox->size(resource) return mbox number of messages

string mbox->get(int resource, messageNumber) return the message number of the resource

bool mbox->update(int resource, int messageNumber, string message) update the message offset to message (need write permission)

bool mbox->remove(int resource, int messageNumber) remove the message messageNumber (need write permission)

bool mbox->insert(int resource, string message[, $offset = null]) add message to the end of the mbox. Offset == 0 message will be append at first message. If after == null will be the last one message. (need write permission)

RELATED LINKS:

  • CPAN Perl Mail::Folder::Mbox Module Used as a start point to create this class. http://search.cpan.org/author/KJOHNSON/MailFolder-0.07/Mail/Folder/Mbox.pm
  • PHP Mime Decode PEAR Module Use it to parse headers and body. http://pear.php.net/package-info.php?pacid=21
EXAMPLE: // some random content $content = <<<EOF From Foo@example.com Fri Dec 27 14:31:10 2002 Return-Path: Received: from [unix socket] by campos.example.com (LMTP); Fri, 27 Dec 2002 14:31:10 -0200 (BRST) Date: Fri, 27 Dec 2002 14:31:21 -0500 Message-Id: <200212271931.gBRJVL012289@example.com> Received: from pcp128525pcs.foo.example.com ( pcp128525pcs.example.com [99.99.99.99]) by/ serjolen6com.example.com (v64.19) with ESMTP id MAILRELAYINZA98-3601058302; Fri, 08 Nov 2002 06:39:05 -0500 From: "Foo@example.com" To: fool@example.com Subject: This is A SPAM!! Content-Type: text/plan

testing foo spam EOF;

// starting mbox require_once "mbox.php"; $mbox = new Mail_Mbox();

// uncomment to see lots of things #$mbox->debug = true;

// opennign file mbox $mid = $mbox->open("mbox");

// uncomment to see internal vars #print_r($mbox);

// deleting a message (uncomment to test) #$res1 = $mbox->remove($mid,0); if (PEAR::isError($res1)) { print $res1->getMessage(); }

// changing a message (uncomment to test) #$res2 = $mbox->update($mid,0,$content); if (PEAR::isError($res2)) { print $res2->getMessage(); }

// adding a message (uncomment to test) $res3 = $mbox->insert($mid,$content,0); if (PEAR::isError($res3)) { print $res3->getMessage(); }

require_once "Mail/mimeDecode.php"; // showing current messages with Mail Mime for ($x = 0; $x < $mbox->size($mid); $x++) { printf("Message: %08d

",$x);
        $thisMessage     = $mbox->get($mid,$x);
        print $thisMessage;
        print "
"; $decode = new Mail_mimeDecode($thisMessage, "\r\n"); $structure = $decode->decode(); print_r($structure); print "
<hr /><hr /><hr />"; }



[ Top ]


Class Variables

$debug =  false

[line 167]

Debug mode

Set to true to turn on debug mode

  • Access: public

Type:   bool


[ Top ]



Method Detail

close   [line 215]

mixed close( int $resourceId)

Close a Mbox

Close the Mbox file opened by open()

  • Return: true on success else pear error class
  • Access: public

Parameters:

int   $resourceId   —  Mbox resouce id created by open

[ Top ]

get   [line 259]

string get( int $resourceId, int $message)

Mbox Get

Get a Message from Mbox

Note: Message number start from 0.

  • Return: Return the message else pear error class
  • Access: public

Parameters:

int   $resourceId   —  Mbox resouce id created by open
int   $message   —  The number of Message

[ Top ]

insert   [line 415]

mixed insert( int $resourceId, string $content, [int $offset = NULL])

Insert a message

PEAR::Mail_Mbox will insert the message according its offset.

  1. means before the actual message 0. 3 means before the message 3
(Remember: message 3 is the forth message). The default is put AFTER the last message.

Note: PEAR::Mail_Mbox auto adds \n\n at end of the message

  • Return: Return true else pear error class
  • Access: public

Parameters:

int   $resourceId   —  Mbox resouce id created by open
string   $content   —  The content of the new Message
int   $offset   —  offset Before the offset. Default: last message

[ Top ]

open   [line 181]

mixed open( int $file)

Open a Mbox

Open the Mbox file and return an resource identificator.

Also, this function will process the Mbox and create a cache that tells each message start and end bytes.

  • Return: ResourceID on success else pear error class
  • Access: public

Parameters:

int   $file   —  Mbox file to open

[ Top ]

remove   [line 301]

mixed remove( int $resourceId, int $message)

Delete Message

Remove a message from Mbox and save it.

Note: messages start with 0.

  • Return: Return true else pear error class
  • Access: public

Parameters:

int   $resourceId   —  Mbox resouce id created by open
int   $message   —  The number of Message to remove, or array of message ids to remove

[ Top ]

size   [line 238]

int size( int $resourceId)

Mbox Size

Get Mbox Number of Messages

  • Return: Number of messages on Mbox (starting on 1,
    1. if no message exists)
  • Access: public

Parameters:

int   $resourceId   —  Mbox resouce id created by open

[ Top ]

update   [line 362]

mixed update( int $resourceId, int $message, string $content)

Update a message

Note: Mail_Mbox auto adds \n\n at end of the message

Note: messages start with 0.

  • Return: Return true else pear error class
  • Access: public

Parameters:

int   $resourceId   —  Mbox resouce id created by open
int   $message   —  The number of Message to updated
string   $content   —  The new content of the Message

[ Top ]


Documentation generated on Mon, 11 Mar 2019 13:58:17 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.