chwala issue on debian wheezy
Aleksander Machniak
machniak at kolabsys.com
Tue Mar 3 15:20:10 CET 2015
On 03/03/2015 03:01 PM, Szota, Marcin wrote:
> i'm just guessing it's all about that size doesn't exist
Yes, it is. Here's a php script I used once to fix broken files.
<?php
$file = $_SERVER['argv'][1];
$content = file_get_contents($file);
$header = substr($content, 0, strpos($content, "\r\n\r\n"));
if (!preg_match('/X-Kolab-Type: application\/x-vnd\.kolab\.file/',
$header)) {
echo "Not a file object: $file!\n";
exit(1);
}
if (!preg_match('/boundary="([a-z0-9=_]+)"/', $header, $m)) {
echo "Boundary not found in file $file!\n";
exit(1);
}
$separator = "--" . $m[1];
$content = explode($separator, $content);
$end_part = array_pop($content);
$file_part = array_pop($content);
list($headers, $file_part) = explode("\r\n\r\n", $file_part);
// sanity check
if (!preg_match('/Content-Transfer-Encoding: base64/i', $headers)) {
echo "Malformed message [1]?!\n";
exit(1);
}
if (!preg_match('/Content-Disposition: attachment/i', $headers)) {
echo "Malformed message [2]?!\n";
exit(1);
}
if (preg_match('/[\s\t]size=/', $headers)) {
// size parameter already exists
exit;
}
// calculate size
$decoded = base64_decode($file_part);
$size = strlen($decoded);
unset($decoded);
if (!$size) {
// error or empty file
exit;
}
$headers = rtrim($headers) . ";\r\n size=$size";
// build the message back
$content = implode($content, $separator);
$content .= $separator . "\r\n";
$content .= ltrim($headers) . "\r\n\r\n";
$content .= $file_part . "\r\n\r\n";
$content .= $separator . $end_part;
// overwrite the file with new content
file_put_contents($file, $content);
?>
After executing it on every file in imap folder, you'd need to do the
mailbox/folder reconstruct and clear the Roundcube cache (kolab_cache_file).
--
Aleksander Machniak
Software Developer
Kolab Systems AG: http://kolabsys.com
PGP: 19359DC1
More information about the users
mailing list