public function testEmailParsing()
 {
     $email = new PhutilEmailAddress('Abraham Lincoln <*****@*****.**>');
     $this->assertEqual('Abraham Lincoln', $email->getDisplayName());
     $this->assertEqual('alincoln', $email->getLocalPart());
     $this->assertEqual('logcabin.com', $email->getDomainName());
     $this->assertEqual('*****@*****.**', $email->getAddress());
     $email = new PhutilEmailAddress('*****@*****.**');
     $this->assertEqual(null, $email->getDisplayName());
     $this->assertEqual('alincoln', $email->getLocalPart());
     $this->assertEqual('logcabin.com', $email->getDomainName());
     $this->assertEqual('*****@*****.**', $email->getAddress());
     $email = new PhutilEmailAddress('"Abraham" <*****@*****.**>');
     $this->assertEqual('Abraham', $email->getDisplayName());
     $this->assertEqual('alincoln', $email->getLocalPart());
     $this->assertEqual('logcabin.com', $email->getDomainName());
     $this->assertEqual('*****@*****.**', $email->getAddress());
     $email = new PhutilEmailAddress('    alincoln@logcabin.com     ');
     $this->assertEqual(null, $email->getDisplayName());
     $this->assertEqual('alincoln', $email->getLocalPart());
     $this->assertEqual('logcabin.com', $email->getDomainName());
     $this->assertEqual('*****@*****.**', $email->getAddress());
     $email = new PhutilEmailAddress('alincoln');
     $this->assertEqual(null, $email->getDisplayName());
     $this->assertEqual('alincoln', $email->getLocalPart());
     $this->assertEqual(null, $email->getDomainName());
     $this->assertEqual('alincoln', $email->getAddress());
     $email = new PhutilEmailAddress('alincoln <alincoln at logcabin dot com>');
     $this->assertEqual('alincoln', $email->getDisplayName());
     $this->assertEqual('alincoln at logcabin dot com', $email->getLocalPart());
     $this->assertEqual(null, $email->getDomainName());
     $this->assertEqual('alincoln at logcabin dot com', $email->getAddress());
 }
 private static function renderName($name)
 {
     $email = new PhutilEmailAddress($name);
     if ($email->getDisplayName() || $email->getDomainName()) {
         return phutil_render_tag('span', array('title' => $email->getAddress()), phutil_escape_html($email->getDisplayName()));
     }
     return phutil_escape_html($name);
 }
Пример #3
0
 public static final function renderName($name)
 {
     $email = new PhutilEmailAddress($name);
     if ($email->getDisplayName() && $email->getDomainName()) {
         Javelin::initBehavior('phabricator-tooltips', array());
         require_celerity_resource('aphront-tooltip-css');
         return javelin_tag('span', array('sigil' => 'has-tooltip', 'meta' => array('tip' => $email->getAddress(), 'align' => 'E', 'size' => 'auto')), $email->getDisplayName());
     }
     return hsprintf('%s', $name);
 }
Пример #4
0
 /**
  * @task restrictions
  */
 public static function isAllowedAddress($address)
 {
     $allowed_domains = PhabricatorEnv::getEnvConfig('auth.email-domains');
     if (!$allowed_domains) {
         return true;
     }
     $addr_obj = new PhutilEmailAddress($address);
     $domain = $addr_obj->getDomainName();
     if (!$domain) {
         return false;
     }
     return in_array($domain, $allowed_domains);
 }
 /**
  * Identifies the sender's user account for a piece of received mail. Note
  * that this method does not validate that the sender is who they say they
  * are, just that they've presented some credential which corresponds to a
  * recognizable user.
  */
 public function loadSender(PhabricatorMetaMTAReceivedMail $mail)
 {
     $raw_from = $mail->getHeader('From');
     $from = self::getRawAddress($raw_from);
     $reasons = array();
     // Try to find a user with this email address.
     $user = PhabricatorUser::loadOneWithEmailAddress($from);
     if ($user) {
         return $user;
     } else {
         $reasons[] = pht('This email was sent from "%s", but that address is not recognized by ' . 'Phabricator and does not correspond to any known user account.', $raw_from);
     }
     // If we missed on "From", try "Reply-To" if we're configured for it.
     $raw_reply_to = $mail->getHeader('Reply-To');
     if (strlen($raw_reply_to)) {
         $reply_to_key = 'metamta.insecure-auth-with-reply-to';
         $allow_reply_to = PhabricatorEnv::getEnvConfig($reply_to_key);
         if ($allow_reply_to) {
             $reply_to = self::getRawAddress($raw_reply_to);
             $user = PhabricatorUser::loadOneWithEmailAddress($reply_to);
             if ($user) {
                 return $user;
             } else {
                 $reasons[] = pht('Phabricator is configured to authenticate users using the ' . '"Reply-To" header, but the reply address ("%s") on this ' . 'message does not correspond to any known user account.', $raw_reply_to);
             }
         } else {
             $reasons[] = pht('(Phabricator is not configured to authenticate users using the ' . '"Reply-To" header, so it was ignored.)');
         }
     }
     // If we don't know who this user is, load or create an external user
     // account for them if we're configured for it.
     $email_key = 'phabricator.allow-email-users';
     $allow_email_users = PhabricatorEnv::getEnvConfig($email_key);
     if ($allow_email_users) {
         $from_obj = new PhutilEmailAddress($from);
         $xuser = id(new PhabricatorExternalAccountQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withAccountTypes(array('email'))->withAccountDomains(array($from_obj->getDomainName(), 'self'))->withAccountIDs(array($from_obj->getAddress()))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->loadOneOrCreate();
         return $xuser->getPhabricatorUser();
     } else {
         $reasons[] = pht('Phabricator is also not configured to allow unknown external users ' . 'to send mail to the system using just an email address.');
         $reasons[] = pht('To interact with Phabricator, add this address ("%s") to your ' . 'account.', $raw_from);
     }
     $reasons = implode("\n\n", $reasons);
     throw new PhabricatorMetaMTAReceivedMailProcessingException(MetaMTAReceivedMailStatus::STATUS_UNKNOWN_SENDER, $reasons);
 }
Пример #6
0
 /**
  * @task restrictions
  */
 public static function isAllowedAddress($address)
 {
     if (!self::isValidAddress($address)) {
         return false;
     }
     $allowed_domains = PhabricatorEnv::getEnvConfig('auth.email-domains');
     if (!$allowed_domains) {
         return true;
     }
     $addr_obj = new PhutilEmailAddress($address);
     $domain = $addr_obj->getDomainName();
     if (!$domain) {
         return false;
     }
     $lower_domain = phutil_utf8_strtolower($domain);
     foreach ($allowed_domains as $allowed_domain) {
         $lower_allowed = phutil_utf8_strtolower($allowed_domain);
         if ($lower_allowed === $lower_domain) {
             return true;
         }
     }
     return false;
 }
 private function readCorporateSignatureForm(LegalpadDocument $document, AphrontRequest $request)
 {
     $viewer = $request->getUser();
     if (!$viewer->isLoggedIn()) {
         throw new Exception(pht('You can not sign a document on behalf of a corporation unless ' . 'you are logged in.'));
     }
     $signature_data = array();
     $errors = array();
     $field_errors = array();
     $name = $request->getStr('name');
     if (!strlen($name)) {
         $field_errors['name'] = pht('Required');
         $errors[] = pht('Company name is required.');
     } else {
         $field_errors['name'] = null;
     }
     $signature_data['name'] = $name;
     $address = $request->getStr('address');
     if (!strlen($address)) {
         $field_errors['address'] = pht('Required');
         $errors[] = pht('Company address is required.');
     } else {
         $field_errors['address'] = null;
     }
     $signature_data['address'] = $address;
     $contact_name = $request->getStr('contact.name');
     if (!strlen($contact_name)) {
         $field_errors['contact.name'] = pht('Required');
         $errors[] = pht('Contact name is required.');
     } else {
         $field_errors['contact.name'] = null;
     }
     $signature_data['contact.name'] = $contact_name;
     $email = $request->getStr('email');
     $addr_obj = null;
     if (!strlen($email)) {
         $field_errors['email'] = pht('Required');
         $errors[] = pht('Contact email is required.');
     } else {
         $addr_obj = new PhutilEmailAddress($email);
         $domain = $addr_obj->getDomainName();
         if (!$domain) {
             $field_errors['email'] = pht('Invalid');
             $errors[] = pht('A valid email is required.');
         } else {
             $field_errors['email'] = null;
         }
     }
     $signature_data['email'] = $email;
     return array($signature_data, $errors, $field_errors);
 }
 private function splitUserIdentifier($user)
 {
     $email = new PhutilEmailAddress($user);
     if ($email->getDisplayName() || $email->getDomainName()) {
         $user_name = $email->getDisplayName();
         $user_email = $email->getAddress();
     } else {
         $user_name = $email->getAddress();
         $user_email = null;
     }
     return array($user_name, $user_email);
 }
 protected function validateTransaction(PhabricatorLiskDAO $object, $type, array $xactions)
 {
     $errors = parent::validateTransaction($object, $type, $xactions);
     switch ($type) {
         case PhortuneMerchantTransaction::TYPE_NAME:
             $missing = $this->validateIsEmptyTextField($object->getName(), $xactions);
             if ($missing) {
                 $error = new PhabricatorApplicationTransactionValidationError($type, pht('Required'), pht('Merchant name is required.'), nonempty(last($xactions), null));
                 $error->setIsMissingFieldError(true);
                 $errors[] = $error;
             }
             break;
         case PhortuneMerchantTransaction::TYPE_INVOICEEMAIL:
             $new_email = null;
             foreach ($xactions as $xaction) {
                 switch ($xaction->getTransactionType()) {
                     case PhortuneMerchantTransaction::TYPE_INVOICEEMAIL:
                         $new_email = $xaction->getNewValue();
                         break;
                 }
             }
             if (strlen($new_email)) {
                 $email = new PhutilEmailAddress($new_email);
                 $domain = $email->getDomainName();
                 if (!$domain) {
                     $error = new PhabricatorApplicationTransactionValidationError($type, pht('Invalid'), pht('%s is not a valid email.', $new_email), nonempty(last($xactions), null));
                     $errors[] = $error;
                 }
             }
             break;
     }
     return $errors;
 }