Skip to content

Commit

Permalink
- Implemented: HTML commit mails
Browse files Browse the repository at this point in the history
  • Loading branch information
kore committed May 22, 2010
1 parent 552f6b6 commit c098bae
Showing 1 changed file with 143 additions and 7 deletions.
150 changes: 143 additions & 7 deletions src/classes/reporter/commit_mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,152 @@ class pchCommitMailReporter extends pchMailReporter
*/
public function report( pchRepository $repository, array $issues )
{
$hash = md5( microtime() );

mail(
$this->replacePlaceholders( $this->receiver, $repository ),
$this->subject . " r{$repository->version} - " . $this->getBasePath( $repository ),
"Author: {$repository->author}\n" .
"Date: {$repository->date}\n" .
"Revision: {$repository->version}\n\n" .
"Log:\n\n{$repository->log}\n\n" .
"Modified:\n{$repository->changed}\n\n" .
$repository->diff,
"From: " . $this->replacePlaceholders( $this->sender, $repository ) . "\r\n"
"--$hash\n" .
"Content-Type: text/plain; charset=\"utf-8\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$this->getTextMail( $repository ) .
"\n--$hash\n" .
"Content-Type: text/html; charset=\"utf-8\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$this->getHtmlMail( $repository ) .
"\n--$hash--\n",
"From: " . $this->replacePlaceholders( $this->sender, $repository ) . "\r\n" .
"Content-Type: multipart/alternative; boundary=\"$hash\";"
);
}

/**
* Get text mail
*
* Return contents of a text diff mail
*
* @param pchRepository $repository
* @return string
*/
protected function getTextMail( pchRepository $repository )
{
return sprintf(
"Author: %s\n" .
"Date: %s\n" .
"Revision: %s\n\n" .
"Log:\n\n%s\n\n" .
"Files changed:\n%s\n\n%s\n",
$repository->author,
$repository->date,
$repository->version,
$repository->log,
$repository->changed,
$repository->diff
);
}

/**
* Get HTML mail
*
* Return contents of a HTML diff mail
*
* @param pchRepository $repository
* @return string
*/
protected function getHtmlMail( pchRepository $repository )
{
return sprintf( '<html>
<head>
<title>SVN diff mail</title>
<style type="text/css">
dt {
width: 20%%;
font-weight: bold;
float: left;
clear: left;
}
dd {
margin-left: 21%%;
width: 79%%;
}
pre {
display: block;
white-space: pre;
font-family: monospace;
color: #000000;
}
ol.diff {
list-style-type: none;
padding: 0px;
margin: 0px;
}
ol.diff li {
padding: 0px;
margin: 0px;
font-family: monospace;
white-space: pre;
}
li.added {
background-color: #dff7c6;
color: #4e9a06;
}
li.removed {
background-color: #fccbcb;
color: #A40000;
}
li.comment {
color: #babdb5;
}
</style>
</head>
<body>
<dl>
<dt>Author</dt><dd>%s</dd>
<dt>Date</dt><dd>%s</dd>
<dt>Revision</dt><dd>%s</dd>
<dt>Log</dt><dd><pre>%s</pre></dd>
<dt>Changed</dt><dd>%s</dd>
</dl>
<ol class="diff">%s</pre>
</body>
</html>',
$repository->author,
$repository->date,
$repository->version,
$repository->log,
nl2br( $repository->changed ),
preg_replace_callback(
'(^(?P<marker>=|\\+\\+\\+|---|\\+|-|).*$)m',
function ( $matches )
{
$text = htmlspecialchars( $matches[0], ENT_QUOTES );
switch ( $matches['marker'] )
{
case '=':
case '+++':
case '---':
return '<li class="comment">' . $text . '</li>';

case '+':
return '<li class="added">' . $text . '</li>';

case '-':
return '<li class="removed">' . $text . '</li>';

default:
return '<li>' . $text . '</li>';
}
},
$repository->diff
)
);
}

Expand Down

0 comments on commit c098bae

Please sign in to comment.