Subversion Repositories computer_asset_manager_v1

Rev

Rev 23 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 23 Rev 24
Line 40... Line 40...
40
 * 
40
 * 
41
 * 
41
 * 
42
 */
42
 */
43
 
43
 
44
$VERSION = '0.1';
44
$VERSION = '0.1';
45
$MAXDOWNLOAD = 5000; // maximum number of e-mails to download at one time
45
$MAXDOWNLOAD = 10000; // maximum number of e-mails to download at one time
-
 
46
$LOGGING = 1;
46
$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
47
// where to load the configuration file from
48
// where to load the configuration file from
48
$confFileName = "rsbackupRead.conf.yaml";
49
$confFileName = "rsbackupRead.conf.yaml";
49
$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() );
50
 
51
 
-
 
52
 
51
/*
53
/*
52
 * function loadConfig
54
 * function loadConfig
53
 * Parameters $confFileName - the name of the configuration file
55
 * Parameters $confFileName - the name of the configuration file
54
 *            $searchPaths - an array of paths to be searched
56
 *            $searchPaths - an array of paths to be searched
55
 * Returns    An array containing the configuration 
57
 * Returns    An array containing the configuration 
Line 166... Line 168...
166
}
168
}
167
 
169
 
168
 
170
 
169
function saveAttachments ( $attachments, $mailDate ) {
171
function saveAttachments ( $attachments, $mailDate ) {
170
   $body = '';
172
   $body = '';
-
 
173
   $saved = false;
171
   foreach ( $attachments as $thisOne ) {
174
   foreach ( $attachments as $thisOne ) {
172
      if ( $thisOne['is_attachment'] ) {
175
      if ( $thisOne['is_attachment'] ) {
173
         saveFile( makeFileName( $thisOne['filename'] ), $thisOne['attachment'], $mailDate );
176
         saveFile( makeFileName( $thisOne['filename'] ), $thisOne['attachment'], $mailDate );
-
 
177
         $saved = true;
174
      } else {
178
      } else {
175
         $body .= $thisOne['attachment'];
179
         $body .= $thisOne['attachment'];
176
      }
180
      }
177
   }
181
   }
178
   return $body;
182
   return array( $saved, $body );
179
}
183
}
180
         
184
         
181
/* function makeFileName
185
/* function makeFileName
182
 * Parameter $data
186
 * Parameter $data
183
 *           $type - the type of the file
187
 *           $type - the type of the file
Line 234... Line 238...
234
   }
238
   }
235
}
239
}
236
 
240
 
237
$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
238
 
242
 
-
 
243
 
239
foreach ( $configuration['servers'] as $thisServer ) {
244
foreach ( $configuration['servers'] as $thisServer ) {
240
   if ($MAXDOWNLOAD <= 0 ) break;
245
   if ($MAXDOWNLOAD <= 0 ) break;
241
   if ( ! $thisServer['enabled'] ) continue; // ignore anything that is not enabled
246
   if ( ! $thisServer['enabled'] ) continue; // ignore anything that is not enabled
242
   print "Working on " . $thisServer['servername'] . "\n";
247
   print "Working on " . $thisServer['servername'] . "\n";
243
   $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
Line 257... Line 262...
257
      $list = imap_list($server, $connectString, "*");
262
      $list = imap_list($server, $connectString, "*");
258
      print_r( $list ); print "\n";
263
      print_r( $list ); print "\n";
259
      continue;
264
      continue;
260
   }
265
   }
261
   $count = 0;
266
   $count = 0;
-
 
267
   $lookedAt = 0;
262
   if ( $server ) {
268
   if ( $server ) {
263
      $folderCount = imap_num_msg( $server );
269
      $folderCount = imap_num_msg( $server );
264
      for ( $num = 1; ($num <= $folderCount) && $MAXDOWNLOAD; $num++ ) {
270
      for ( $num = 1; ($num <= $folderCount) && $MAXDOWNLOAD; $num++ ) {
265
         list( $header, $attachments ) = getContents( $server, $num );
271
         list( $header, $attachments ) = getContents( $server, $num );
-
 
272
         $lookedAt++;
266
         # $mailDate = getMailDate( $header );
273
         # $mailDate = getMailDate( $header );
267
         $body = saveAttachments( $attachments, strtotime($header->date) );
274
         list($saved,$body) = saveAttachments( $attachments, strtotime($header->date) );
-
 
275
         if ( $saved ) {
268
         $messagesToDelete[] = imap_uid( $server, $num );
276
            $messagesToDelete[] = imap_uid( $server, $num );
269
         $count++;
277
            $count++;
-
 
278
            $MAXDOWNLOAD--;
-
 
279
         }
270
         if ( $CLI ) print '.'; // only do this if interactive session
280
         if ( $CLI ) print '.'; // only do this if interactive session
271
         $MAXDOWNLOAD--;
-
 
272
      } // for
281
      } // for
273
      /*
-
 
274
      if ( $thisServer['deleteProcessed'] ) {
282
      if ( $thisServer['deleteProcessed'] ) {
275
         foreach ( $messagesToDelete as $uid ) {
283
         foreach ( $messagesToDelete as $uid ) {
276
            imap_delete( $server, $uid, FT_UID ) or logError( "Can't delete [$uid]: imap_last_error()" );
284
            imap_delete( $server, $uid, FT_UID ) or logError( "Can't delete [$uid]: imap_last_error()" );
277
         }
285
         }
278
         imap_expunge( $server );
286
         imap_expunge( $server );
279
      }  // if delete
287
      }  // if delete
280
      */
-
 
281
      imap_close( $server );
288
      imap_close( $server );
282
   } else {
289
   } else {
283
      print "Could not open server " . $thisServer['servername'] . "\n";
290
      print "Could not open server " . $thisServer['servername'] . "\n";
284
   } // if..else
291
   } // if..else
285
   print "\nProcessed $count messages\n\n";
292
   print "\nLooked at $lookedAt messages, Processed $count\n\n";
286
} // outer for
293
} // outer for
287
?>
294
?>