Create Replays

Add a "Reply-To" addresses

@param mixed $addresses
@uses \PHPMailer
189694
private function createReplays($addresses) {
        if (is_array($addresses) && count($addresses) > 0) {
            foreach ($addresses as $address) {
                $this->mailer->addReplyTo($address);
            }
        } else if (!empty($addresses)) {
            $this->mailer->addReplyTo($addresses);
        }
    }
309528
protected function prepareListAddress(array &$addresses)
    {
        foreach ($addresses as &$address) {
            $address['translated'] = $this->address->getTranslated($address, true);
        }
    }
1086584
private function addAddress(
                        &$emailAddresses,
                        &$emailAddress,
                        $encoding,
                        $i)
    {
        if (!$emailAddress['invalid']) {
            if ($emailAddress['address_temp'] || $emailAddress['quote_temp']) {
                $emailAddress['invalid'] = true;
                $emailAddress['invalid_reason'] = "Incomplete address";
                $this->log('error', "Email\\Parse->addAddress - corruption during parsing - leftovers:\n\$i: ${i}\n\$emailAddress['address_temp'] : {$emailAddress['address_temp']}\n\$emailAddress['quote_temp']: {$emailAddress['quote_temp']}\n");
            } elseif ($emailAddress['ip'] && $emailAddress['domain']) {
                // Error - this should never occur
                $emailAddress['invalid'] = true;
                $emailAddress['invalid_reason'] = "Confusion during parsing";
                $this->log('error', "Email\\Parse->addAddress - both an IP address '{$emailAddress['ip']}' and a domain '{$emailAddress['domain']}' found for the email address '{$emailAddress['original_address']}'\n");
            } elseif ($emailAddress['ip'] || ($emailAddress['domain'] && preg_match('/\d+\.\d+\.\d+\.\d+/', $emailAddress['domain']))) {
                // also test if the current domain looks like an IP address

                if ($emailAddress['domain']) {
                    // Likely an IP address if we get here

                    $emailAddress['ip'] = $emailAddress['domain'];
                    $emailAddress['domain'] = null;
                }
                if (!$this->ipValidator) {
                    $this->ipValidator = new Ip();
                }
                try {
                    if (!$this->ipValidator->isValid($emailAddress['ip'])) {
                        $emailAddress['invalid'] = true;
                        $emailAddress['invalid_reason'] = 'IP address invalid: \''.$emailAddress['ip'].'\' does not appear to be a valid IP address';
                    } elseif (preg_match('/192\.168\.\d+\.\d+/', $emailAddress['ip']) ||
                        preg_match('/172\.(1[6-9]|2[0-9]|3[0-2])\.\d+\.\d+/', $emailAddress['ip']) ||
                        preg_match('/10\.\d+\.\d+\.\d+/', $emailAddress['ip'])) {
                        $emailAddress['invalid'] = true;
                        $emailAddress['invalid_reason'] = 'IP address invalid (private): '.$emailAddress['ip'];
                    } elseif (preg_match('/169\.254\.\d+\.\d+/', $emailAddress['ip'])) {
                        $emailAddress['invalid'] = true;
                        $emailAddress['invalid_reason'] = 'IP address invalid (APIPA): '.$emailAddress['ip'];
                    }
                } catch (\Exception $e) {
                    $emailAddress['invalid'] = true;
                    $emailAddress['invalid_reason'] = 'IP address invalid: '.$emailAddress['ip'];
                }
            } elseif ($emailAddress['domain']) {
                // Check for IDNA
                if (max(array_keys(count_chars($emailAddress['domain'], 1))) > 127) {
                    try {
                        $emailAddress['domain'] = $this->getPunycode()->encode($emailAddress['domain']);
                    } catch (\Exception $e) {
                        $emailAddress['invalid'] = true;
                        $emailAddress['invalid_reason'] = "Can't convert domain {$emailAddress['domain']} to punycode";
                    }
                }

                $result = $this->validateDomainName($emailAddress['domain']);
                if (!$result['valid']) {
                    $emailAddress['invalid'] = true;
                    $emailAddress['invalid_reason'] = isset($result['reason']) ? 'Domain invalid: '.$result['reason'] : 'Domain invalid for some unknown reason';
                }
            }
        }

        // Prepare some of the fields needed
        $emailAddress['name_parsed'] = rtrim($emailAddress['name_parsed']);
        $emailAddress['original_address'] = rtrim($emailAddress['original_address']);
        $name = $emailAddress['name_quoted'] ? "\"{$emailAddress['name_parsed']}\"" : $emailAddress['name_parsed'];
        $localPart = $emailAddress['local_part_quoted'] ? "\"{$emailAddress['local_part_parsed']}\"" : $emailAddress['local_part_parsed'];
        $domainPart = $emailAddress['ip'] ? '['.$emailAddress['ip'].']' : $emailAddress['domain'];

        if (!$emailAddress['invalid']) {
            if (mb_strlen($domainPart, $encoding) == 0) {
                $emailAddress['invalid'] = true;
                $emailAddress['invalid_reason'] = 'Email address needs a domain after the \'@\'';
            } elseif (mb_strlen($localPart, $encoding) > 63) {
                $emailAddress['invalid'] = true;
                $emailAddress['invalid_reason'] = 'Email address before the \'@\' can not be greater than 63 characters';
            } elseif ((mb_strlen($localPart, $encoding) + mb_strlen($domainPart, $encoding) + 1) > 254) {
                $emailAddress['invalid'] = true;
                $emailAddress['invalid_reason'] = 'Email addresses can not be greater than 254 characters';
            }
        }

        // Build the email address hash
        $emailAddrDef = ['address' => '',
                        'simple_address' => '',
                        'original_address' => rtrim($emailAddress['original_address']),
                        'name' => $name,
                        'name_parsed' => $emailAddress['name_parsed'],
                        'local_part' => $localPart,
                        'local_part_parsed' => $emailAddress['local_part_parsed'],
                        'domain_part' => $domainPart,
                        'domain' => $emailAddress['domain'],
                        'ip' => $emailAddress['ip'],
                        'invalid' => $emailAddress['invalid'],
                        'invalid_reason' => $emailAddress['invalid_reason']];



        // Build the proper address by hand (has comments stripped out and should have quotes in the proper places)
        if (!$emailAddrDef['invalid']) {
            $emailAddrDef['simple_address'] = "{$emailAddrDef['local_part']}@{$emailAddrDef['domain_part']}";
            $properAddress = $emailAddrDef['name'] ? "{$emailAddrDef['name']} <{$emailAddrDef['local_part']}@{$emailAddrDef['domain_part']}>" : $emailAddrDef['simple_address'];
            $emailAddrDef['address'] = $properAddress;
        }

        $emailAddresses[] = $emailAddrDef;
        return $emailAddrDef['invalid'];
    }
972431
private function validateAddress($address) {
		ArgUtils::valType($address, 'scalar');
		
		$email = self::stripEmail($address);
		
		if (!filter_var($email, FILTER_VALIDATE_EMAIL)) throw new MailFormatException('invalid e-mail address: ' . $address);
	}
482188
public function create($address)
    {
        if (is_array($address)) {
            $address = new OrderAddress($address);
        }

        if ($address instanceof OrderAddress) {
            if ($this->fireEvent('creating', array($address)) === false) {
                return false;
            }

            $address->setCaller($this);
            $address->save();

            $this->fireEvent('created', array($address));

            $address = $this->find($address->id);

            return $address;
        }

        throw new Exception(sprintf(Exception::CANT_CREATE_MODEL,
            'Subbly\\Model\\Order',
            $this->name()
        ));
    }
326876
public function sendNotifications(array &$failedAddresses)
    {
        // get all recipientIds with pending notifications in the database, that are due to be sent
        $recipientIds = $this->getNotificationRecipientIds();

        // get vars that are the same for all recipients of this notification-mail-batch
        $params = $this->getVarsForNotificationsEmail();

        $notificationsTemplate = $this->configParameter[AzineEmailExtension::TEMPLATES.'_'.AzineEmailExtension::NOTIFICATIONS_TEMPLATE];

        $sentCount = 0;
        foreach ($recipientIds as $recipientId) {
            // send the mail for this recipient
            $failedAddress = $this->sendNotificationsFor($recipientId, $notificationsTemplate, $params);
            if (null !== $failedAddress && strlen($failedAddress) > 0) {
                $failedAddresses[] = $failedAddress;
            } else {
                ++$sentCount;
            }
        }

        return $sentCount;
    }
822433
public function setReadReceiptTo($addresses)
    {
        if (!$this->setHeaderFieldModel('Disposition-Notification-To', $addresses)) {
            $this->getHeaders()
                ->addMailboxHeader('Disposition-Notification-To', $addresses);
        }

        return $this;
    }
986606
public function emailOutputTo($addresses, $onlyIfOutputExists = false)
    {
        $this->ensureOutputIsBeingCapturedForEmail();

        if (! is_array($addresses)) {
            $addresses = array($addresses);
        }

        return $this->then(function (Mailer $mailer) use ($addresses, $onlyIfOutputExists)
        {
            $this->emailOutput($mailer, $addresses, $onlyIfOutputExists);
        });
    }
880518
private function decodeEmailAddresses(array $addresses): array
    {
        $return = [];
        foreach ($addresses as $address) {
            if (isset($address->mailbox)) {
                $return[] = $this->decodeEmailAddress($address);
            }
        }

        return $return;
    }
198762
public function replyTo($emailAddress, $name = null)
    {
        $this->message->setReplyTo((string)$emailAddress, (string)$name);
        return $this;
    }
1143783
public function update(string $address, array $parameters = [])
    {
        Assert::stringNotEmpty($address);
        Assert::isArray($parameters);

        foreach ($parameters as $field => $value) {
            switch ($field) {
                case 'address':
                case 'name':
                case 'description':
                    Assert::stringNotEmpty($value);

                    break;
                case 'access_level':
                    Assert::oneOf($value, ['readonly', 'members', 'everyone']);

                    break;
            }
        }

        $response = $this->httpPut(sprintf('/v3/lists/%s', $address), $parameters);

        return $this->hydrateResponse($response, UpdateResponse::class);
    }
1326719
public function addMailboxListHeader(string $name, array $addresses)
    {
        return $this->add(new MailboxListHeader($name, Address::createArray($addresses)));
    }
674021
public function setAddress(array $address)
    {
        if (!empty($address) && is_array($address)) {
            $this->address = $address;
        }

        return $this;
    }
865321
public function addRecipients($recipients)
    {
        try {
            if (is_array($recipients)) {
                foreach ($recipients as $recipientsOne) {
                    $this->addRecipient($recipientsOne);
                }
            } else {
                $this->addRecipient($recipientsOne);
            }
        } catch (\Exception $e) {
            return false;
        }

        return true;
    }
529797
protected static function format_addresses($addresses)
	{
		$return = array();

		foreach ($addresses as $recipient)
		{
			$recipient['name'] and $recipient['email'] = '"'.$recipient['name'].'" <'.$recipient['email'].'>';
			$return[] = $recipient['email'];
		}

		return join(', ', $return);
	}
519311
public function addMailboxHeader($name, $addresses = null)
    {
        $this->storeHeader($name, $this->factory->createMailboxHeader($name, $addresses));
    }
630026
private function adaptAddresses(array $addresses): array
    {
        $adapted = [];
        foreach ($addresses as $address) {
            if ($address->name() !== null) {
                $adapted[$address->email()] = $address->name();
            } else {
                $adapted[] = $address->email();
            }
        }

        return $adapted;
    }