Source code raw phps
<?php
$sqlink = sqlite_open('sqlite/cvslogs.sqlite');
$mbox = imap_open('{mail.colder.ch:110/pop3/tls/novalidate-cert}INBOX', 'cvslogger@colder.ch', '***');
$mbox_infos = imap_mailboxmsginfo($mbox);
echo "Found $mbox_infos->Nmsgs mails\n";
$msgInserted = 0;
if ($mbox_infos->Nmsgs == 0) {
exit;
}
foreach(imap_fetch_overview($mbox, "1:$mbox_infos->Nmsgs", 0) as $msg){
$body = imap_body($mbox, $msg->msgno);
$lines = explode("\r\n", $body);
$nlines = count($lines);
// Mark the msg as deleted
imap_delete($mbox, $msg->msgno);
// first line: cvsuser and date.
if(preg_match('/^(\w+)\s+(\w{3} \w{3} .+)$/', trim($lines[0]), $match)) {
$sender = $match[1];
$date = $match[2];
} else {
// probably not a cvs log mail
continue;
}
// Branch detection
if(preg_match('/^Modified files:\s+\(Branch: (\w+)\)$/', trim($lines[2]), $match)) {
$branch = $match[1];
} else {
$branch = 'HEAD';
}
// 4th+: modified files & log.
$inlog = false;
$modified = array();
$log = '';
for ($i = 3; $i < $nlines; $i++) {
if(!$inlog){
if (preg_match('/^(\S+)\s+(\S.+)$/', trim($lines[$i]), $match)) {
$files = explode(' ', $match[2]);
foreach($files as $file) {
$modified[] = $match[1].'/'.$file;
}
} elseif(strpos($lines[$i], 'Log:') !== false) {
$inlog = true;
continue;
}
} elseif(!preg_match('/^\s*$/', $lines[$i]) || (isset($lines[$i+1][0]) && $lines[$i+1][0] == ' ')) {
$log .= substr(rtrim($lines[$i]), 2)."\n";
} else {
break;
}
}
// check for @doc tag
$doc = false;
if (strpos($log, '@doc') !== false) {
$doc = true;
$sql_query = "INSERT INTO cvslogs (
cvsuser,
branch,
files,
log,
import_date
)
VALUES (
'".sqlite_escape_string($sender)."',
'".sqlite_escape_string($branch)."',
'".sqlite_escape_string(implode(':', $modified))."',
'".sqlite_escape_String($log)."',
datetime('now')
)";
if (sqlite_exec($sqlink, $sql_query)) {
$msgInserted++;
}
}
}
imap_expunge($mbox);
imap_close($mbox);
sqlite_close($sqlink);
echo "Inserted $msgInserted entries in the DB.\n";
Comments
There is currently no comment here.