Download the PHP package sfaut/zimbra without Composer
On this page you can find all versions of the php package sfaut/zimbra. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package zimbra
Short Description Search, read and send simply Zimbra messages with PHP. Attachments are managed.
License
Informations about the package zimbra
sfaut\Zimbra
Read and send simply Zimbra messages. Attachments are managed.
Based on Zimbra 8 SOAP API.
Introduction
- E-mail messages are versatile.
sfaut\Zimbra
is a relatively low-level class whose aim is to provide a simple anonymous object representing a message and its main components.sfaut\Zimbra
also provides some helper methods to send and get messages, upload and download attachments, explore directories structure, and make a search. - KISS – Fire & Forget
Composer installation
You can add sfaut\Zimbra
package to your project with Composer :
And include it as usual with autoloader :
Raw installation
sfaut\Zimbra
is an unique class with no dependancies,
so you can download /src/Zimbra.php
and include it in your script like any others scripts.
Object structure
Here is a search response structure within an array of messages. A message is an anonymous object.
Connection
Static method Zimbra::authenticate()
creates a new sfaut\Zimbra
instance and immediately connects to Zimbra server.
An exception is raised on failure.
To shorten following examples,
use
,require
and others out of scope parts will be snipped. Assumesfaut\Zimbra
is instanciate in$zimbra
.
Error management
sfaut\Zimbra
is exceptions-oriented.
So, you should encapsulate statements within try / catch / finally
blocks.
To shorten following examples, exceptions management will be snipped.
Get mailbox messages
All messages listing are, in reality, search result.
Search is performed with Zimbra::search()
method and Zimbra client search capacities.
Zimbra search tips have been archived on this gist.
Send a message
Send a message to multiple recipients
You can use arrays to specify multiple e-mail addresses :
Send a message with attachment
4th Zimbra::send()
parameter is an array of attachments.
Basically, an attachment is an anonymous object (or an array) containing 2 properties :
basename
: the name and extension of the attached filetype
: containing the attachment natur
Possible type
values are :
file
: the value represents the file full path to attachbuffer
: the value represents the raw data to attachstream
: the value is the stream resource to attach- Attachment ID : a string given when uploading a file previously
Attach a locale file to a message :
You can also attach multiple files in a row :
And you can mix different types of data sources :
Eeach attachment is uploaded while sending message.
That can be unnecessarily resource-consuming if you send multiple messages with the same attachments.
To save resources, you can first upload files with Zimbra::upload()
, then attach them to messages.
Attachments
Message attachments are specified in array $message->attachments
.
Attachments can be uploaded with Zimbra::upload()
and downloaded with Zimbra::download()
.
Each attachment is an anonymous object having the following structure :
Attachments retrieving
All attachments of a message are retrieved in an array returned by Zimbra::download()
.
Attachments are downloaded in temporary files.
These temporary files are automatically deleted at script end.
Each attachment is an anonymous object containing, among other things,
a stream
property pointing to the temporary file, and ready to read and write.
You can filter attachments to retrieve with a closure
accepting an attachment object as parameter (returning true
by default).
Real-life use case
Mass download attachments
- You need to download tons of messages CSV attachments, deadline : yesterday
- Messages are stored on mailbox in folder
/Inbox/Reports
- Each message has 0 to n attachments
- Attachments can be of any types like
.csv
,.xlsx
,.pdf
, etc., and you need to retrieve only.csv
- CSV files are named in the following format :
Report Y-m-d.csv
, eg.Report 2022-03-06.csv
- Filename, and its extension, can be in lower or upper case, or mix, you need to manage that
- You must download all CSV attachments starting
2020-01-01
, eg.Report 2019-12-31.csv
is not downloaded whereasReport 2020-01-01.csv
is downloaded - There are a lot of files, so you must save them as Gzip files
- Each message subject is unique, but each attachment name is not, so attachments downloaded must have a name in format
Message subject -- Attachment basename.gz
, eg.Report 2020-01-01.csv.gz
- Target directory is the locale subdirectory
/mailbox/reports
PHP and sfaut\Zimbra
allows you to do that easily :)
That's all Folks! 🐰