-
Notifications
You must be signed in to change notification settings - Fork 0
Kh/dev/mail adjustments #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 = ''; | ||
|
|
@@ -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); | ||
|
bromiesTM marked this conversation as resolved.
|
||
|
|
||
| // 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; | ||
|
Comment on lines
+103
to
+151
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lgtm. But the whole concept of this file html breaking needs to updated for a proper solution maybe in a later PR. Also, a minor improvement can be made. 'Sharewith' check can be moved in the Priority 1 check, as it is same for the And is 3rd priority to find with Also the email lookup can be made if there is an "@" in data, so the lookup is more faster and won't pass any other data to Code snippet:
This comment was marked as duplicate.
Sorry, something went wrong.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Arsalanulhaq regarding strat 3 with Also
Thats why I had it in the strat 2 |
||
| } | ||
|
|
||
| /** | ||
|
|
||
| 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"> |
Uh oh!
There was an error while loading. Please reload this page.