Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 89 additions & 5 deletions lib/EMailTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
use OC\Mail\EMailTemplate as ParentTemplate;
use OCA\NcwMailtemplate\AppInfo\Application;
use OCP\Defaults;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory;

class EMailTemplate extends ParentTemplate {
private IL10N $l;
private ?IUser $user = null;

// Generated asset URLs (filled in constructor)
private string $spacerUrl = '';
Expand Down Expand Up @@ -54,17 +58,97 @@ public function __construct(
?int $logoHeight,
string $emailId,
array $data = [],
) {
) {
// Initialize parent first to set up basic properties
parent::__construct($defaults, $urlGenerator, $l10nFactory, $logoWidth, $logoHeight, $emailId, $data);

// Initialize localization object
$this->l = $l10nFactory->get(Application::APP_ID);

// Try to get user from various sources (for recipient's language)
$this->user = $this->determineUser($this->data);

// Get language: user's preference, or system default
if ($this->user) {
$lang = $this->l10nFactory->getUserLanguage($this->user);
} else {
$config = \OC::$server->get(IConfig::class);
$lang = $config->getSystemValue('default_language', 'en');
}
$this->l = $this->l10nFactory->get(Application::APP_ID, $lang);

// Generate URLs for template assets
$this->generateTemplateAssetUrls($urlGenerator);

// Load all HTML template files
// Load all HTML template files - this will override parent's head and tail
$this->loadHtmlTemplateFiles();

// Replace the parent's htmlBody that was set with the parent's head
// with our custom head
$this->htmlBody = $this->head;
}

/**
* Determine the user for this email template
* Tries multiple sources: data array keys, current logged-in user, etc.
*
* Supported data keys (from various email types):
* - userid: from settings.Welcome
* - emailAddress: from settings.PasswordChanged, settings.EmailChanged
* - newEMailAddress: from settings.EmailChanged
* - shareWith: from file sharing emails (can be email or user ID)
* - displayname: from various emails
* - attendee_name: from calendar invitation emails
*
* @param array $data
* @return IUser|null
*/
private function determineUser(array $data): ?IUser {
$userManager = \OC::$server->get(IUserManager::class);

// Priority 1: Try to get recipient by user ID (most direct)
$userIdKeys = ['userid', 'userId', 'uid'];
foreach ($userIdKeys as $key) {
if (isset($data[$key]) && is_string($data[$key])) {
$user = $userManager->get($data[$key]);
if ($user instanceof IUser) {
return $user;
}
}
}

// Priority 2: Try to get recipient by email address
$emailKeys = ['emailAddress', 'newEMailAddress', 'shareWith'];
foreach ($emailKeys as $key) {
if (isset($data[$key]) && is_string($data[$key]) && str_contains($data[$key], '@')) {
$value = $data[$key];

// Try to get user by email address
$users = $userManager->getByEmail($value);
if (!empty($users)) {
return reset($users);
}
}
}

// Priority 3: Try attendee_name or displayname as user ID or display name search
$nameKeys = ['attendee_name', 'displayname'];
foreach ($nameKeys as $key) {
if (isset($data[$key]) && is_string($data[$key])) {
$value = $data[$key];

// First try as user ID
$user = $userManager->get($value);
if ($user instanceof IUser) {
return $user;
}

// Then try as display name search
$users = $userManager->searchDisplayName($value, 1);
if (!empty($users)) {
return reset($users);
}
}
}

return null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/templates/email/bodyEnd.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- Start bodyEnd -->
<p class="footer-greeting" style="padding:0 0 0 0;margin:0;text-align:left;line-height:20px" >
<font class="footer-font" style="font-family:\'Open Sans\', \'Google Sans\', Arial, sans-serif;font-size:15px;font-weight:normal;color:#465A75;line-height:20px" ><?= $l->t('Best regards')?><br/>IONOS SE<br/></font>
<font class="footer-font" style="font-family:\'Open Sans\', \'Google Sans\', Arial, sans-serif;font-size:15px;font-weight:normal;color:#001B41;line-height:20px" ><?= $l->t('Best regards')?><br/>IONOS SE<br/></font>
</p>
</td>
<td width="20" style="min-width:20px;width:20px;line-height:1px;font-size:0px" >
Expand Down
2 changes: 1 addition & 1 deletion lib/templates/email/bodyText.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- Start bodyText-->
<p class="body-text" style="padding:0 0 0 0;margin:0;text-align:left;line-height:20px" >
<font class="body-font" style="font-family:\'Open Sans\', \'Google Sans\', Arial, sans-serif;font-size:15px;font-weight:normal;color:#465A75;line-height:20px" >
<font class="body-font" style="font-family:\'Open Sans\', \'Google Sans\', Arial, sans-serif;font-size:15px;font-weight:normal;color:#001B41;line-height:20px" >
%s
</font>
</p>
Expand Down
2 changes: 1 addition & 1 deletion lib/templates/email/button.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<table cellpadding="0" cellspacing="0" border="0" name="halign" width="100%%" style="width:100%%;border-spacing:0" >
<tr valign="top" >
<td align="center" >
<a href="%3$s" class="button" target="_blank" style="background-color: rgb(17, 199, 230);border: 2px solid rgb(17, 199, 230);border-radius: 40px;box-sizing: border-box;color: rgb(11, 42, 99);cursor: pointer;display: inline-grid;font-size: 12px;font-weight: 600;height: 36px;line-height: 20px;padding: 6px 12px;text-align: center;text-decoration: none;">
<a href="%3$s" class="button" target="_blank" style="background-color: rgb(17, 199, 230);border: 2px solid rgb(17, 199, 230);border-radius: 40px;box-sizing: border-box;color: rgb(11, 42, 99);cursor: pointer;display: inline-grid;font-size: 15px;font-weight: 600;height: 36px;line-height: 20px;padding: 6px 12px;text-align: center;text-decoration: none;">
%7$s
</a>
</td>
Expand Down
4 changes: 2 additions & 2 deletions lib/templates/email/buttonGroup.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<table cellpadding="0" cellspacing="0" border="0" name="halign" width="100%%" style="width:100%%;border-spacing:0" >
<tr valign="top" >
<td align="center" >
<a href="%3$s" class="button" target="_blank" style="background-color: rgb(17, 199, 230);border: 2px solid rgb(17, 199, 230);border-radius: 40px;box-sizing: border-box;color: rgb(11, 42, 99);cursor: pointer;display: inline-grid;font-size: 12px;font-weight: 600;height: 36px;line-height: 20px;padding: 6px 12px;text-align: center;text-decoration: none;">
<a href="%3$s" class="button" target="_blank" style="background-color: rgb(17, 199, 230);border: 2px solid rgb(17, 199, 230);border-radius: 40px;box-sizing: border-box;color: rgb(11, 42, 99);cursor: pointer;display: inline-grid;font-size: 15px;font-weight: 600;height: 36px;line-height: 20px;padding: 6px 12px;text-align: center;text-decoration: none;">
%7$s
</a>
</td>
<td align="center" >
<a href="%8$s" class="button" target="_blank" style="background-color: rgb(17, 199, 230);border: 2px solid rgb(17, 199, 230);border-radius: 40px;box-sizing: border-box;color: rgb(11, 42, 99);cursor: pointer;display: inline-grid;font-size: 12px;font-weight: 600;height: 36px;line-height: 20px;padding: 6px 12px;text-align: center;text-decoration: none;">
<a href="%8$s" class="button" target="_blank" style="background-color: rgb(17, 199, 230);border: 2px solid rgb(17, 199, 230);border-radius: 40px;box-sizing: border-box;color: rgb(11, 42, 99);cursor: pointer;display: inline-grid;font-size: 15px;font-weight: 600;height: 36px;line-height: 20px;padding: 6px 12px;text-align: center;text-decoration: none;">
%9$s
</a>
</td>
Expand Down
4 changes: 2 additions & 2 deletions lib/templates/email/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
</td>
<td align="left" >
<p class="footer-address" style="padding:0 0 0 0;margin:0;text-align:left;line-height:18px" >
<font class="footer-address-font" style="font-family:\'Open Sans\', \'Google Sans\', Arial, sans-serif;font-size:14px;font-weight:normal;color:#465A75;line-height:18px" >IONOS SE
<font class="footer-address-font" style="font-family:\'Open Sans\', \'Google Sans\', Arial, sans-serif;font-size:15px;font-weight:normal;color:#001B41;line-height:18px" >IONOS SE
<br/>Elgendorfer Straße 57
<br/>56410 Montabaur
<br/><?= $l->t('Germany')?>
</font>
</p>
<p>
<a href="https://ionos.eu" class="footer-link" style="font-family:\'Open Sans\', \'Google Sans\', Arial, sans-serif;font-size:14px;font-weight:normal;color:#465A75;line-height:18px" target="_blank"><?= $l->t('Further information')?></a>
<a href="https://ionos.eu" class="footer-link" style="font-family:\'Open Sans\', \'Google Sans\', Arial, sans-serif;font-size:16px;font-weight:normal;color:#001B41;line-height:18px" target="_blank"><?= $l->t('Further information')?></a>
</p>
<table cellpadding="0" cellspacing="0" border="0" width="100%%" >
<tr>
Expand Down
146 changes: 14 additions & 132 deletions lib/templates/email/head.html
Original file line number Diff line number Diff line change
@@ -1,133 +1,15 @@
<!-- start head -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
<meta name="x-apple-disable-message-reformatting" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="format-detection" content="date=no" />
<meta name="format-detection" content="address=no" />
<meta name="format-detection" content="email=no" />
<title></title>
<style type="text/css" >
table,td {
mso-table-lspace: 0pt !important;
mso-table-rspace: 0pt !important;
}
img {
-ms-interpolation-mode:bicubic;
}
@media only screen and (max-width: 580px) {
.h-15 {height:15px !important;}
.w-20 {width:20px !important;}
.minw-20 {min-width:20px !important;}
.h-25 {height:25px !important;}
.h-12 {height:12px !important;}
.h-10 {height:10px !important;}
.inline-block {display:inline-block !important;}
.w-100 {width:100%% !important;}
.minw-100 {min-width:100%% !important;}
.v-top {vertical-align:top !important;}
.w-80 {width:80px !important;}
.minw-80 {min-width:80px !important;}
.h-80 {height:80px !important;}
.minh-80 {min-height:80px !important;}
.w-280 {width:280px !important;}
.w-580 {width:580px !important;}
.minw-580 {min-width:580px !important;}
.w-640 {width:640px !important;}
.minw-640 {min-width:640px !important;}


@media only screen and (min-width: 1900px) {
.h-15 {height:15px !important;}
.w-340 {width:340px !important;}
.minw-340 {min-width:340px !important;}
.w-20 {width:20px !important;}
.minw-20 {min-width:20px !important;}
.h-25 {height:25px !important;}
.h-12 {height:12px !important;}
.h-20 {height:20px !important;}
.h-10 {height:10px !important;}
.inline-block {display:inline-block !important;}
.w-33 {width:33.3%% !important;}
.minw-33 {min-width:33.3%% !important;}
.v-top {vertical-align:top !important;}
.text-left {text-align:left !important;}
.text-right {text-align:right !important;}
.w-100 {width:100%% !important;}
.w-25 {width:25px !important;}
.minw-25 {min-width:25px !important;}
.w-100px {width:100px !important;}
.minw-100px {min-width:100px !important;}
.h-100 {height:100px !important;}
.minh-100 {min-height:100px !important;}
.w-353 {width:353px !important;}
.h-32 {height:32px !important;}
.w-175 {width:175px !important;}
.w-680 {width:680px !important;}
.minw-680 {min-width:680px !important;}
.w-740 {width:740px !important;}
.minw-740 {min-width:740px !important;}
}
}
.button {
background-color: rgb(17, 199, 230);
border: 2px solid rgb(17, 199, 230);
border-radius: 40px;
border-image-outset: 0;
border-image-repeat: stretch;
border-image-slice: 100%;
border-image-source: none;
border-image-width: 1;
box-shadow: rgba(0, 0, 0, 0) 0px 0px 0px 0px, rgba(0, 0, 0, 0) 0px 0px 0px 0px, rgba(0, 0, 0, 0) 0px 2px 12px 0px;
box-sizing: border-box;
color: rgb(11, 42, 99);
cursor: pointer;
display: inline-grid;
font-feature-settings: normal;
font-size: 12px;
font-variation-settings: normal;
font-weight: 600;
height: 36px;
line-height: 20px;
outline-color: rgba(0, 0, 0, 0);
outline-offset: 2px;
outline-style: solid;
outline-width: 2px;
padding: 6px 12px;
tab-size: 4;
text-align: center;
text-decoration-color: rgb(11, 42, 99);
text-decoration-line: none;
text-decoration-style: solid;
text-decoration-thickness: auto;
text-size-adjust: 100%;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
@media all {
.inline-block {display:inline-block !important;}
}
</style>
<!--[if mso]><style>* {font-family: Arial,sans-serif !important;}</style><![endif]-->
<!--[if !mso]><!-->
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Overpass:400,600,700" rel="stylesheet" type="text/css">
<!--<![endif]-->
<!--[if gte mso 9]>
<xml><o:OfficeDocumentSettings><o:AllowPNG/><o:PixelsPerInch>96</o:PixelsPerInch></o:OfficeDocumentSettings></xml>
<![endif]-->
</head>
<body topmargin="0" rightmargin="0" leftmargin="0" style="background-color:#FFFFFF;-webkit-text-size-adjust:none;font-family:\'Open Sans\', \'Google Sans\', Arial, sans-serif;font-stretch:normal;font-style:normal;font-weight:normal;font-variant:normal;font-size:1.2rem" link="#3B9CDA" text="#465A75" vlink="#3B9CDA" alink="#3B9CDA" bgcolor="#FFFFFF">
<div class="body-bg" style="background-color:#FFFFFF;width:100%%" bgcolor="#FFFFFF">
<div class="pad" style="padding-top:0px;padding-right:0px;padding-bottom:30px;padding-left:0px">
<!--[if mso]>
<style>.nomsoffice{mso-hide:all;visibility:hidden;}</style>
<![endif]-->
<a name="nltop"></a>
<table class="layout-wrapper w-740 minw-740" cellpadding="0" cellspacing="0" border="0" width="740" align="center" style="width:740px;border-spacing:0" >
<tr valign="top" >
<td class="w-740 minw-740 bg-white" width="740" align="left" bgcolor="#FFFFFF" style="background-color:#FFFFFF;min-width:740px;width:740px" >
<!-- End head -->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" style="-webkit-font-smoothing:antialiased;background:#fff!important">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width">
<title></title>
<style type="text/css">@media only screen{html{min-height:100%;background:#fff}}@media only screen and (max-width:610px){table.body img{width:auto;height:auto}table.body center{min-width:0!important}table.body .container{width:95%!important}table.body .columns{height:auto!important;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;padding-left:30px!important;padding-right:30px!important}th.small-12{display:inline-block!important;width:100%!important}table.menu{width:100%!important}table.menu td,table.menu th{width:auto!important;display:inline-block!important}table.menu.vertical td,table.menu.vertical th{display:block!important}table.menu[align=center]{width:auto!important}}</style>
</head>
<body style="-moz-box-sizing:border-box;-ms-text-size-adjust:100%;-webkit-box-sizing:border-box;-webkit-font-smoothing:antialiased;-webkit-text-size-adjust:100%;margin:0;background:#fff!important;box-sizing:border-box;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;min-width:100%;padding:0;text-align:left;width:100%!important">
<span class="preheader" style="color:#F5F5F5;display:none!important;font-size:1px;line-height:1px;max-height:0;max-width:0;mso-hide:all!important;opacity:0;overflow:hidden;visibility:hidden">
</span>
<table class="body" style="-webkit-font-smoothing:antialiased;margin:0;background:#fff;border-collapse:collapse;border-spacing:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;width:100%">
<tr style="padding:0;text-align:left;vertical-align:top">
<td class="center" align="center" valign="top" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
<center data-parsed="" style="width:100%;max-width:740px;margin:auto">
Loading
Loading