Index: bp-activity/bp-activity-notifications.php
===================================================================
--- bp-activity/bp-activity-notifications.php	(revision 2716)
+++ bp-activity/bp-activity-notifications.php	(working copy)
@@ -15,35 +15,42 @@
 		if ( !$receiver_user_id = bp_core_get_userid($username) )
 			continue;
 
-		// Now email the user with the contents of the message (if they have enabled email notifications)
+		/* Now email the user with the contents of the message (if they have enabled email notifications) */
 		if ( 'no' != get_usermeta( $user_id, 'notification_activity_new_mention' ) ) {
 			$poster_name = bp_core_get_user_displayname( $poster_user_id );
-
 			$message_link = bp_activity_get_permalink( $activity_id );
 			$settings_link = bp_core_get_user_domain( $receiver_user_id ) . 'settings/notifications/';
 
-			// Set up and send the message
+			/* Get email recipient data */
 			$ud = bp_core_get_core_userdata( $receiver_user_id );
-			$to = $ud->user_email;
-			$subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( '%s mentioned you in an update', 'buddypress' ), stripslashes($poster_name) );
+			$to = apply_filters( 'bp_activity_at_message_notification_to', $ud->user_email );
 
-$message = sprintf( __(
-'%s mentioned you in an update:
+			/* Get blog name */
+			$blog_name = get_blog_option( BP_ROOT_BLOG, 'blogname' );
 
-"%s"
+			/* Filter content of comment */
+			$content = bp_activity_filter_kses( stripslashes( $content ) );
 
-To view and respond to the message, log in and visit: %s
+			/* Allow filtering of email subject and body */
+			$subject_text = apply_filters( 'bp_activity_at_message_notification_subject', __( '[%1$s] %2$s mentioned you in an update', 'buddypress' ), $blog_name, $poster_name );
+			$message_text = apply_filters( 'bp_activity_at_message_notification_message', __(
+'%1$s mentioned you in an update:
 
+"%2$s"
+
+To view and respond to the message, log in and visit: %3$s
+
 ---------------------
-', 'buddypress' ), $poster_name, bp_activity_filter_kses( stripslashes($content) ), $message_link );
+', 'buddypress' ), $poster_name, $content, $message_link );
 
+			/* Prepare the email */
+			$subject = sprintf( $subject_text, $blog_name, $poster_name );
+			$message = sprintf( $message_text, $poster_name, $content, $message_link );
+
+			/* Add link for user to turn off this notification */
 			$message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
 
-			/* Send the message */
-			$to = apply_filters( 'bp_activity_at_message_notification_to', $to );
-			$subject = apply_filters( 'bp_activity_at_message_notification_subject', $subject );
-			$message = apply_filters( 'bp_activity_at_message_notification_message', $message );
-
+			/* Send the email */
 			wp_mail( $to, $subject, $message );
 		}
 	}
@@ -59,31 +66,40 @@
 
 	if ( $original_activity->user_id != $commenter_id && 'no' != get_usermeta( $original_activity->user_id, 'notification_activity_new_reply' ) ) {
 		$poster_name = bp_core_get_user_displayname( $commenter_id );
+		$poster_name = stripslashes_deep( $poster_name );
 		$thread_link = bp_activity_get_permalink( $activity_id );
 		$settings_link = bp_core_get_user_domain( $original_activity->user_id ) . 'settings/notifications/';
 
-		// Set up and send the message
+		/* Get email recipient data */
 		$ud = bp_core_get_core_userdata( $original_activity->user_id );
-		$to = $ud->user_email;
-		$subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( '%s replied to one of your updates', 'buddypress' ), stripslashes_deep( $poster_name ) );
+		$to = apply_filters( 'bp_activity_new_comment_notification_to', $ud->user_email );
 
-$message = sprintf( __(
-'%s replied to one of your updates:
+		/* Get blog name */
+		$blog_name = get_blog_option( BP_ROOT_BLOG, 'blogname' );
 
-"%s"
+		/* Filter content of comment */
+		$content = bp_activity_filter_kses( stripslashes( $content ) );
 
-To view your original update and all comments, log in and visit: %s
+		/* Allow filtering of email subject and body */
+		$subject_text = apply_filters( 'bp_activity_new_comment_notification_subject', __( '[%1$s] %2$s replied to one of your updates', 'buddypress' ), $blog_name, $poster_name );
+		$message_text = apply_filters( 'bp_activity_new_comment_notification_message', __(
+'%1$s replied to one of your updates:
 
+"%2$s"
+
+To view your original update and all comments, log in and visit: %3$s
+
 ---------------------
-', 'buddypress' ), $poster_name, bp_activity_filter_kses( stripslashes( $content ) ), $thread_link );
+', 'buddypress' ), $poster_name, $content, $thread_link );
 
+		/* Prepare the email */
+		$subject = sprintf( $subject_text, $blog_name, $poster_name );
+		$message = sprintf( $message_text, $poster_name, $content, $thread_link );
+
+		/* Add link for user to turn off this notification */
 		$message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
 
-		/* Send the message */
-		$to = apply_filters( 'bp_activity_new_comment_notification_to', $to );
-		$subject = apply_filters( 'bp_activity_new_comment_notification_subject', $subject );
-		$message = apply_filters( 'bp_activity_new_comment_notification_message', $message );
-
+		/* Send the email */
 		wp_mail( $to, $subject, $message );
 	}
 
@@ -101,28 +117,39 @@
 		$thread_link = bp_activity_get_permalink( $activity_id );
 		$settings_link = bp_core_get_user_domain( $parent_comment->user_id ) . 'settings/notifications/';
 
-		// Set up and send the message
+		/* Get email recipient data */
 		$ud = bp_core_get_core_userdata( $parent_comment->user_id );
-		$to = $ud->user_email;
-		$subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( '%s replied to one of your comments', 'buddypress' ), stripslashes_deep( $poster_name ) );
+		$to = apply_filters( 'bp_activity_new_comment_notification_comment_author_to', $ud->user_email );
 
-$message = sprintf( __(
-'%s replied to one of your comments:
+		/* Get blog name */
+		$blog_name = get_blog_option( BP_ROOT_BLOG, 'blogname' );
 
-"%s"
+		/* Filter content of comment */
+		$content = bp_activity_filter_kses( stripslashes( $content ) );
 
-To view the original activity, your comment and all replies, log in and visit: %s
+		/* Allow filtering of email subject and body */
+		$subject_text = apply_filters( 'bp_activity_new_comment_notification_comment_author_subject', __( '[%1$s] %2$s replied to one of your comments', 'buddypress' ), $blog_name, $poster_name );
+		$message_text = apply_filters( 'bp_activity_new_comment_notification_comment_author_message', __(
 
+'%1$s replied to one of your comments:
+
+"%2$s"
+
+To view the original activity, your comment and all replies, log in and visit: %3$s
+
 ---------------------
-', 'buddypress' ), $poster_name, bp_activity_filter_kses( stripslashes( $content ) ), $thread_link );
+', 'buddypress' ), $poster_name, $content, $thread_link );
 
 		$message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
 
-		/* Send the message */
-		$to = apply_filters( 'bp_activity_new_comment_notification_comment_author_to', $to );
-		$subject = apply_filters( 'bp_activity_new_comment_notification_comment_author_subject', $subject );
-		$message = apply_filters( 'bp_activity_new_comment_notification_comment_author_message', $message );
+		/* Prepare the email */
+		$subject = sprintf( $subject_text, $blog_name, $poster_name );
+		$message = sprintf( $message_text, $poster_name, $content, $thread_link );
 
+		/* Add link for user to turn off this notification */
+		$message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
+
+		/* Send the email */
 		wp_mail( $to, $subject, $message );
 	}
 }
Index: bp-core/bp-core-activation.php
===================================================================
--- bp-core/bp-core-activation.php	(revision 2716)
+++ bp-core/bp-core-activation.php	(working copy)
@@ -95,32 +95,37 @@
 if ( !is_admin() && empty( $_GET['e'] ) )
 	add_filter( 'wpmu_welcome_user_notification', 'bp_core_disable_welcome_email' );
 
-// Notify user of signup success.
+/* Notify user of signup success. */
 function bp_core_activation_signup_blog_notification( $domain, $path, $title, $user, $user_email, $key, $meta ) {
 	global $current_site;
 
-	// Send email with activation link.
-	$activate_url = bp_get_activation_page() ."?key=$key";
-	$activate_url = clean_url($activate_url);
+	/* Send email with activation link. */
+	$activate_url = bp_get_activation_page() . "?key=$key";
+	$activate_url = clean_url( $activate_url );
 
-	$admin_email = get_site_option( "admin_email" );
+	/* Get admin email */
+	$admin_email = get_site_option( 'admin_email' );
 
 	if ( empty( $admin_email ) )
 		$admin_email = 'support@' . $_SERVER['SERVER_NAME'];
 
-	$from_name = ( '' == get_site_option( "site_name" ) ) ? 'WordPress' : wp_specialchars( get_site_option( "site_name" ) );
-	$message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
-	$message = sprintf(__("Thanks for registering! To complete the activation of your account and blog, please click the following link:\n\n%s\n\n\n\nAfter you activate, you can visit your blog here:\n\n%s", 'buddypress' ), $activate_url, clean_url("http://{$domain}{$path}" ) );
-	$subject = '[' . $from_name . '] ' . sprintf(__('Activate %s', 'buddypress' ), clean_url('http://' . $domain . $path));
+	$from_name = ( '' == get_site_option( 'site_name' ) ) ? 'WordPress' : wp_specialchars( get_site_option( 'site_name' ) );
+	$message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option( 'blog_charset' ) . "\"\n";
+	$site = clean_url( 'http://' . $domain . $path );
 
-	/* Send the message */
+	/* Allow filtering of email recipient, subject, and body */
 	$to = apply_filters( 'bp_core_activation_signup_blog_notification_to', $user_email );
-	$subject = apply_filters( 'bp_core_activation_signup_blog_notification_subject', $subject );
-	$message = apply_filters( 'bp_core_activation_signup_blog_notification_message', $message );
+	$subject_text = apply_filters( 'bp_core_activation_signup_blog_notification_subject', __( '[%1$s] Activate %2$s', 'buddypress' ), $from_name, $site );
+	$message_text = apply_filters( 'bp_core_activation_signup_blog_notification_message', __( 'Thanks for registering! To complete the activation of your account and blog, please click the following link:\n\n%1$s\n\n\n\nAfter you activate, you can visit your blog here:\n\n%2$s', 'buddypress' ), $activate_url, $site );
 
+	/* Prepare the email */
+	$subject = sprintf( $subject_text, $from_name, $site );
+	$message = sprintf( $message_text, $activate_url, $site );
+
+	/* Send the email */
 	wp_mail( $to, $subject, $message, $message_headers );
 
-	// Return false to stop the original WPMU function from continuing
+	/* Return false to stop the original WPMU function from continuing */
 	return false;
 }
 if ( !is_admin() )
@@ -129,9 +134,9 @@
 function bp_core_activation_signup_user_notification( $user, $user_email, $key, $meta ) {
 	global $current_site;
 
-	$activate_url = bp_get_activation_page() ."?key=$key";
+	$activate_url = bp_get_activation_page() . "?key=$key";
 	$activate_url = clean_url($activate_url);
-	$admin_email = get_site_option( "admin_email" );
+	$admin_email = get_site_option( 'admin_email' );
 
 	if ( empty( $admin_email ) )
 		$admin_email = 'support@' . $_SERVER['SERVER_NAME'];
@@ -140,19 +145,22 @@
 	if ( is_admin() )
 		$email = '&e=1';
 
-	$from_name = ( '' == get_site_option( "site_name" ) ) ? 'WordPress' : wp_specialchars( get_site_option( "site_name" ) );
-	$message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
-	$message = sprintf( __( "Thanks for registering! To complete the activation of your account please click the following link:\n\n%s\n\n", 'buddypress' ), $activate_url . $email, clean_url("http://{$domain}{$path}" ) );
-	$subject = '[' . $from_name . '] ' . __( 'Activate Your Account', 'buddypress' );
+	$from_name = ( '' == get_site_option( 'site_name' ) ) ? 'WordPress' : wp_specialchars( get_site_option( 'site_name' ) );
+	$message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option( 'blog_charset' ) . "\"\n";
 
-	/* Send the message */
+	/* Allow filtering of email recipient, subject, and body */
 	$to = apply_filters( 'bp_core_activation_signup_user_notification_to', $user_email );
-	$subject = apply_filters( 'bp_core_activation_signup_user_notification_subject', $subject );
-	$message = apply_filters( 'bp_core_activation_signup_user_notification_message', $message );
+	$subject_text = apply_filters( 'bp_core_activation_signup_user_notification_subject', __( '[%1$s] Activate Your Account', 'buddypress' ), $from_name );
+	$message_text = apply_filters( 'bp_core_activation_signup_user_notification_message', __( 'Thanks for registering! To complete the activation of your account please click the following link:\n\n%s\n\n', 'buddypress' ), $activate_url );
 
+	/* Prepare the email */
+	$subject = sprintf( $subject_text, $from_name );
+	$message = sprintf( $message_text, $activate_url );
+
+	/* Send the email */
 	wp_mail( $to, $subject, $message, $message_headers );
 
-	// Return false to stop the original WPMU function from continuing
+	/* Return false to stop the original WPMU function from continuing */
 	return false;
 }
 if ( !is_admin() || ( is_admin() && empty( $_POST['noconfirmation'] ) ) )
Index: bp-friends/bp-friends-notifications.php
===================================================================
--- bp-friends/bp-friends-notifications.php	(revision 2716)
+++ bp-friends/bp-friends-notifications.php	(working copy)
@@ -3,77 +3,86 @@
 function friends_notification_new_request( $friendship_id, $initiator_id, $friend_id ) {
 	global $bp;
 
-	$initiator_name = bp_core_get_user_displayname( $initiator_id );
-
 	if ( 'no' == get_usermeta( (int)$friend_id, 'notification_friends_friendship_request' ) )
 		return false;
 
+	/* Get blog name */
+	$blog_name = get_blog_option( BP_ROOT_BLOG, 'blogname' );
+
+	/* Get email recipient data */
 	$ud = get_userdata( $friend_id );
-	$initiator_ud = get_userdata( $initiator_id );
-
 	$all_requests_link = bp_core_get_user_domain( $friend_id ) . BP_FRIENDS_SLUG . '/requests/';
 	$settings_link = bp_core_get_user_domain( $friend_id ) . 'settings/notifications';
+	$to = apply_filters( 'friends_notification_new_request_to', $ud->user_email );
 
+	/* Get intiator data */
+	$initiator_ud = get_userdata( $initiator_id );
+	$initiator_name = bp_core_get_user_displayname( $initiator_id );
 	$initiator_link = bp_core_get_user_domain( $initiator_id );
 
-	// Set up and send the message
-	$to = $ud->user_email;
-	$subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( 'New friendship request from %s', 'buddypress' ), $initiator_name );
+	/* Allow filtering of email subject and body */
+	$subject_text = apply_filters( 'friends_notification_new_request_subject', __( '[%1$s] New friendship request from %s', 'buddypress' ), $blog_name, $initiator_name );
+	$message_text = apply_filters( 'friends_notification_new_request_message', __(
+'%1$s wants to add you as a friend.
 
-	$message = sprintf( __(
-"%s wants to add you as a friend.
+To view %1$s\'s profile: %3$s
 
-To view all of your pending friendship requests: %s
+To view all of your pending friendship requests: %2$s
 
-To view %s's profile: %s
-
 ---------------------
-", 'buddypress' ), $initiator_name, $all_requests_link, $initiator_name, $initiator_link );
+', 'buddypress' ), $initiator_name, $initiator_link, $all_requests_link );
 
+	/* Prepare the email */
+	$subject = sprintf( $subject_text, $blog_name, $initiator_name );
+	$message = sprintf( $message_text, $initiator_name, $initiator_link, $all_requests_link );
+
+	/* Add link for user to turn off this notification */
 	$message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
 
-	/* Send the message */
-	$to = apply_filters( 'friends_notification_new_request_to', $to );
-	$subject = apply_filters( 'friends_notification_new_request_subject', $subject );
-	$message = apply_filters( 'friends_notification_new_request_message', $message );
-
+	/* Send the email */
 	wp_mail( $to, $subject, $message );
 }
 
 function friends_notification_accepted_request( $friendship_id, $initiator_id, $friend_id ) {
 	global $bp;
 
+	/* Create friendship */
 	$friendship = new BP_Friends_Friendship( $friendship_id, false, false );
 
-	$friend_name = bp_core_get_user_displayname( $friend_id );
-
 	if ( 'no' == get_usermeta( (int)$initiator_id, 'notification_friends_friendship_accepted' ) )
 		return false;
 
+	/* Get blog name */
+	$blog_name = get_blog_option( BP_ROOT_BLOG, 'blogname' );
+
+	/* Get email recipient data */
 	$ud = get_userdata( $initiator_id );
+	$to = apply_filters( 'friends_notification_accepted_request_to', $ud->user_email );
+	$settings_link = bp_core_get_user_domain( $initiator_id ) . 'settings/notifications';
 
+	/* Get friend data */
+	$friend_name = bp_core_get_user_displayname( $friend_id );
 	$friend_link = bp_core_get_user_domain( $friend_id );
-	$settings_link = bp_core_get_user_domain( $initiator_id ) . 'settings/notifications';
 
-	// Set up and send the message
-	$to = $ud->user_email;
-	$subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( '%s accepted your friendship request', 'buddypress' ), $friend_name );
 
-	$message = sprintf( __(
-'%s accepted your friend request.
+	/* Allow filtering of email subject and body */
+	$subject_text = apply_filters( 'friends_notification_accepted_request_subject', __( '[%1$s] %2$s accepted your friendship request', 'buddypress' ), $blog_name, $friend_name );
+	$message_text = apply_filters( 'friends_notification_accepted_request_message', __(
+'%1$s accepted your friend request.
 
-To view %s\'s profile: %s
+To view %1$s\'s profile: %2$s
 
 ---------------------
-', 'buddypress' ), $friend_name, $friend_name, $friend_link );
+', 'buddypress' ), $friend_name, $friend_link );
 
+	/* Prepare the email */
+	$subject = sprintf( $subject_text, $blog_name, $friend_name );
+	$message = sprintf( $message_text, $friend_name, $friend_link );
+
+	/* Add link for user to turn off this notification */
 	$message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
 
-	/* Send the message */
-	$to = apply_filters( 'friends_notification_accepted_request_to', $to );
-	$subject = apply_filters( 'friends_notification_accepted_request_subject', $subject );
-	$message = apply_filters( 'friends_notification_accepted_request_message', $message );
-
+	/* Send the email */
 	wp_mail( $to, $subject, $message );
 }
 
Index: bp-groups/bp-groups-notifications.php
===================================================================
--- bp-groups/bp-groups-notifications.php	(revision 2716)
+++ bp-groups/bp-groups-notifications.php	(working copy)
@@ -3,38 +3,45 @@
 function groups_notification_group_updated( $group_id ) {
 	global $bp;
 
+	/* Get group data */
 	$group = new BP_Groups_Group( $group_id );
-	$subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . __( 'Group Details Updated', 'buddypress' );
+	$group_link = site_url( $bp->groups->slug . '/' . $group->slug );
+	$user_ids = BP_Groups_Member::get_group_member_ids( $group->id );
 
-	$user_ids = BP_Groups_Member::get_group_member_ids( $group->id );
+	/* Get blog name */
+	$blog_name = get_blog_option( BP_ROOT_BLOG, 'blogname' );
+
+	/* Email subject */
+	$subject_text = apply_filters( 'groups_notification_group_updated_subject', __( '[%s] Group Details Updated', 'buddypress' ), $blog_name );
+
 	foreach ( (array)$user_ids as $user_id ) {
 		if ( 'no' == get_usermeta( $user_id, 'notification_groups_group_updated' ) ) continue;
 
+		/* Get email recipient data */
 		$ud = bp_core_get_core_userdata( $user_id );
-
-		// Set up and send the message
-		$to = $ud->user_email;
-
-		$group_link = site_url( $bp->groups->slug . '/' . $group->slug );
 		$settings_link = bp_core_get_user_domain( $user_id ) . 'settings/notifications/';
+		$to = apply_filters( 'groups_notification_group_updated_to', $ud->user_email );
 
-		$message = sprintf( __(
-'Group details for the group "%s" were updated:
+		/* Email text */
+		$message_text = apply_filters( 'groups_notification_group_updated_message', __(
+'Group details for the group "%1$s" were updated:
 
-To view the group: %s
+To view the group: %2$s
 
 ---------------------
 ', 'buddypress' ), $group->name, $group_link );
 
+		/* Prepare the email */
+		$subject = sprintf( $subject_text, $blog_name );
+		$message = sprintf( $message_text, $group->name, $group_link );
+
+		/* Add link for user to turn off this notification */
 		$message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
 
-		/* Send the message */
-		$to = apply_filters( 'groups_notification_group_updated_to', $to );
-		$subject = apply_filters( 'groups_notification_group_updated_subject', $subject );
-		$message = apply_filters( 'groups_notification_group_updated_message', $message );
-
+		/* Send the email */
 		wp_mail( $to, $subject, $message );
 
+		/* Unset specific user data to avoid duplicate emails */
 		unset( $message, $to );
 	}
 }
@@ -47,47 +54,53 @@
 	if ( 'no' == get_usermeta( $admin_id, 'notification_groups_membership_request' ) )
 		return false;
 
-	$requesting_user_name = bp_core_get_user_displayname( $requesting_user_id );
+	/* Get group data */
 	$group = new BP_Groups_Group( $group_id );
+	$group_requests = bp_get_group_permalink( $group ) . 'admin/membership-requests';
 
-	$ud = bp_core_get_core_userdata($admin_id);
-	$requesting_ud = bp_core_get_core_userdata($requesting_user_id);
+	/* Get email recipient data */
+	$ud = bp_core_get_core_userdata( $admin_id );
+	$to = apply_filters( 'groups_notification_new_membership_request_to', $ud->user_email );
 
-	$group_requests = bp_get_group_permalink( $group ) . 'admin/membership-requests';
+	/* Get requester data */
+	$requesting_ud = bp_core_get_core_userdata( $requesting_user_id );
+	$requesting_user_name = bp_core_get_user_displayname( $requesting_user_id );
 	$profile_link = bp_core_get_user_domain( $requesting_user_id );
 	$settings_link = bp_core_get_user_domain( $requesting_user_id ) . 'settings/notifications/';
 
-	// Set up and send the message
-	$to = $ud->user_email;
-	$subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( 'Membership request for group: %s', 'buddypress' ), $group->name );
+	/* Get blog name */
+	$blog_name = get_blog_option( BP_ROOT_BLOG, 'blogname' );
 
-$message = sprintf( __(
-'%s wants to join the group "%s".
+	/* Allow filtering of email subject and body */
+	$subject_text = apply_filters( 'groups_notification_new_membership_request_subject', __( '[%1$s] Membership request for group: %2$s', 'buddypress' ), $blog_name, $group->name );
+	$message_text = apply_filters( 'groups_notification_new_membership_request_message', __(
+'%1$s wants to join the group "%2$s".
 
 Because you are the administrator of this group, you must either accept or reject the membership request.
 
 To view all pending membership requests for this group, please visit:
-%s
+%3$s
 
-To view %s\'s profile: %s
+To view %1$s\'s profile: %4$s
 
 ---------------------
-', 'buddypress' ), $requesting_user_name, $group->name, $group_requests, $requesting_user_name, $profile_link );
+', 'buddypress' ), $requesting_user_name, $group->name, $group_requests, $profile_link );
 
+	/* Prepare the email */
+	$subject = sprintf( $subject_text, $blog_name, $group->name );
+	$message = sprintf( $message_text, $requesting_user_name, $group->name, $group_requests, $profile_link );
+
+	/* Add link for user to turn off this notification */
 	$message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
 
-	/* Send the message */
-	$to = apply_filters( 'groups_notification_new_membership_request_to', $to );
-	$subject = apply_filters( 'groups_notification_new_membership_request_subject', $subject );
-	$message = apply_filters( 'groups_notification_new_membership_request_message', $message );
-
+	/* Send the email */
 	wp_mail( $to, $subject, $message );
 }
 
 function groups_notification_membership_request_completed( $requesting_user_id, $group_id, $accepted = true ) {
 	global $bp;
 
-	// Post a screen notification first.
+	/* Post a screen notification first. */
 	if ( $accepted )
 		bp_core_add_notification( $group_id, $requesting_user_id, 'groups', 'membership_request_accepted' );
 	else
@@ -96,44 +109,48 @@
 	if ( 'no' == get_usermeta( $requesting_user_id, 'notification_membership_request_completed' ) )
 		return false;
 
+	/* Get group data */
 	$group = new BP_Groups_Group( $group_id );
+	$group_link = bp_get_group_permalink( $group );
 
-	$ud = bp_core_get_core_userdata($requesting_user_id);
-
-	$group_link = bp_get_group_permalink( $group );
+	/* Get email recipient data */
+	$ud = bp_core_get_core_userdata( $requesting_user_id );
 	$settings_link = bp_core_get_user_domain( $requesting_user_id ) . 'settings/notifications/';
+	$to = apply_filters( 'groups_notification_membership_request_completed_to', $ud->user_email );
 
-	// Set up and send the message
-	$to = $ud->user_email;
+	/* Get blog name */
+	$blog_name = get_blog_option( BP_ROOT_BLOG, 'blogname' );
 
+	/* Allow filtering of email subject and body */
 	if ( $accepted ) {
-		$subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( 'Membership request for group "%s" accepted', 'buddypress' ), $group->name );
-		$message = sprintf( __(
-'Your membership request for the group "%s" has been accepted.
+		$subject_text = apply_filters( 'groups_notification_new_membership_request_subject', __( '[%1$s] Membership request for group "%2$s" accepted', 'buddypress' ), $blog_name, $group->name );
+		$message_text = sprintf( __(
+'Your membership request for the group "%1$s" has been accepted.
 
-To view the group please login and visit: %s
+To view the group please login and visit: %2$s
 
 ---------------------
 ', 'buddypress' ), $group->name, $group_link );
 
 	} else {
-		$subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( 'Membership request for group "%s" rejected', 'buddypress' ), $group->name );
-		$message = sprintf( __(
-'Your membership request for the group "%s" has been rejected.
+		$subject_text = apply_filters( 'groups_notification_new_membership_request_subject', __( '[%1$s] Membership request for group "%2$s" rejected', 'buddypress' ), $blog_name, $group->name );
+		$message_text = sprintf( __(
+'Your membership request for the group "%1$s" has been rejected.
 
-To submit another request please log in and visit: %s
+To submit another request please log in and visit: %2$s
 
 ---------------------
 ', 'buddypress' ), $group->name, $group_link );
 	}
 
+	/* Prepare the email */
+	$subject = sprintf( $subject_text, $blog_name, $group->name );
+	$message = sprintf( $message_text, $group->name, $group_link );
+
+	/* Add link for user to turn off this notification */
 	$message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
 
-	/* Send the message */
-	$to = apply_filters( 'groups_notification_membership_request_completed_to', $to );
-	$subject = apply_filters( 'groups_notification_membership_request_completed_subject', $subject );
-	$message = apply_filters( 'groups_notification_membership_request_completed_message', $message );
-
+	/* Send the email */
 	wp_mail( $to, $subject, $message );
 }
 
@@ -148,38 +165,42 @@
 		$type = 'member_promoted_to_mod';
 	}
 
-	// Post a screen notification first.
+	/* Post a screen notification first. */
 	bp_core_add_notification( $group_id, $user_id, 'groups', $type );
 
 	if ( 'no' == get_usermeta( $user_id, 'notification_groups_admin_promotion' ) )
 		return false;
 
+	/* Get group data */
 	$group = new BP_Groups_Group( $group_id );
-	$ud = bp_core_get_core_userdata($user_id);
+	$group_link = bp_get_group_permalink( $group );
 
-	$group_link = bp_get_group_permalink( $group );
+	/* Get email recipient data */
+	$ud = bp_core_get_core_userdata( $user_id );
 	$settings_link = bp_core_get_user_domain( $user_id ) . 'settings/notifications/';
+	$to = apply_filters( 'groups_notification_promoted_member_to', $ud->user_email );
 
-	// Set up and send the message
-	$to = $ud->user_email;
+	/* Get blog name */
+	$blog_name = get_blog_option( BP_ROOT_BLOG, 'blogname' );
 
-	$subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( 'You have been promoted in the group: "%s"', 'buddypress' ), $group->name );
+	/* Allow filtering of email subject and body */
+	$subject_text = apply_filters( 'groups_notification_promoted_member_subject', __( '[%1$s] You have been promoted in the group: "%s"', 'buddypress' ), $blog_name, $group->name );
+	$message_text = apply_filters( 'groups_notification_promoted_member_message', __(
+'You have been promoted to %1$s for the group: "%2$s".
 
-	$message = sprintf( __(
-'You have been promoted to %s for the group: "%s".
+To view the group please visit: %3$s
 
-To view the group please visit: %s
-
 ---------------------
 ', 'buddypress' ), $promoted_to, $group->name, $group_link );
 
+	/* Prepare the email */
+	$subject = sprintf( $subject_text, $blog_name, $group->name );
+	$message = sprintf( $message_text, $promoted_to, $group->name, $group_link );
+
+	/* Add link for user to turn off this notification */
 	$message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
 
-	/* Send the message */
-	$to = apply_filters( 'groups_notification_promoted_member_to', $to );
-	$subject = apply_filters( 'groups_notification_promoted_member_subject', $subject );
-	$message = apply_filters( 'groups_notification_promoted_member_message', $message );
-
+	/* Send the email */
 	wp_mail( $to, $subject, $message );
 }
 add_action( 'groups_promoted_member', 'groups_notification_promoted_member', 10, 2 );
@@ -187,51 +208,52 @@
 function groups_notification_group_invites( &$group, &$member, $inviter_user_id ) {
 	global $bp;
 
+	/* Get inviter data */
 	$inviter_ud = bp_core_get_core_userdata( $inviter_user_id );
 	$inviter_name = bp_core_get_userlink( $inviter_user_id, true, false, true );
 	$inviter_link = bp_core_get_user_domain( $inviter_user_id );
 
+	/* Get group data */
 	$group_link = bp_get_group_permalink( $group );
 
 	if ( !$member->invite_sent ) {
 		$invited_user_id = $member->user_id;
 
-		// Post a screen notification first.
+		/* Post a screen notification first. */
 		bp_core_add_notification( $group->id, $invited_user_id, 'groups', 'group_invite' );
 
 		if ( 'no' == get_usermeta( $invited_user_id, 'notification_groups_invite' ) )
 			return false;
 
+		/* Get invited data */
 		$invited_ud = bp_core_get_core_userdata($invited_user_id);
-
 		$settings_link = bp_core_get_user_domain( $invited_user_id ) . 'settings/notifications/';
 		$invited_link = bp_core_get_user_domain( $invited_user_id );
 		$invites_link = $invited_link . $bp->groups->slug . '/invites';
+		$to = apply_filters( 'groups_notification_group_invites_to', $invited_ud->user_email );
 
-		// Set up and send the message
-		$to = $invited_ud->user_email;
+		/* Allow filtering of email subject and body */
+		$subject_text = apply_filters( 'groups_notification_group_invites_subject', __( '[%1$s] You have an invitation to the group: "%s"', 'buddypress' ), $blog_name, $group->name );
+		$message_text = apply_filters( 'groups_notification_group_invites_message', __(
+'One of your friends (%1$s) has invited you to the group "%2$s".
 
-		$subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( 'You have an invitation to the group: "%s"', 'buddypress' ), $group->name );
+To view your group invites visit: %3$s
 
-		$message = sprintf( __(
-'One of your friends %s has invited you to the group: "%s".
+To view the group visit: %4$s
 
-To view your group invites visit: %s
+To view %1$s\'s profile visit: %5$s
 
-To view the group visit: %s
+---------------------
+', 'buddypress' ), $inviter_name, $group->name, $invites_link, $group_link, $inviter_link );
 
-To view %s\'s profile visit: %s
+		/* Prepare the email */
+		$subject = sprintf( $subject_text, $blog_name, $group->name );
+		$message = sprintf( $message_text, $inviter_name, $group->name, $invites_link, $group_link, $inviter_link );
 
----------------------
-', 'buddypress' ), $inviter_name, $group->name, $invites_link, $group_link, $inviter_name, $inviter_link );
-
+		/* Add link for user to turn off this notification */
 		$message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
 
-		/* Send the message */
-		$to = apply_filters( 'groups_notification_group_invites_to', $to );
-		$subject = apply_filters( 'groups_notification_group_invites_subject', $subject );
-		$message = apply_filters( 'groups_notification_group_invites_message', $message );
-
+		/* Send the email */
 		wp_mail( $to, $subject, $message );
 	}
 }
@@ -247,50 +269,54 @@
 	if ( !$usernames = array_unique( $usernames[1] ) )
 		return false;
 
+	/* Get group data */
 	$group = new BP_Groups_Group( $group_id );
 
 	foreach( (array)$usernames as $username ) {
-		if ( !$receiver_user_id = bp_core_get_userid($username) )
-			continue;
+		if ( !$receiver_user_id = bp_core_get_userid( $username ) ) continue;
 
 		/* Check the user is a member of the group before sending the update. */
-		if ( !groups_is_user_member( $receiver_user_id, $group_id ) )
-			continue;
+		if ( !groups_is_user_member( $receiver_user_id, $group_id ) ) continue;
 
-		// Now email the user with the contents of the message (if they have enabled email notifications)
+		/* Now email the user with the contents of the message (if they have enabled email notifications) */
 		if ( 'no' != get_usermeta( $user_id, 'notification_activity_new_mention' ) ) {
+			/* Get poster name */
 			$poster_name = bp_core_get_user_displayname( $poster_user_id );
+			$poster_name = stripslashes( $poster_name );
 
+			/* Get activity data */
 			$message_link = bp_activity_get_permalink( $activity_id );
+			$content = bp_groups_filter_kses( stripslashes( $content ) );
+			
+			/* Get email recipient data */
+			$ud = bp_core_get_core_userdata( $receiver_user_id );
 			$settings_link = bp_core_get_user_domain( $receiver_user_id ) . 'settings/notifications/';
+			$to = apply_filters( 'groups_at_message_notification_to', $ud->user_email );
 
-			// Set up and send the message
-			$ud = bp_core_get_core_userdata( $receiver_user_id );
-			$to = $ud->user_email;
-			$subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( '%s mentioned you in the group "%s"', 'buddypress' ), stripslashes( $poster_name ), $group->name );
+			/* Allow filtering of email subject and body */
+			$subject_text = apply_filters( 'groups_at_message_notification_subject', __( '[%1$s] %s mentioned you in the group "%s"', 'buddypress' ), $blog_name, $poster_name, $group->name );
+			$message_text = apply_filters( 'groups_at_message_notification_message', __(
+'%1$s mentioned you in the group "%2$s":
 
-$message = sprintf( __(
-'%s mentioned you in the group "%s":
+"%3$s"
 
-"%s"
+To view and/or respond to the message, log in and visit: %4$s
 
-To view and respond to the message, log in and visit: %s
-
 ---------------------
-', 'buddypress' ), $poster_name, $group->name, bp_groups_filter_kses( stripslashes( $content ) ), $message_link );
+', 'buddypress' ), $poster_name, $group->name, $content, $message_link );
 
+			/* Prepare the email */
+			$subject = sprintf( $subject_text, $blog_name, $poster_name, $group->name );
+			$message = sprintf( $message_text, $poster_name, $group->name, $content, $message_link );
+
+			/* Add link for user to turn off this notification */
 			$message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
 
-			/* Send the message */
-			$to = apply_filters( 'groups_at_message_notification_to', $to );
-			$subject = apply_filters( 'groups_at_message_notification_subject', $subject );
-			$message = apply_filters( 'groups_at_message_notification_message', $message );
-
+			/* Send the email */
 			wp_mail( $to, $subject, $message );
 		}
 	}
 }
 add_action( 'bp_groups_posted_update', 'groups_at_message_notification', 10, 4 );
 
-
 ?>
\ No newline at end of file
Index: bp-messages/bp-messages-notifications.php
===================================================================
--- bp-messages/bp-messages-notifications.php	(revision 2716)
+++ bp-messages/bp-messages-notifications.php	(working copy)
@@ -4,39 +4,52 @@
 	global $bp;
 	extract($args);
 
+	/* Email sender */
 	$sender_name = bp_core_get_user_displayname( $sender_id );
+	$sender_name = stripslashes( $sender_name );
 
+	/* Get blog name */
+	$blog_name = get_blog_option( BP_ROOT_BLOG, 'blogname' );
+
+	/* Message subject */
+	$subject = stripslashes( wp_filter_kses( $subject ) );
+	$subject_text = apply_filters( 'messages_notification_new_message_subject', __( '[%1$s] New message from %2$s', 'buddypress' ), $blog_name, $sender_name );
+
 	foreach( $recipients as $recipient ) {
 		if ( $sender_id == $recipient->user_id || 'no' == get_usermeta( $recipient->user_id, 'notification_messages_new_message' ) ) continue;
 
+		/* Get email recipient data */
 		$ud = get_userdata( $recipient->user_id );
 		$message_link = bp_core_get_user_domain( $recipient->user_id ) . BP_MESSAGES_SLUG .'/';
 		$settings_link = bp_core_get_user_domain( $recipient->user_id ) . 'settings/notifications/';
+		$to = apply_filters( 'messages_notification_new_message_to', $ud->user_email );
 
-		// Set up and send the message
-		$email_to = $ud->user_email;
-		$email_subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( 'New message from %s', 'buddypress' ), stripslashes( $sender_name ) );
+		/* Message body */
+		$content = stripslashes( wp_filter_kses( $content ) );
+		$message_text = apply_filters( 'messages_notification_new_message_message', __(
+'%1$s sent you a new message:
 
-		$email_content = sprintf( __(
-'%s sent you a new message:
+Subject: %2$s
 
-Subject: %s
+"%3$s"
 
-"%s"
+To view and read your messages please log in and visit: %4$s
 
-To view and read your messages please log in and visit: %s
-
 ---------------------
-', 'buddypress' ), $sender_name, stripslashes( wp_filter_kses( $subject ) ), stripslashes( wp_filter_kses( $content ) ), $message_link );
+', 'buddypress' ), $sender_name, $subject, $content, $message_link );
 
-		$content .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
+		/* Prepare the email */
+		$subject = sprintf( $subject_text, $blog_name, $sender_name );
+		$message = sprintf( $message_text, $sender_name, $subject, $content, $message_link );
 
-		/* Send the message */
-		$email_to = apply_filters( 'messages_notification_new_message_to', $email_to );
-		$email_subject = apply_filters( 'messages_notification_new_message_subject', $email_subject );
-		$email_content = apply_filters( 'messages_notification_new_message_message', $email_content );
+		/* Add link for user to turn off this notification */
+		$message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
 
-		wp_mail( $email_to, $email_subject, $email_content );
+		/* Send the email */
+		wp_mail( $to, $subject, $message );
+
+		/* Unset specific user data to avoid duplicate emails */
+		unset( $message, $to );
 	}
 }
 
