Bcc notification emails to the request creator

Add both the request creator and the current package maintainer to the
Bcc list of notification emails for package requests.

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2014-07-16 10:47:14 +02:00
parent f8343e5a68
commit bfb253ef72

View file

@ -56,6 +56,23 @@ function pkgreq_get_pkgbase_name($id) {
return $result->fetch(PDO::FETCH_COLUMN, 0); return $result->fetch(PDO::FETCH_COLUMN, 0);
} }
/**
* Obtain the email address of the creator of a package request
*
* @param int $id Package request ID to retrieve the creator for
*
* @return int The email address of the creator
*/
function pkgreq_get_creator_email($id) {
$dbh = DB::connect();
$q = "SELECT Email FROM Users INNER JOIN PackageRequests ";
$q.= "ON Users.ID = PackageRequests.UsersID ";
$q.= "WHERE PackageRequests.ID = " . intval($id);
$result = $dbh->query($q);
return $result->fetch(PDO::FETCH_COLUMN, 0);
}
/** /**
* File a deletion/orphan request against a package base * File a deletion/orphan request against a package base
* *
@ -108,15 +125,15 @@ function pkgreq_file($ids, $type, $merge_into, $comments) {
* Send e-mail notifications. * Send e-mail notifications.
* TODO: Move notification logic to separate function where it belongs. * TODO: Move notification logic to separate function where it belongs.
*/ */
$bcc = array(pkgreq_get_creator_email($request_id));
$q = "SELECT Users.Email "; $q = "SELECT Users.Email ";
$q.= "FROM Users INNER JOIN PackageBases "; $q.= "FROM Users INNER JOIN PackageBases ";
$q.= "ON PackageBases.MaintainerUID = Users.ID "; $q.= "ON PackageBases.MaintainerUID = Users.ID ";
$q.= "WHERE PackageBases.ID = " . intval($base_id); $q.= "WHERE PackageBases.ID = " . intval($base_id);
$result = $dbh->query($q); $result = $dbh->query($q);
if ($row = $result->fetch(PDO::FETCH_ASSOC)) { if ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$bcc = $row['Email']; $bcc[] = $row['Email'];
} else {
unset($bcc);
} }
$q = "SELECT Name FROM PackageBases WHERE ID = "; $q = "SELECT Name FROM PackageBases WHERE ID = ";
@ -138,10 +155,8 @@ function pkgreq_file($ids, $type, $merge_into, $comments) {
"[2] " . $AUR_LOCATION . get_pkgbase_uri($row['Name']) . "\n"; "[2] " . $AUR_LOCATION . get_pkgbase_uri($row['Name']) . "\n";
$body = wordwrap($body, 70); $body = wordwrap($body, 70);
$headers = "MIME-Version: 1.0\r\n" . $headers = "MIME-Version: 1.0\r\n" .
"Content-type: text/plain; charset=UTF-8\r\n"; "Content-type: text/plain; charset=UTF-8\r\n" .
if (!empty($bcc)) { "Bcc: " . implode(', ', $bcc) . "\r\n";
$headers .= "Bcc: $bcc\r\n";
}
$thread_id = "<pkg-request-" . $request_id . "@aur.archlinux.org>"; $thread_id = "<pkg-request-" . $request_id . "@aur.archlinux.org>";
$headers .= "From: notify@aur.archlinux.org\r\n" . $headers .= "From: notify@aur.archlinux.org\r\n" .
"Message-ID: $thread_id\r\n" . "Message-ID: $thread_id\r\n" .
@ -194,6 +209,8 @@ function pkgreq_close($id, $reason, $comments) {
* Send e-mail notifications. * Send e-mail notifications.
* TODO: Move notification logic to separate function where it belongs. * TODO: Move notification logic to separate function where it belongs.
*/ */
$bcc = array(pkgreq_get_creator_email($id));
$q = "SELECT Users.Email "; $q = "SELECT Users.Email ";
$q.= "FROM Users INNER JOIN PackageBases "; $q.= "FROM Users INNER JOIN PackageBases ";
$q.= "ON PackageBases.MaintainerUID = Users.ID "; $q.= "ON PackageBases.MaintainerUID = Users.ID ";
@ -202,9 +219,7 @@ function pkgreq_close($id, $reason, $comments) {
$q.= "WHERE PackageRequests.ID = " . $id; $q.= "WHERE PackageRequests.ID = " . $id;
$result = $dbh->query($q); $result = $dbh->query($q);
if ($row = $result->fetch(PDO::FETCH_ASSOC)) { if ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$bcc = $row['Email']; $bcc[] = $row['Email'];
} else {
unset($bcc);
} }
/* /*
@ -224,10 +239,8 @@ function pkgreq_close($id, $reason, $comments) {
$body .= "[1] " . $AUR_LOCATION . get_user_uri($username) . "\n"; $body .= "[1] " . $AUR_LOCATION . get_user_uri($username) . "\n";
$body = wordwrap($body, 70); $body = wordwrap($body, 70);
$headers = "MIME-Version: 1.0\r\n" . $headers = "MIME-Version: 1.0\r\n" .
"Content-type: text/plain; charset=UTF-8\r\n"; "Content-type: text/plain; charset=UTF-8\r\n" .
if (!empty($bcc)) { "Bcc: " . implode(', ', $bcc) . "\r\n";
$headers .= "Bcc: $bcc\r\n";
}
$thread_id = "<pkg-request-" . $id . "@aur.archlinux.org>"; $thread_id = "<pkg-request-" . $id . "@aur.archlinux.org>";
$headers .= "From: notify@aur.archlinux.org\r\n" . $headers .= "From: notify@aur.archlinux.org\r\n" .
"In-Reply-To: $thread_id\r\n" . "In-Reply-To: $thread_id\r\n" .