@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add a setting to disable all notification email

Summary: Ref T5861. Adds an option to opt out of all notification email. We'll still send you password resets, email verifications, etc.

Test Plan:
{F189484}

- Added unit tests.
- With preference set to different things, tried to send myself mail. Mail respected preferences.
- Sent password reset email, which got through the preference.

Reviewers: btrahan, chad

Reviewed By: chad

Subscribers: rush898, epriestley

Maniphest Tasks: T5861

Differential Revision: https://secure.phabricator.com/D10237

+109 -11
+1 -4
src/applications/auth/controller/PhabricatorEmailLoginController.php
··· 108 108 EOBODY; 109 109 } 110 110 111 - // NOTE: Don't set the user as 'from', or they may not receive the 112 - // mail if they have the "don't send me email about my own actions" 113 - // preference set. 114 - 115 111 $mail = id(new PhabricatorMetaMTAMail()) 116 112 ->setSubject(pht('[Phabricator] Password Reset')) 113 + ->setForceDelivery(true) 117 114 ->addRawTos(array($target_email->getAddress())) 118 115 ->setBody($body) 119 116 ->saveAndSend();
+1
src/applications/legalpad/controller/LegalpadDocumentSignController.php
··· 631 631 id(new PhabricatorMetaMTAMail()) 632 632 ->addRawTos(array($email->getAddress())) 633 633 ->setSubject(pht('[Legalpad] Signature Verification')) 634 + ->setForceDelivery(true) 634 635 ->setBody($body) 635 636 ->setRelatedPHID($signature->getDocumentPHID()) 636 637 ->saveAndSend();
+41 -5
src/applications/metamta/storage/PhabricatorMetaMTAMail.php
··· 243 243 } 244 244 245 245 /** 246 + * Force delivery of a message, even if recipients have preferences which 247 + * would otherwise drop the message. 248 + * 249 + * This is primarily intended to let users who don't want any email still 250 + * receive things like password resets. 251 + * 252 + * @param bool True to force delivery despite user preferences. 253 + * @return this 254 + */ 255 + public function setForceDelivery($force) { 256 + $this->setParam('force', $force); 257 + return $this; 258 + } 259 + 260 + public function getForceDelivery() { 261 + return $this->getParam('force', false); 262 + } 263 + 264 + /** 246 265 * Flag that this is an auto-generated bulk message and should have bulk 247 266 * headers added to it if appropriate. Broadly, this means some flavor of 248 267 * "Precedence: bulk" or similar, but is implementation and configuration ··· 794 813 return array(); 795 814 } 796 815 816 + if ($this->getForceDelivery()) { 817 + // If we're forcing delivery, skip all the opt-out checks. 818 + return $actors; 819 + } 820 + 797 821 // Exclude explicit recipients. 798 822 foreach ($this->getExcludeMailRecipientPHIDs() as $phid) { 799 823 $actor = idx($actors, $phid); ··· 834 858 } 835 859 } 836 860 861 + $all_prefs = id(new PhabricatorUserPreferences())->loadAllWhere( 862 + 'userPHID in (%Ls)', 863 + $actor_phids); 864 + $all_prefs = mpull($all_prefs, null, 'getUserPHID'); 865 + 866 + // Exclude recipients who don't want any mail. 867 + foreach ($all_prefs as $phid => $prefs) { 868 + $exclude = $prefs->getPreference( 869 + PhabricatorUserPreferences::PREFERENCE_NO_MAIL, 870 + false); 871 + if ($exclude) { 872 + $actors[$phid]->setUndeliverable( 873 + pht( 874 + 'This recipient has disabled all email notifications '. 875 + '(Settings > Email Preferences > Email Notifications).')); 876 + } 877 + } 837 878 838 879 // Exclude all recipients who have set preferences to not receive this type 839 880 // of email (for example, a user who says they don't want emails about task 840 881 // CC changes). 841 882 $tags = $this->getParam('mailtags'); 842 883 if ($tags) { 843 - $all_prefs = id(new PhabricatorUserPreferences())->loadAllWhere( 844 - 'userPHID in (%Ls)', 845 - $actor_phids); 846 - $all_prefs = mpull($all_prefs, null, 'getUserPHID'); 847 - 848 884 foreach ($all_prefs as $phid => $prefs) { 849 885 $user_mailtags = $prefs->getPreference( 850 886 PhabricatorUserPreferences::PREFERENCE_MAILTAGS,
+1
src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php
··· 329 329 330 330 $mail = id(new PhabricatorMetaMTAMail()) 331 331 ->setIsErrorEmail(true) 332 + ->setForceDelivery(true) 332 333 ->setSubject($title) 333 334 ->addRawTos(array($from)) 334 335 ->setBody($body)
+26 -1
src/applications/metamta/storage/__tests__/PhabricatorMetaMTAMailTestCase.php
··· 72 72 '"To" is a recipient.'); 73 73 74 74 75 - // Test that the "No Self Mail" preference works correctly. 75 + // Test that the "No Self Mail" and "No Mail" preferences work correctly. 76 76 $mail->setFrom($phid); 77 77 78 78 $this->assertTrue( ··· 90 90 91 91 $prefs->unsetPreference( 92 92 PhabricatorUserPreferences::PREFERENCE_NO_SELF_MAIL); 93 + $prefs->save(); 94 + 95 + $this->assertTrue( 96 + in_array($phid, $mail->buildRecipientList()), 97 + '"From" does not exclude recipients by default.'); 98 + 99 + $prefs->setPreference( 100 + PhabricatorUserPreferences::PREFERENCE_NO_MAIL, 101 + true); 102 + $prefs->save(); 103 + 104 + $this->assertFalse( 105 + in_array($phid, $mail->buildRecipientList()), 106 + '"From" excludes recipients with no-mail set.'); 107 + 108 + $mail->setForceDelivery(true); 109 + 110 + $this->assertTrue( 111 + in_array($phid, $mail->buildRecipientList()), 112 + '"From" includes no-mail recipients when forced.'); 113 + 114 + $mail->setForceDelivery(false); 115 + 116 + $prefs->unsetPreference( 117 + PhabricatorUserPreferences::PREFERENCE_NO_MAIL); 93 118 $prefs->save(); 94 119 95 120 $this->assertTrue(
+1
src/applications/people/controller/PhabricatorPeopleApproveController.php
··· 45 45 ->addTos(array($user->getPHID())) 46 46 ->addCCs(array($admin->getPHID())) 47 47 ->setSubject('[Phabricator] '.$title) 48 + ->setForceDelivery(true) 48 49 ->setBody($body) 49 50 ->saveAndSend(); 50 51
+2
src/applications/people/storage/PhabricatorUser.php
··· 540 540 541 541 $mail = id(new PhabricatorMetaMTAMail()) 542 542 ->addTos(array($this->getPHID())) 543 + ->setForceDelivery(true) 543 544 ->setSubject('[Phabricator] Welcome to Phabricator') 544 545 ->setBody($body) 545 546 ->saveAndSend(); ··· 583 584 584 585 $mail = id(new PhabricatorMetaMTAMail()) 585 586 ->addTos(array($this->getPHID())) 587 + ->setForceDelivery(true) 586 588 ->setSubject('[Phabricator] Username Changed') 587 589 ->setBody($body) 588 590 ->saveAndSend();
+3
src/applications/people/storage/PhabricatorUserEmail.php
··· 173 173 174 174 id(new PhabricatorMetaMTAMail()) 175 175 ->addRawTos(array($address)) 176 + ->setForceDelivery(true) 176 177 ->setSubject('[Phabricator] Email Verification') 177 178 ->setBody($body) 178 179 ->setRelatedPHID($user->getPHID()) ··· 210 211 211 212 id(new PhabricatorMetaMTAMail()) 212 213 ->addRawTos(array($old_address)) 214 + ->setForceDelivery(true) 213 215 ->setSubject('[Phabricator] Primary Address Changed') 214 216 ->setBody($body) 215 217 ->setFrom($user->getPHID()) ··· 241 243 242 244 id(new PhabricatorMetaMTAMail()) 243 245 ->addRawTos(array($new_address)) 246 + ->setForceDelivery(true) 244 247 ->setSubject('[Phabricator] Primary Address Changed') 245 248 ->setBody($body) 246 249 ->setFrom($user->getPHID())
+32 -1
src/applications/settings/panel/PhabricatorSettingsPanelEmailPreferences.php
··· 20 20 21 21 $preferences = $user->loadPreferences(); 22 22 23 + $pref_no_mail = PhabricatorUserPreferences::PREFERENCE_NO_MAIL; 23 24 $pref_no_self_mail = PhabricatorUserPreferences::PREFERENCE_NO_SELF_MAIL; 24 25 25 26 $errors = array(); 26 27 if ($request->isFormPost()) { 28 + $preferences->setPreference( 29 + $pref_no_mail, 30 + $request->getStr($pref_no_mail)); 31 + 27 32 $preferences->setPreference( 28 33 $pref_no_self_mail, 29 34 $request->getStr($pref_no_self_mail)); ··· 56 61 $form = new AphrontFormView(); 57 62 $form 58 63 ->setUser($user) 64 + ->appendRemarkupInstructions( 65 + pht( 66 + 'These settings let you control how Phabricator notifies you about '. 67 + 'events. You can configure Phabricator to send you an email, '. 68 + 'just send a web notification, or not notify you at all.')) 69 + ->appendRemarkupInstructions( 70 + pht( 71 + 'If you disable **Email Notifications**, Phabricator will never '. 72 + 'send email to notify you about events. This preference overrides '. 73 + 'all your other settings.'. 74 + "\n\n". 75 + "//You may still receive some administrative email, like password ". 76 + "reset email.//")) 77 + ->appendChild( 78 + id(new AphrontFormSelectControl()) 79 + ->setLabel(pht('Email Notifications')) 80 + ->setName($pref_no_mail) 81 + ->setOptions( 82 + array( 83 + '0' => pht('Send me email notifications'), 84 + '1' => pht('Never send email notifications'), 85 + )) 86 + ->setValue($preferences->getPreference($pref_no_mail, 0))) 87 + ->appendRemarkupInstructions( 88 + pht( 89 + 'If you disable **Self Actions**, Phabricator will not notify '. 90 + 'you about actions you take.')) 59 91 ->appendChild( 60 92 id(new AphrontFormSelectControl()) 61 93 ->setLabel(pht('Self Actions')) ··· 65 97 '0' => pht('Send me an email when I take an action'), 66 98 '1' => pht('Do not send me an email when I take an action'), 67 99 )) 68 - ->setCaption(pht('You can disable email about your own actions.')) 69 100 ->setValue($preferences->getPreference($pref_no_self_mail, 0))); 70 101 71 102 $mailtags = $preferences->getPreference('mailtags', array());
+1
src/applications/settings/storage/PhabricatorUserPreferences.php
··· 12 12 13 13 const PREFERENCE_RE_PREFIX = 're-prefix'; 14 14 const PREFERENCE_NO_SELF_MAIL = 'self-mail'; 15 + const PREFERENCE_NO_MAIL = 'no-mail'; 15 16 const PREFERENCE_MAILTAGS = 'mailtags'; 16 17 const PREFERENCE_VARY_SUBJECT = 'vary-subject'; 17 18