Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // By Ryan Griggs - rgriggs@hilltop.net.
- // GPL Licensed.
- // Specify POP3 UIDL file as arg #1
- // Specify dovecot-uidlist file as arg #2
- // Outputs to stdout
- $current_dir = dirname(__FILE__);
- if (count($argv) != 3) { echo "Invalid arguments."; exit(1); }
- $input1 = $argv[1];
- $input2 = $argv[2];
- // Open files
- $f1 = fopen($input1, 'r');
- $f2 = fopen($input2, 'r');
- if ($f1 == false) { echo "Could not open file $input1"; exit(1); }
- if ($f2 == false) { echo "Could not open file $input2"; exit(1); }
- // Read first line of f2 and dump to output
- // (this is the header of the dovecot-uidlist file)
- $line = fgets($f2);
- echo $line;
- // While there is input, read a line from each file and replace the UID
- while ($line = fgets($f1))
- {
- // Find UID in first file.
- $temp = explode('.', $line); // Format: # [UIDVALIDITY].[UID]
- $uid = $temp[1];
- // Remove \r and \n
- $uid = str_replace("\n", '', $uid);
- $uid = str_replace("\r", '', $uid);
- // Read line from 2nd file and replace UID.
- $line = fgets($f2);
- if (!$line) { echo "Unable to read line from $input2."; exit(1); }
- // Split into appropriate values
- $temp = explode(' ', $line); // Format: # P[UIDVALIDITY].[UID] :[filename]
- $number = $temp[0];
- $uidstring = $temp[1];
- $filename = $temp[2];
- $filename = str_replace("\n", '', $filename); // Remove end-of-line chars.
- $filename = str_replace("\r", '', $filename);
- // If numbers don't match:
- // Split uidstring (format P[UIDVALIDITY].[UID]) (discard UID)
- $temp = explode('.', $uidstring);
- $validity = $temp[0];
- // Build and output new string:
- echo "$number $validity.$uid $filename\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement