Advertisement
Guest User

Import UIDS from mail list

a guest
May 4th, 2016
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.83 KB | None | 0 0
  1. <?php
  2.     // By Ryan Griggs - rgriggs@hilltop.net.
  3.     // GPL Licensed.
  4.     // Specify POP3 UIDL file as arg #1
  5.     // Specify dovecot-uidlist file as arg #2
  6.     // Outputs to stdout
  7.  
  8.    
  9.     $current_dir = dirname(__FILE__);
  10.    
  11.     if (count($argv) != 3) { echo "Invalid arguments."; exit(1); }
  12.     $input1 = $argv[1];
  13.     $input2 = $argv[2];
  14.    
  15.     // Open files
  16.     $f1 = fopen($input1, 'r');
  17.     $f2 = fopen($input2, 'r');
  18.    
  19.     if ($f1 == false) { echo "Could not open file $input1"; exit(1); }
  20.     if ($f2 == false) { echo "Could not open file $input2"; exit(1); }
  21.    
  22.     // Read first line of f2 and dump to output
  23.     // (this is the header of the dovecot-uidlist file)
  24.     $line = fgets($f2);
  25.     echo $line;
  26.    
  27.     // While there is input, read a line from each file and replace the UID
  28.    
  29.     while ($line = fgets($f1))
  30.     {
  31.     // Find UID in first file.
  32.     $temp = explode('.', $line);    // Format: # [UIDVALIDITY].[UID]
  33.     $uid = $temp[1];
  34.     // Remove \r and \n
  35.     $uid = str_replace("\n", '', $uid);
  36.     $uid = str_replace("\r", '', $uid);
  37.    
  38.     // Read line from 2nd file and replace UID.
  39.     $line = fgets($f2);
  40.     if (!$line) { echo "Unable to read line from $input2."; exit(1); }
  41.    
  42.     // Split into appropriate values
  43.     $temp = explode(' ', $line);    // Format: # P[UIDVALIDITY].[UID] :[filename]
  44.     $number = $temp[0];
  45.     $uidstring = $temp[1];
  46.     $filename = $temp[2];
  47.     $filename = str_replace("\n", '', $filename);   // Remove end-of-line chars.
  48.     $filename = str_replace("\r", '', $filename);
  49.    
  50.     // If numbers don't match:
  51.    
  52.     // Split uidstring (format P[UIDVALIDITY].[UID]) (discard UID)
  53.     $temp = explode('.', $uidstring);
  54.     $validity = $temp[0];
  55.    
  56.     // Build and output new string:
  57.     echo "$number $validity.$uid $filename\n";
  58.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement