[aur-dev] [PATCH 4/6] Send notification mail when closing a request

Lukas Fleischer archlinux at cryptocrack.de
Wed Jun 25 15:58:59 EDT 2014


The mail is sent to the request mailing list and to the current package
maintainer.

Signed-off-by: Lukas Fleischer <archlinux at cryptocrack.de>
---
 web/lib/pkgbasefuncs.inc.php | 45 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php
index bab8f4c..339cd7e 100644
--- a/web/lib/pkgbasefuncs.inc.php
+++ b/web/lib/pkgbasefuncs.inc.php
@@ -1093,11 +1093,16 @@ function pkgbase_file_request($ids, $type, $merge_into, $comments) {
 /**
  * Close a deletion/orphan request
  *
+ * @global string $AUR_LOCATION The AUR's URL used for notification e-mails
+ * @global string $AUR_REQUEST_ML The request notification mailing list
  * @param int $id The package request to close
  *
  * @return void
  */
 function pkgbase_close_request($id) {
+	global $AUR_LOCATION;
+	global $AUR_REQUEST_ML;
+
 	$dbh = DB::connect();
 
 	if (!check_user_privileges()) {
@@ -1107,5 +1112,45 @@ function pkgbase_close_request($id) {
 	$q = "UPDATE PackageRequests SET Status = 1 WHERE ID = " . intval($id);
 	$dbh->exec($q);
 
+	/*
+	 * Send e-mail notifications.
+	 * TODO: Move notification logic to separate function where it belongs.
+	 */
+	$q = "SELECT Users.Email ";
+	$q.= "FROM Users INNER JOIN PackageBases ";
+	$q.= "ON PackageBases.MaintainerUID = Users.ID ";
+	$q.= "INNER JOIN PackageRequests ";
+	$q.= "ON PackageRequests.PackageBaseID = PackageBases.ID ";
+	$q.= "WHERE PackageRequests.ID = " . intval($id);
+	$result = $dbh->query($q);
+	if ($row = $result->fetch(PDO::FETCH_ASSOC)) {
+		$bcc = $row['Email'];
+	} else {
+		unset($bcc);
+	}
+
+	/*
+	 * TODO: Add native language emails for users, based on their
+	 * preferences. Simply making these strings translatable won't
+	 * work, users would be getting emails in the language that the
+	 * user who posted the comment was in.
+	 */
+	$username = username_from_sid($_COOKIE['AURSID']);
+	$body = $username . " [1] closed request #" . intval($id) . ".\n\n" .
+		"[1] " . $AUR_LOCATION . get_user_uri($username) . "\n";
+	$body = wordwrap($body, 70);
+	$headers = "MIME-Version: 1.0\r\n" .
+		   "Content-type: text/plain; charset=UTF-8\r\n";
+	if (!empty($bcc)) {
+		$headers .= "Bcc: $bcc\r\n";
+	}
+	$thread_id = "<pkg-request-" . $id . "@aur.archlinux.org>";
+	$headers .= "Reply-to: noreply at aur.archlinux.org\r\n" .
+		    "From: notify at aur.archlinux.org\r\n" .
+		    "In-Reply-To: $thread_id\r\n" .
+		    "References: $thread_id\r\n" .
+		    "X-Mailer: AUR";
+	@mail($AUR_REQUEST_ML, "AUR Request Closed", $body, $headers);
+
 	return array(true, __("Request closed successfully."));
 }
-- 
2.0.0



More information about the aur-dev mailing list