Line 40... |
Line 40... |
40 |
*
|
40 |
*
|
41 |
*
|
41 |
*
|
42 |
*/
|
42 |
*/
|
43 |
|
43 |
|
44 |
$VERSION = '0.1';
|
44 |
$VERSION = '0.1';
|
45 |
$MAXDOWNLOAD = 10000; // maximum number of e-mails to download at one time
|
45 |
$configuration['maxemail'] = 10000; // maximum number of e-mails to download at one time
|
46 |
$LOGGING = 1;
|
46 |
$LOGGING = 1;
|
47 |
$CLI = isset( $_SERVER["TERM"]); // only set if we are not in a cron job
|
47 |
$CLI = isset( $_SERVER["TERM"]); // only set if we are not in a cron job
|
48 |
// where to load the configuration file from
|
48 |
// where to load the configuration file from
|
49 |
$confFileName = "rsbackupRead.conf.yaml";
|
49 |
$confFileName = "rsbackupRead.conf.yaml";
|
50 |
$searchPaths = array( '/etc/camp', '/opt/camp', '/opt/camp/backups', $_SERVER['SCRIPT_FILENAME'], getcwd() );
|
50 |
$searchPaths = array( '/etc/camp', '/opt/camp', '/opt/camp/backups', $_SERVER['SCRIPT_FILENAME'], getcwd() );
|
Line 240... |
Line 240... |
240 |
|
240 |
|
241 |
$listMailboxes = isset( $argv[1] ) ; // anything passed on cli results in a list of mailboxes instead of the job
|
241 |
$listMailboxes = isset( $argv[1] ) ; // anything passed on cli results in a list of mailboxes instead of the job
|
242 |
|
242 |
|
243 |
|
243 |
|
244 |
foreach ( $configuration['servers'] as $thisServer ) {
|
244 |
foreach ( $configuration['servers'] as $thisServer ) {
|
245 |
if ($MAXDOWNLOAD <= 0 ) break;
|
245 |
if ($configuration['maxemail'] <= 0 ) break;
|
246 |
if ( ! $thisServer['enabled'] ) continue; // ignore anything that is not enabled
|
246 |
if ( ! $thisServer['enabled'] ) continue; // ignore anything that is not enabled
|
247 |
print "Working on " . $thisServer['servername'] . "\n";
|
247 |
print "Working on " . $thisServer['servername'] . "\n";
|
248 |
$messagesToDelete = array(); // trap the UID's of messages to delete, more accurate than using message number
|
248 |
$messagesToDelete = array(); // trap the UID's of messages to delete, more accurate than using message number
|
249 |
print "Opening " . $thisServer['servername'] . "\n";
|
249 |
print "Opening " . $thisServer['servername'] . "\n";
|
250 |
|
250 |
|
Line 265... |
Line 265... |
265 |
}
|
265 |
}
|
266 |
$count = 0;
|
266 |
$count = 0;
|
267 |
$lookedAt = 0;
|
267 |
$lookedAt = 0;
|
268 |
if ( $server ) {
|
268 |
if ( $server ) {
|
269 |
$folderCount = imap_num_msg( $server );
|
269 |
$folderCount = imap_num_msg( $server );
|
270 |
for ( $num = 1; ($num <= $folderCount) && $MAXDOWNLOAD; $num++ ) {
|
270 |
for ( $num = 1; ($num <= $folderCount) && $count < $configuration['maxemail']; $num++ ) {
|
271 |
list( $header, $attachments ) = getContents( $server, $num );
|
271 |
list( $header, $attachments ) = getContents( $server, $num );
|
272 |
$lookedAt++;
|
272 |
$lookedAt++;
|
273 |
# $mailDate = getMailDate( $header );
|
273 |
# $mailDate = getMailDate( $header );
|
274 |
list($saved,$body) = saveAttachments( $attachments, strtotime($header->date) );
|
274 |
list($saved,$body) = saveAttachments( $attachments, strtotime($header->date) );
|
275 |
if ( $saved ) {
|
275 |
if ( $saved ) {
|
276 |
$messagesToDelete[] = imap_uid( $server, $num );
|
276 |
$messagesToDelete[] = imap_uid( $server, $num );
|
277 |
$count++;
|
277 |
$count++;
|
278 |
$MAXDOWNLOAD--;
|
- |
|
279 |
}
|
278 |
}
|
280 |
if ( $CLI ) print '.'; // only do this if interactive session
|
279 |
if ( $CLI ) print '.'; // only do this if interactive session
|
281 |
} // for
|
280 |
} // for
|
282 |
if ( $thisServer['deleteProcessed'] ) {
|
281 |
if ( $thisServer['deleteProcessed'] ) {
|
283 |
foreach ( $messagesToDelete as $uid ) {
|
282 |
foreach ( $messagesToDelete as $uid ) {
|