|
19 | 19 | use OCP\L10N\IFactory as L10NFactory; |
20 | 20 | use OCP\Mail\EMailDetails; |
21 | 21 | use OCP\Mail\IEMailTemplate; |
| 22 | +use OCP\Mail\IMailer; |
22 | 23 | use OCP\Security\ISecureRandom; |
23 | 24 | use Sabre\VObject\Component\VCalendar; |
24 | 25 | use Sabre\VObject\Component\VEvent; |
@@ -77,6 +78,7 @@ public function __construct( |
77 | 78 | private readonly IUserManager $userManager, |
78 | 79 | private readonly IUserConfig $userConfig, |
79 | 80 | private readonly IAppConfig $appConfig, |
| 81 | + private readonly IMailer $mailer, |
80 | 82 | ) { |
81 | 83 | $language = $this->l10nFactory->findGenericLanguage(); |
82 | 84 | $locale = $this->l10nFactory->findLocale($language); |
@@ -150,6 +152,117 @@ public function diffInstance(VEvent $newEvent, VEvent $oldEvent): array { |
150 | 152 | return $changed; |
151 | 153 | } |
152 | 154 |
|
| 155 | + /** |
| 156 | + * Builds the full REQUEST invitation/update email, including the |
| 157 | + * old-vs-new diff and, when the recipient is eligible, the Accept/Decline |
| 158 | + * response buttons. |
| 159 | + */ |
| 160 | + public function buildRequestEmail( |
| 161 | + Message $iTipMessage, |
| 162 | + VEvent $vEvent, |
| 163 | + ?VEvent $oldVevent, |
| 164 | + Property $attendee, |
| 165 | + string $recipient, |
| 166 | + ?string $recipientName, |
| 167 | + string $sender, |
| 168 | + ?string $senderName, |
| 169 | + int $lastOccurrence, |
| 170 | + ): IEMailTemplate { |
| 171 | + $data = $this->withRecipientNames($this->buildBodyData($vEvent, $oldVevent), $recipient, $recipientName, $sender, $senderName); |
| 172 | + |
| 173 | + $template = $this->newTemplate(IMipPlugin::METHOD_REQUEST, $data, $senderName !== null ? $sender : ''); |
| 174 | + $this->addSubjectAndHeading($template, IMipPlugin::METHOD_REQUEST, $data['invitee_name'], $data['meeting_title'], $oldVevent !== null); |
| 175 | + $this->addEventDetails($template, $vEvent, $data); |
| 176 | + |
| 177 | + // Only add response buttons to invitation requests: Fix Issue #11230 |
| 178 | + if ($this->getAttendeeRsvpOrReqForParticipant($attendee)) { |
| 179 | + /* |
| 180 | + ** Only offer invitation accept/reject buttons, which link back to the |
| 181 | + ** nextcloud server, to recipients who can access the nextcloud server via |
| 182 | + ** their internet/intranet. Issue #12156 |
| 183 | + ** |
| 184 | + ** The app setting is stored in the appconfig database table. |
| 185 | + ** |
| 186 | + ** For nextcloud servers accessible to the public internet, the default |
| 187 | + ** "invitation_link_recipients" value "yes" (all recipients) is appropriate. |
| 188 | + ** |
| 189 | + ** When the nextcloud server is restricted behind a firewall, accessible |
| 190 | + ** only via an internal network or via vpn, you can set "dav.invitation_link_recipients" |
| 191 | + ** to the email address or email domain, or comma separated list of addresses or domains, |
| 192 | + ** of recipients who can access the server. |
| 193 | + ** |
| 194 | + ** To always deliver URLs, set invitation_link_recipients to "yes". |
| 195 | + ** To suppress URLs entirely, set invitation_link_recipients to boolean "no". |
| 196 | + */ |
| 197 | + $recipientDomain = substr(strrchr($recipient, '@'), 1); |
| 198 | + $invitationLinkRecipients = explode(',', preg_replace('/\s+/', '', strtolower($this->appConfig->getValueString('dav', 'invitation_link_recipients', 'yes')))); |
| 199 | + |
| 200 | + if (strcmp('yes', $invitationLinkRecipients[0]) === 0 |
| 201 | + || in_array(strtolower($recipient), $invitationLinkRecipients, true) |
| 202 | + || in_array(strtolower($recipientDomain), $invitationLinkRecipients, true)) { |
| 203 | + $token = $this->createInvitationToken($iTipMessage, $vEvent, $lastOccurrence); |
| 204 | + $this->addResponseButtons($template, $token); |
| 205 | + } |
| 206 | + } |
| 207 | + |
| 208 | + $template->addFooter(); |
| 209 | + return $template; |
| 210 | + } |
| 211 | + |
| 212 | + /** |
| 213 | + * Builds the REPLY email an organizer receives when an attendee responds. |
| 214 | + */ |
| 215 | + public function buildReplyEmail( |
| 216 | + Message $iTipMessage, |
| 217 | + VEvent $vEvent, |
| 218 | + string $recipient, |
| 219 | + ?string $recipientName, |
| 220 | + string $sender, |
| 221 | + ?string $senderName, |
| 222 | + ): IEMailTemplate { |
| 223 | + $data = $this->withRecipientNames($this->buildReplyBodyData($vEvent), $recipient, $recipientName, $sender, $senderName); |
| 224 | + |
| 225 | + $template = $this->newTemplate(IMipPlugin::METHOD_REPLY, $data, $senderName !== null ? $sender : ''); |
| 226 | + $replyingAttendee = $this->getReplyingAttendee($iTipMessage); |
| 227 | + $this->addSubjectAndHeading($template, IMipPlugin::METHOD_REPLY, $data['invitee_name'], $data['meeting_title'], false, $replyingAttendee); |
| 228 | + $this->addEventDetails($template, $vEvent, $data); |
| 229 | + $template->addFooter(); |
| 230 | + return $template; |
| 231 | + } |
| 232 | + |
| 233 | + /** |
| 234 | + * Builds the CANCEL email an attendee receives when dropped from an event. |
| 235 | + */ |
| 236 | + public function buildCancellationEmail( |
| 237 | + VEvent $vEvent, |
| 238 | + string $recipient, |
| 239 | + ?string $recipientName, |
| 240 | + string $sender, |
| 241 | + ?string $senderName, |
| 242 | + ): IEMailTemplate { |
| 243 | + $data = $this->withRecipientNames($this->buildCancelledBodyData($vEvent), $recipient, $recipientName, $sender, $senderName); |
| 244 | + |
| 245 | + $template = $this->newTemplate(IMipPlugin::METHOD_CANCEL, $data, $senderName !== null ? $sender : ''); |
| 246 | + $this->addSubjectAndHeading($template, IMipPlugin::METHOD_CANCEL, $data['invitee_name'], $data['meeting_title'], false); |
| 247 | + $this->addEventDetails($template, $vEvent, $data); |
| 248 | + $template->addFooter(); |
| 249 | + return $template; |
| 250 | + } |
| 251 | + |
| 252 | + private function withRecipientNames(array $data, string $recipient, ?string $recipientName, string $sender, ?string $senderName): array { |
| 253 | + $data['attendee_name'] = $recipientName ?: $recipient; |
| 254 | + $data['invitee_name'] = $senderName ?: $sender; |
| 255 | + return $data; |
| 256 | + } |
| 257 | + |
| 258 | + private function newTemplate(string $method, array $data, string $senderEmail): IEMailTemplate { |
| 259 | + $template = $this->mailer->createEMailTemplate('dav.calendarInvite.' . $method, $data); |
| 260 | + $template->setLanguage($this->getLanguageCode()); |
| 261 | + $template->addHeader(); |
| 262 | + $template->addBodySender($data['invitee_name'], $senderEmail); |
| 263 | + return $template; |
| 264 | + } |
| 265 | + |
153 | 266 | /** |
154 | 267 | * @param VEvent $vEvent |
155 | 268 | * @param VEvent|null $oldVEvent |
|
0 commit comments