@param Model $recipient

@return bool
327599
public function canFollow(Model $recipient)
    {
        if (!property_exists($recipient, 'canBeFollowed') || !$recipient->canBeFollowed) {
            return false;
        }

        if (!$recipient->canBeFollowedBy($this)) {
            return false;
        }

        // if user has Blocked the recipient and changed his mind
        // he can send a follow request after unblocking
        if ($this->hasBlockedBeingFollowedBy($recipient)) {
            $this->unblockBeingFollowedBy($recipient);
        }

        return true;
    }
482704
public function hasBlocked(Model $recipient): bool
    {
        return $this->getFriendship($recipient)->status === Status::BLOCKED;
    }
1339745
public function hasSentFriendRequestTo(Model $recipient)
    {
        return Friendship::whereRecipient($recipient)->whereSender($this)->whereStatus(Status::PENDING)->exists();
    }
218657
public function sendMail(
        $recipient,
        $templatePath,
        $data = array(),
        $blindCopyRecipients = array()
    ) {
        $tmplData = array_merge(
            $data,
            array(
                'footerTxt' => $this->templateFooterTxtPath,
                'footerHtml' => $this->templateFooterHtmlPath,
            )
        );

        // Load template from twig.
        $template = $this->twig->loadTemplate($templatePath);

        // Merge twig globals so that they also are available in renderBlock.
        $tmplData = $this->twig->mergeGlobals($tmplData);

        // Get subject from block.
        $subject = $template->renderBlock('subject', $tmplData);

        $emailBodyText = $template->renderBlock('body_text', $tmplData);
        $emailBodyHtml = $template->renderBlock('body_html', $tmplData);

        /** @var \Swift_Message $message */
        $message = \Swift_Message::newInstance()
            ->setSubject($subject)
            ->setFrom($this->emailFrom)
            ->setTo($recipient)
            ->setBody($emailBodyText, 'text/plain')
            ->addPart($emailBodyHtml, 'text/html');
        
        // add blind copy recipients
        foreach ($blindCopyRecipients as $bcc) {
            $message->addBcc($bcc);
        }

        $failedRecipients = array();
        $this->mailer->send($message, $failedRecipients);

        if (count($failedRecipients) > 0) {
            $this->writeLog('Could not send mail to the following recipients: ' . join(', ', $failedRecipients));

            return false;
        }

        return true;
    }
695441
private function findFriendship(Model $recipient): Builder
    {
        return Friend::where(function ($query) use ($recipient) {
            $query->where('sender_id', $this->id);
            $query->where('sender_type', get_class($this));

            $query->where('recipient_id', $recipient->id);
            $query->where('recipient_type', get_class($recipient));
        })->orWhere(function ($query) use ($recipient) {
            $query->where('sender_id', $recipient->id);
            $query->where('sender_type', get_class($recipient));

            $query->where('recipient_id', $this->id);
            $query->where('recipient_type', get_class($this));
        });
    }
658
public function decryptUsingKey(JWE &$jwe, JWK $jwk, int $recipient): bool
    {
        $jwkset = new JWKSet([$jwk]);

        return $this->decryptUsingKeySet($jwe, $jwkset, $recipient);
    }
237204
protected function getNotificationsFor(RecipientInterface $recipient)
    {
        // get the notification mode
        $notificationMode = $recipient->getNotificationMode();

        // get the date/time of the last notification
        $lastNotificationDate = $this->getNotificationRepository()->getLastNotificationDate($recipient->getId());

        $sendNotifications = false;
        $timeDelta = time() - $lastNotificationDate->getTimestamp();

        if (RecipientInterface::NOTIFICATION_MODE_IMMEDIATELY == $notificationMode) {
            $sendNotifications = true;
        } elseif (RecipientInterface::NOTIFICATION_MODE_HOURLY == $notificationMode) {
            $sendNotifications = ($timeDelta > $this->getHourInterval());
        } elseif (RecipientInterface::NOTIFICATION_MODE_DAYLY == $notificationMode) {
            $sendNotifications = ($timeDelta > $this->getDayInterval());
        } elseif (RecipientInterface::NOTIFICATION_MODE_NEVER == $notificationMode) {
            $this->markAllNotificationsAsSentFarInThePast($recipient);

            return array();
        }

        // regularly sent notifications now
        if ($sendNotifications) {
            $notifications = $this->getNotificationRepository()->getNotificationsToSend($recipient->getId());

        // if notifications exist, that should be sent immediately, then send those now disregarding the users mailing-preferences.
        } else {
            $notifications = $this->getNotificationRepository()->getNotificationsToSendImmediately($recipient->getId());
        }

        return $notifications;
    }
1012879
protected function normalizeRecipient($recipient)
    {
        if (is_array($recipient)) {
            return (object) $recipient;
        } elseif (is_string($recipient)) {
            return (object) ['email' => $recipient];
        }

        return $recipient;
    }
188542
public function hasBlocked(Model $recipient)
    {
        return $this->friends()->whereRecipient($recipient)->whereStatus(Status::BLOCKED)->exists();
    }
633491
public function contact($email)
    {
        if ($this->validate()) {
            Yii::$app->mailer->compose()
                ->setTo($email)
                ->setFrom([Yii::$app->params['senderEmail'] => Yii::$app->params['senderName']])
                ->setReplyTo([$this->email => $this->name])
                ->setSubject($this->subject)
                ->setTextBody($this->body)
                ->send();

            return true;
        }
        return false;
    }
850049
protected function sendMail(Message $mail): bool
    {
        $allRecipients = $mail->getTo() + $mail->getCc() + $mail->getBcc();
        $totalNumberOfRecipients = count($allRecipients);
        $actualNumberOfRecipients = 0;
        $exceptionMessage = '';

        try {
            $actualNumberOfRecipients = $mail->send();
        } catch (\Exception $e) {
            $exceptionMessage = $e->getMessage();
            if ($this->logSendingErrors === self::LOG_LEVEL_LOG) {
                $this->systemLogger->logException($e);
            } elseif ($this->logSendingErrors === self::LOG_LEVEL_THROW) {
                throw $e;
            }
        }

        $emailInfo = [
            'recipients' => array_keys($mail->getTo() + $mail->getCc() + $mail->getBcc()),
            'failedRecipients' => $mail->getFailedRecipients(),
            'subject' => $mail->getSubject(),
            'id' => (string)$mail->getHeaders()->get('Message-ID')
        ];
        if (strlen($exceptionMessage) > 0) {
            $emailInfo['exception'] = $exceptionMessage;
        }

        if ($actualNumberOfRecipients < $totalNumberOfRecipients && $this->logSendingErrors === self::LOG_LEVEL_LOG) {
            $this->systemLogger->log(
                sprintf('Could not send an email to all given recipients. Given %s, sent to %s', $totalNumberOfRecipients, $actualNumberOfRecipients),
                LOG_ERR, $emailInfo);
            return false;
        }

        if ($this->logSendingSuccess === self::LOG_LEVEL_LOG) {
            $this->systemLogger->log('Email sent successfully.', LOG_INFO, $emailInfo);
        }
        return true;
    }
1185419
public function fire($recipient, $message)
    {
        // because we cant use "$message" on Laravel emails
        $msg = $message;

        try {
            Mail::send('eyewitness::email.notification', ['recipient' => $recipient, 'msg' => $msg], function ($m) use ($recipient, $msg) {
                $m->to($recipient->address);
                $m->subject($msg->title());
            });
        } catch (Exception $e) {
            app(Eye::class)->logger()->error('Unable to send Email noitification', $e);
        }
    }
332958
public function removeRecipient(string $recipient): self
    {
        $itemPosition = array_search($recipient, $this->recipients);

        if (false !== $itemPosition) {
            unset($this->recipients[$itemPosition]);
        }

        unset($this->recipientVariables[$recipient]);

        return $this;
    }
386531
public function addRecipient($recipient)
    {
        if (!is_string($recipient)) {
            throw new \Exception('Recipient is not string.');
        }

        try {
            $new = new EmailUser;
            $new->email = $recipient;

            $this->addRecipientUser($new);
        } catch (\Exception $e) {
            return false;
        }

        return true;
    }
491704
public function notify(Model $model, Model $recipient): Mention
    {
        $pool = $this->pool($recipient);

        $notificationClass = class_exists($pool->notification) ? $pool->notification : $this->mentionNotification;

        if (class_exists($notificationClass)) {
            $recipient->notify(new $notificationClass($model));
        }

        return $this;
    }
415853
private function addressee_exists(string $addressee, array $lists = []): bool {
		foreach ($this->recipients as $recipient_list => $recipients) {
			if (in_array($recipient_list, $lists) or count($lists) === 0) {
				foreach ($recipients as $recipient) {
					if ($recipient['email'] == $addressee) {
						return true;
					}
				}
			}
		}

		return false;
	}
713149
private function sendEmailMessage($content, $from, $recipient)
    {
        $lines = explode(PHP_EOL, trim($content));
        $subject = $lines[0];
        $body = implode(PHP_EOL, array_slice($lines, 1));

        try {
            $mail = new \Swift_Message();
            $mail
                ->setSubject($subject)
                ->setBody($body)
                ->setFrom($from)
                ->addTo($recipient);

            $this->mailer->send($mail);
        } catch (\Exception $e) {
            $this->logger->error(__METHOD__.' failed to send mail: '.$e->getMessage());

            return false;
        }

        return true;
    }