├── .github ├── ISSUE_TEMPLATE │ ├── Bug_report.md │ ├── Feature_request.md │ └── Support_question.md ├── PULL_REQUEST_TEMPLATE.md └── SECURITY.md ├── CHANGELOG-1.0.md ├── CHANGELOG-1.1.md ├── Console └── RefreshMailboxCommand.php ├── Controller ├── MailboxChannel.php └── MailboxChannelXHR.php ├── DependencyInjection ├── Configuration.php └── UVDeskExtension.php ├── EventListener ├── Mailer.php └── Swiftmailer.php ├── LICENSE.txt ├── README.md ├── Resources ├── config │ ├── routes.yaml │ ├── routes │ │ ├── private.yaml │ │ └── public.yaml │ └── services │ │ ├── automations.yaml │ │ └── services.yaml └── views │ ├── listConfigurations.html.twig │ └── manageConfigurations.html.twig ├── Routing └── RoutingResource.php ├── Services └── MailboxService.php ├── Templates ├── Default.yaml └── Mailbox │ ├── IMAP │ ├── AppConfiguration.php │ ├── DefaultConfiguration.php │ └── SimpleConfiguration.php │ ├── Mailbox.php │ ├── MailboxSettings.php │ ├── SMTP │ ├── AppConfiguration.php │ └── DefaultConfiguration.php │ └── SwiftMailerSettings.php ├── UIComponents └── Dashboard │ ├── Homepage │ └── Items │ │ └── Mailbox.php │ ├── Panel │ └── Items │ │ └── Settings │ │ └── Mailboxes.php │ └── Search │ ├── Mailbox.php │ └── SwiftMailer.php ├── UVDeskMailboxBundle.php ├── Utils ├── IMAP │ ├── Configuration.php │ └── Transport │ │ ├── AppTransportConfigurationInterface.php │ │ ├── DefaultTransportConfigurationInterface.php │ │ ├── ResolvedTransportConfigurationInterface.php │ │ ├── SimpleTransportConfigurationInterface.php │ │ ├── TransportConfigurationInterface.php │ │ └── Type │ │ ├── Gmail.php │ │ ├── IMAP.php │ │ ├── Outlook.php │ │ ├── OutlookModernAuth.php │ │ ├── Webhook.php │ │ └── Yahoo.php ├── Imap │ ├── Configuration.php │ ├── ConfigurationInterface.php │ ├── CustomConfigurationInterface.php │ ├── ResolvedConfigurationInterface.php │ └── Transport │ │ ├── Custom.php │ │ ├── Gmail.php │ │ └── Yahoo.php ├── Mailbox │ └── Mailbox.php ├── MailboxConfiguration.php └── SMTP │ ├── Configuration.php │ └── Transport │ ├── AppTransportConfigurationInterface.php │ ├── DefaultTransportConfigurationInterface.php │ ├── ResolvedTransportConfigurationInterface.php │ ├── TransportConfigurationInterface.php │ └── Type │ ├── Gmail.php │ ├── Outlook.php │ ├── OutlookModernAuth.php │ ├── SMTP.php │ └── Yahoo.php ├── Workflow ├── Actions │ └── Email │ │ └── FromEmail.php └── Events │ └── Email │ └── EmailRecieved.php └── composer.json /.github/ISSUE_TEMPLATE/Bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🐛 Bug Report 3 | about: Report errors and problems 4 | 5 | --- 6 | 7 | **Description** 8 | 9 | 10 | **How to reproduce** 11 | 12 | 13 | **Possible Solution** 14 | 15 | 16 | **Additional context** 17 | 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/Feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🚀 Feature Request 3 | about: RFC and ideas for new features and improvements 4 | 5 | --- 6 | 7 | **Description** 8 | 9 | 10 | **Example** 11 | 13 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/Support_question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: ⛔ Support Question 3 | about: Visit https://support.uvdesk.com/ to learn more about how the uvdesk team can assist you 4 | 5 | --- 6 | 7 | We use GitHub issues only to discuss about uvdesk bugs and new features. For customizations and extended support: 8 | 9 | - Contact us at support@uvdesk.com 10 | - Visit official support website (https://support.uvdesk.com/en/) 11 | - Visit our community forums (https://forums.uvdesk.com) 12 | 13 | Thanks! 14 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 4 | 5 | ### 1. Why is this change necessary? 6 | 7 | 8 | ### 2. What does this change do, exactly? 9 | 10 | 11 | ### 3. Please link to the relevant issues (if any). 12 | -------------------------------------------------------------------------------- /.github/SECURITY.md: -------------------------------------------------------------------------------- 1 | Security Policy 2 | =============== 3 | 4 | ⚠ PLEASE DON'T DISCLOSE SECURITY-RELATED ISSUES PUBLICLY, SEE BELOW. 5 | 6 | If you have found a security issue in Uvdesk, please send the details to support@uvdesk.com and don't disclose it publicly until we can provide a fix for it. 7 | 8 | Thanks! 9 | -------------------------------------------------------------------------------- /CHANGELOG-1.0.md: -------------------------------------------------------------------------------- 1 | CHANGELOG for 1.0.x 2 | =================== 3 | 4 | This changelog references any relevant changes introduced in 1.0 minor versions. 5 | 6 | * 1.0.14 (2021-10-27) 7 | * **Misc. Updates:** 8 | * Compatibility with PHP 8. 9 | * Added Errors catch during ticket conversion using refresh mailbox command errors will show on console in case of any errror. 10 | * Added a manual check method to check ticket create process using raw content of emails. 11 | 12 | * **Issue #69:** upgrade php-mime-mail-parser version to 7. 13 | * **Issue #71:** Use IMAP IDLE to immediately get new tickets. 14 | * **Issue #72:** Error configuring CRONTAB. 15 | * **Issue #80:** Mailbox component doesn't extract inline image as attachment. 16 | * **Issue #81:** Received Emails not creating/updating tickets. 17 | 18 | * 1.0.13 (2021-08-23) 19 | * **Issue #399:** Reply from collaborator gmail so collaborator name is not showing. 20 | 21 | * **Misc. Updates:** 22 | * Lowercase and upercase check condition added for searching mailbox. 23 | * Option added for delete inbox emails after mails fetch and converted into ticket. 24 | * Collaborator reply threads added into ticket threads. 25 | 26 | * 1.0.12 (2021-08-21) 27 | * **Issue #399:** Reply from collaborator gmail so collaborator name is not showing. 28 | 29 | * **Misc. Updates:** 30 | * Lowercase and upercase check condition added for searching mailbox. 31 | * Option added for delete inbox emails after mails fetch and converted into ticket. 32 | * Collaborator reply threads added into ticket threads. 33 | 34 | * 1.0.11 (2021-06-19) 35 | * **Misc. Updates:** 36 | * Methods added for checking mailbox email exist in multiple to address mail and creating ticket for the same. 37 | 38 | * 1.0.10 (2021-04-02) 39 | 40 | * **Issue Fixes:** 41 | 42 | * **Issue #58:** MailboxService fails to create new ticket when to is not canonically defined. 43 | * **Issue #59:** getting exception when click on add new mailbox button. 44 | * **Issue #60:** mailbox is accessible by agent using search bar. 45 | * **Issue #61:** Email validation failure. 46 | * **Issue #62:** Email validation failure. 47 | * **Issue #64:** email are not converted into ticket as mailbox is case sensitive. 48 | * **Issue #65:** email are not converted into ticket if sent from web form. 49 | * **Issue #67:** The new MailboxService.php did not open ticket from emails. 50 | * **Issue #68:** Emails from same sender with same subject line not created. 51 | 52 | * **Misc. Updates:** 53 | * Controller updates as per symfony version 4.3 for removing depreciation messages. 54 | * Updates with precheck statement for ticket creation process. 55 | * Code updates for Auto-forwording and forwording emails updates. 56 | * Accept and convert both capitalize and non-capitalize email conversion. 57 | 58 | * 1.0.9 (2020-07-22) 59 | * **Issue #57:** Can't see embedded images in ticket. 60 | * **Issue #56:** refresh-mailbox produces Parse Error. 61 | 62 | * 1.0.8 (2020-05-26) 63 | * **Misc. Updates:** 64 | * Added some condition to remove redundency of tickets when more conversation between customer and agent and ticket get duplicates. 65 | 66 | * 1.0.7 (2020-04-17) 67 | * **Misc. Updates:** 68 | * Change processing function and removed unnecessary code for speed up. 69 | 70 | * 1.0.6 (2020-03-17) 71 | * **Misc. Updates:** 72 | * Added Missing Translations. 73 | 74 | * 1.0.5 (2020-02-12) 75 | * **Misc. Updates:** 76 | * Included Github issue templates. 77 | 78 | * 1.0.4 (2020-01-25) 79 | * **Issue #38:** Issue for imap host field when add host inside qoutes ' '. 80 | * **Issue #28:** Error while edit disable mailbox. 81 | * **Issue #50:** Email setting are not being update in production mode. 82 | * **Issue #51:** Duplicate entry for ticket when running refresh command second time. 83 | 84 | * 1.0.3 (2019-11-15) 85 | * **Issue #46:** IMAP not creating tickets 86 | * **Misc. Updates:** 87 | * Included Github issue templates 88 | * Updated composer dependencies & set minimum required php version to 7.2 89 | 90 | * 1.0.2 (2019-10-22) 91 | * **Misc. Updates:** 92 | * Use https when available while refreshing mailboxes via CLI 93 | * Updated README.md with link to the official gitter chat for uvdesk/mailbox-component 94 | 95 | * 1.0.1 (2019-10-15) 96 | * **Misc. Updates:** 97 | * Only users with admin level privileges can configure mailbox settings 98 | 99 | * 1.0.0 (Released on 2019-10-09) 100 | * **Issue #44:** Misc. fixes (raised by anmol107) 101 | * **Issue #14:** duplicate swiftmailer created with same email (raised by vaishaliwebkul) 102 | * **Issue #42:** SwiftMailer SVG update (raised by vaishaliwebkul) 103 | * **Issue #41:** Added Mailbox entry in Search list (raised by vaishaliwebkul) 104 | * **Issue #40:** Add search bar component items (raised by shubhwebkul) 105 | * **Issue #39:** Error when update swiftmailer configuration (raised by vaishaliwebkul) 106 | * **Issue #32:** IMAP host field is not mandatory (raised by vaishaliwebkul) 107 | * **Issue #35:** update template emailSettings.html (raised by vaishaliwebkul) 108 | * **Issue #31:** Mailbox fields missing when edit mailbox for imap transport (raised by vaishaliwebkul) 109 | * **Issue #15:** Swiftmailer gets deleted for setup mailbox (raised by vaishaliwebkul) 110 | * **Issue #16:** updated swiftmailer id not update into uvdesk.yaml (raised by vaishaliwebkul) 111 | * **Issue #33:** Confirm box must be appear while deleting a mailbox configuration (raised by vaishaliwebkul) 112 | * **Issue #30:** uvdesk.yml file update and issues (raised by kumarSaurabh27) 113 | * **Issue #22:** Swiftmailer update with blank mailer_id (raised by vaishaliwebkul) 114 | * **Issue #10:** Define maximum character length of mailbox name (raised by vaishaliwebkul) 115 | * **Issue #20:** Port not define for mailbox when set transport as IMAP (raised by vaishaliwebkul) 116 | * **Issue #27:** Resolve issue(thread was not creating) while creating the ticket via … (raised by papnoisanjeev) 117 | * **Issue #26:** Feature added to show progress in Mailbox refresh command and Issues. (raised by kumarSaurabh27) 118 | * **Issue #24:** Update Prefix in uvdesk.yaml (raised by vaishaliwebkul) 119 | * **Issue #18:** yahoo configuration issue with user password (raised by vaishaliwebkul) 120 | * **Issue #13:** Default site url set when update uvdesk.yaml[email settings] (raised by vaishaliwebkul) 121 | * **Issue #23:** mailbox-component issue-10 (raised by kumarSaurabh27) 122 | * **Issue #9:** Mailbox id not accept integer values (raised by vaishaliwebkul) 123 | * **Issue #12:** Error while deleting swiftmailer (raised by vaishaliwebkul) 124 | * **Issue #8:** Mailbox fields not sanitized properly (raised by vaishaliwebkul) 125 | * **Issue #21:** Always set automatically created mailbox id (raised by vaishaliwebkul) 126 | * **Issue #19:** Update message if mailbox configuration not found (raised by vaishaliwebkul) 127 | * **Issue #11:** blocked email check when creating ticket through mail (raised by papnoisanjeev) 128 | * **Issue #7:** resolved issue (raised by shubhwebkul) 129 | * **Issue #6:** Mailbox setup validation updates (raised by shubhwebkul) 130 | * **Issue #5:** Added a function in mailbox service for mailbox collection (raised by papnoisanjeev) 131 | * **Issue #4:** mailbox updates (raised by shubhwebkul) 132 | * **Issue #3:** resolved issues (raised by shubhwebkul) 133 | * **Issue #2:** resolved issues while configuring mailbox and refactored code (raised by shubhwebkul) 134 | * **Issue #1:** Decoupled Mailbox Component (raised by akshaywebkul) 135 | -------------------------------------------------------------------------------- /CHANGELOG-1.1.md: -------------------------------------------------------------------------------- 1 | CHANGELOG for 1.1.x 2 | =================== 3 | 4 | This changelog references any relevant changes introduced in 1.1 minor versions. 5 | 6 | * 1.1.5 7 | * Email Encoding related issues fixes. 8 | 9 | * 1.1.4 (2024-12-19) 10 | * Microsoft Modern App related updates. 11 | * License and support email address updates. 12 | * Code refactoring. 13 | 14 | * 1.1.3 (2023-06-12) 15 | * Update: Dropped dependency on uvdesk/composer-plugin in support of symfony/flex 16 | 17 | * 1.1.2 (2022-11-10) 18 | * Feature: Add improved log reports when refreshing mailboxes 19 | 20 | * 1.1.1 (2022-09-13) 21 | * Bug Fixes: Entity reference updates and other miscellaneous bug fixes 22 | 23 | * 1.1.0 (2022-03-23) 24 | * Feature: Improved compatibility with PHP 8 and Symfony 5 components 25 | * Bug #92: Check if replyTo headers is provided while processing mail content (vipin-shrivastava) 26 | * Bug #90: Fix ErrorException thrown on empty $mailData['replyTo']. (fiftyz) 27 | * Bug #88: Update mailbox configuration form placeholder values (vipin-shrivastava) 28 | * Bug #87: Update search criteria when looking up relevant threads based on inReplyTo reference ids (vipin-shrivastava) 29 | -------------------------------------------------------------------------------- /Console/RefreshMailboxCommand.php: -------------------------------------------------------------------------------- 1 | container = $container; 29 | $this->entityManager = $entityManager; 30 | $this->microsoftIntegration = $microsoftIntegration; 31 | $this->mailboxService = $mailboxService; 32 | 33 | parent::__construct(); 34 | } 35 | 36 | protected function configure() 37 | { 38 | $this 39 | ->setName('uvdesk:refresh-mailbox') 40 | ->setDescription('Check if any new emails have been received and process them into tickets') 41 | ->addArgument('emails', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, "Email address of the mailboxes you wish to update") 42 | ->addOption('timestamp', 't', InputOption::VALUE_REQUIRED, "Fetch messages no older than the given timestamp") 43 | ->addOption('secure', null, InputOption::VALUE_NONE, "Use HTTTPS for communicating with required api endpoints") 44 | ; 45 | } 46 | 47 | protected function initialize(InputInterface $input, OutputInterface $output) 48 | { 49 | $this->router = $this->container->get('router'); 50 | $useSecureConnection = $this->isSecureConnectionAvailable(); 51 | 52 | $this->router->getContext()->setHost($this->container->getParameter('uvdesk.site_url')); 53 | $this->router->getContext()->setScheme(false === $useSecureConnection ? 'http' : 'https'); 54 | 55 | $this->endpoint = $this->router->generate('helpdesk_member_mailbox_notification', [], UrlGeneratorInterface::ABSOLUTE_URL); 56 | $this->outlookEndpoint = $this->router->generate('helpdesk_member_outlook_mailbox_notification', [], UrlGeneratorInterface::ABSOLUTE_URL); 57 | } 58 | 59 | protected function execute(InputInterface $input, OutputInterface $output): int 60 | { 61 | // Sanitize emails 62 | $mailboxEmailCollection = array_map(function ($email) { 63 | return filter_var($email, FILTER_SANITIZE_EMAIL); 64 | }, $input->getArgument('emails')); 65 | 66 | // Stop execution if no valid emails have been specified 67 | if (empty($mailboxEmailCollection)) { 68 | if (false === $input->getOption('no-interaction')) { 69 | $output->writeln("\n No valid mailbox emails specified.\n"); 70 | } 71 | 72 | return Command::INVALID; 73 | } 74 | 75 | // Process mailboxes 76 | $timestamp = new \DateTime(sprintf("-%u minutes", (int) ($input->getOption('timestamp') ?: 1440))); 77 | 78 | foreach ($mailboxEmailCollection as $mailboxEmail) { 79 | $output->writeln("\n# Retrieving mailbox configuration details for $mailboxEmail:\n"); 80 | 81 | $mailboxConfigurations = $this->mailboxService->parseMailboxConfigurations(); 82 | $mailbox = $mailboxConfigurations->getIncomingMailboxByEmailAddress($mailboxEmail); 83 | 84 | if (empty($mailbox)) { 85 | if (false === $input->getOption('no-interaction')) { 86 | $output->writeln(" Error: Mailbox for email $mailboxEmail not found."); 87 | } 88 | 89 | continue; 90 | } else if (false == $mailbox->getIsEnabled()) { 91 | if (false === $input->getOption('no-interaction')) { 92 | $output->writeln(" Error: Mailbox for email $mailboxEmail is not enabled."); 93 | } 94 | 95 | continue; 96 | } else { 97 | $imapConfiguration = $mailbox->getImapConfiguration(); 98 | 99 | if (empty($imapConfiguration)) { 100 | if (false === $input->getOption('no-interaction')) { 101 | $output->writeln(" Error: No imap configurations defined for email $mailboxEmail."); 102 | } 103 | 104 | continue; 105 | } 106 | } 107 | 108 | try { 109 | if ($imapConfiguration instanceof IMAP\Transport\SimpleTransportConfigurationInterface) { 110 | $output->writeln(" Cannot fetch emails from mailboxes with simple transport configurations."); 111 | } else if ($imapConfiguration instanceof IMAP\Transport\AppTransportConfigurationInterface) { 112 | $microsoftApp = $this->entityManager->getRepository(MicrosoftApp::class)->findOneByClientId($imapConfiguration->getClient()); 113 | 114 | if (empty($microsoftApp)) { 115 | $output->writeln(" No microsoft app was found for configured client id '" . $imapConfiguration->getClient() . "'."); 116 | 117 | continue; 118 | } else { 119 | $microsoftAccount = $this->entityManager->getRepository(MicrosoftAccount::class)->findOneBy([ 120 | 'email' => $imapConfiguration->getUsername(), 121 | 'microsoftApp' => $microsoftApp, 122 | ]); 123 | 124 | if (empty($microsoftAccount)) { 125 | $output->writeln(" No microsoft account was found with email '" . $imapConfiguration->getUsername() . "' for configured client id '" . $imapConfiguration->getClient() . "'."); 126 | 127 | continue; 128 | } 129 | } 130 | 131 | $this->refreshOutlookMailbox($microsoftApp, $microsoftAccount, $timestamp, $output); 132 | } else { 133 | $this->refreshMailbox($imapConfiguration->getHost(), $imapConfiguration->getUsername(), urldecode($imapConfiguration->getPassword()), $timestamp, $output); 134 | } 135 | } catch (\Exception $e) { 136 | $output->writeln(" An unexpected error occurred: " . $e->getMessage() . ""); 137 | } 138 | } 139 | $output->writeln(""); 140 | 141 | return Command::SUCCESS; 142 | } 143 | 144 | public function refreshMailbox($server_host, $server_username, $server_password, \DateTime $timestamp, OutputInterface $output) 145 | { 146 | $output->writeln(" - Establishing connection with mailbox"); 147 | 148 | try { 149 | $imap = imap_open($server_host, $server_username, $server_password); 150 | } catch (\Exception $e) { 151 | $output->writeln(" - Failed to establish connection with mailbox"); 152 | $output->writeln("\n " . $e->getMessage() . "\n"); 153 | 154 | $errorMessages = imap_errors(); 155 | 156 | foreach ($errorMessages as $id => $errorMessage) { 157 | $output->writeln(" $id: $errorMessage"); 158 | } 159 | 160 | return; 161 | } 162 | 163 | if ($imap) { 164 | $timeSpan = $timestamp->format('d F Y'); 165 | $output->writeln(" - Fetching all emails since $timeSpan"); 166 | 167 | $emailCollection = imap_search($imap, 'SINCE "' . $timestamp->format('d F Y') . '"'); 168 | 169 | if (is_array($emailCollection)) { 170 | $emailCount = count($emailCollection); 171 | 172 | $output->writeln(" - Found a total of $emailCount emails in mailbox since $timeSpan"); 173 | $output->writeln("\n # Processing all found emails iteratively:"); 174 | $output->writeln("\n API " . $this->endpoint . "\n"); 175 | 176 | $counter = 1; 177 | try { 178 | foreach ($emailCollection as $id => $messageNumber) { 179 | $output->writeln(" - Processing email $counter of $emailCount:"); 180 | 181 | $message = imap_fetchbody($imap, $messageNumber, ""); 182 | 183 | list($response, $responseCode) = $this->parseInboundEmail($message, $output); 184 | 185 | if ($response['message'] && !isset($response['error'])) { 186 | $output->writeln("\n 200 " . $response['message'] . "\n"); 187 | } 188 | 189 | if (isset($response['error'])) { 190 | $output->writeln("\n ERROR ". $response['message'] ."\n"); 191 | } 192 | 193 | $counter++; 194 | } 195 | 196 | $output->writeln(" - Mailbox refreshed successfully!"); 197 | } catch (\Exception $e) { 198 | $msg = $e->getMessage(); 199 | $output->writeln(" - $msg"); 200 | } 201 | } 202 | } 203 | 204 | return; 205 | } 206 | 207 | public function refreshOutlookMailbox($microsoftApp, $microsoftAccount, \DateTime $timestamp, OutputInterface $output) 208 | { 209 | $timeSpan = $timestamp->format('Y-m-d'); 210 | $credentials = json_decode($microsoftAccount->getCredentials(), true); 211 | $redirectEndpoint = str_replace('http', 'https', $this->router->generate('uvdesk_member_core_framework_integrations_microsoft_apps_oauth_login', [], UrlGeneratorInterface::ABSOLUTE_URL)); 212 | 213 | $filters = [ 214 | 'ReceivedDateTime' => [ 215 | 'operation' => '>', 216 | 'value' => $timeSpan, 217 | ], 218 | ]; 219 | 220 | $mailboxFolderId = null; 221 | $mailboxFolderCollection = $this->getOutlookMailboxFolders($credentials['access_token'], $credentials['refresh_token'], $microsoftApp, $microsoftAccount, $output); 222 | 223 | foreach ($mailboxFolderCollection as $mailboxFolder) { 224 | if ($mailboxFolder['displayName'] == 'Inbox') { 225 | $mailboxFolderId = $mailboxFolder['id']; 226 | break; 227 | } 228 | } 229 | 230 | $nextLink = null; 231 | $counter = 1; 232 | 233 | do { 234 | $response = $nextLink ? MicrosoftGraph\Me::getMessagesWithNextLink($nextLink, $credentials['access_token']) : MicrosoftGraph\Me::messages($credentials['access_token'], $mailboxFolderId, $filters); 235 | 236 | if (! empty($response['error'])) { 237 | if ( 238 | ! empty($response['error']['code']) 239 | && $response['error']['code'] == 'InvalidAuthenticationToken' 240 | ) { 241 | $tokenResponse = $this->microsoftIntegration->refreshAccessToken($microsoftApp, $credentials['refresh_token']); 242 | 243 | if (! empty($tokenResponse['access_token'])) { 244 | $microsoftAccount->setCredentials(json_encode($tokenResponse)); 245 | $this->entityManager->persist($microsoftAccount); 246 | $this->entityManager->flush(); 247 | 248 | $credentials['access_token'] = $tokenResponse['access_token']; 249 | $response = $nextLink ? MicrosoftGraph\Me::getMessagesWithNextLink($nextLink, $credentials['access_token']) : MicrosoftGraph\Me::messages($credentials['access_token'], $mailboxFolderId, $filters); 250 | } else { 251 | $output->writeln("\n ERROR Failed to retrieve a valid access token.\n"); 252 | 253 | return; 254 | } 255 | } else { 256 | $errorCode = $response['error']['code'] ?? 'Unknown'; 257 | $output->writeln("\n ERROR An unexpected api error occurred of type '" . $errorCode . "'.\n"); 258 | 259 | return; 260 | } 261 | } 262 | 263 | if ($counter === 1) { 264 | $emailCount = $response['@odata.count'] ?? 'NA'; 265 | $output->writeln(" - Found a total of $emailCount emails in mailbox since $timeSpan"); 266 | } 267 | 268 | if (! empty($response['value'])) { 269 | $output->writeln("\n # Processing all found emails iteratively:"); 270 | $output->writeln("\n API " . $this->outlookEndpoint . "\n"); 271 | 272 | foreach ($response['value'] as $message) { 273 | $output->writeln(" - Processing email $counter of $emailCount:"); 274 | 275 | $detailedMessage = MicrosoftGraph\Me::message($message['id'], $credentials['access_token']); 276 | 277 | $attachments = $detailedMessage['attachments']; 278 | $outlookAttachments = ['outlookAttachments' => []]; 279 | 280 | foreach ($attachments as $attachment) { 281 | if (isset($attachment['contentBytes'])) { 282 | $tempFilePath = sys_get_temp_dir(); 283 | 284 | if (! is_dir($tempFilePath)) { 285 | mkdir($tempFilePath, 0755, true); 286 | } 287 | 288 | $filePath = $tempFilePath . '/' . $attachment['name']; 289 | 290 | if (file_exists($filePath)) { 291 | $mimeType = mime_content_type($filePath); 292 | } else { 293 | $mimeType = 'application/octet-stream'; 294 | } 295 | 296 | $outlookAttachments['outlookAttachments'][] = [ 297 | 'content' => $attachment['contentBytes'], 298 | 'mimeType' => $mimeType, 299 | 'name' => $attachment['name'], 300 | ]; 301 | } 302 | } 303 | 304 | $detailedMessage = array_merge($detailedMessage, $outlookAttachments); 305 | 306 | if (isset($detailedMessage['body']['content'])) { 307 | $detailedMessage['body']['content'] = preg_replace('/]+>/', '', $detailedMessage['body']['content']); 308 | $detailedMessage['body']['content'] = preg_replace('/<\/?head[^>]*>/', '', $detailedMessage['body']['content']); 309 | $detailedMessage['body']['content'] = preg_replace('/<\/?body[^>]*>/', '', $detailedMessage['body']['content']); 310 | } 311 | 312 | unset($detailedMessage['attachments']); 313 | 314 | list($response, $responseCode) = $this->parseOutlookInboundEmail($detailedMessage, $output); 315 | 316 | if ( 317 | $response['message'] 318 | && !isset($response['error']) 319 | ) { 320 | $output->writeln("\n 200 " . $response['message'] . "\n"); 321 | } 322 | 323 | if (isset($response['error'])) { 324 | $output->writeln("\n ERROR ". $response['message'] ."\n"); 325 | } 326 | 327 | $counter++; 328 | } 329 | } 330 | 331 | $nextLink = $response['@odata.nextLink'] ?? null; 332 | 333 | } while ($nextLink); 334 | 335 | $output->writeln(" - Mailbox refreshed successfully!"); 336 | } 337 | 338 | private function getOutlookMailboxFolders($accessToken, $refreshToken, $microsoftApp, $microsoftAccount, OutputInterface $output) 339 | { 340 | $response = MicrosoftGraph\Me::mailFolders($accessToken); 341 | 342 | if (! empty($response['error'])) { 343 | if ( 344 | ! empty($response['error']['code']) 345 | && $response['error']['code'] == 'InvalidAuthenticationToken' 346 | ) { 347 | $tokenResponse = $this->microsoftIntegration->refreshAccessToken($microsoftApp, $refreshToken); 348 | 349 | if (! empty($tokenResponse['access_token'])) { 350 | $microsoftAccount->setCredentials(json_encode($tokenResponse)); 351 | 352 | $this->entityManager->persist($microsoftAccount); 353 | $this->entityManager->flush(); 354 | 355 | $response = MicrosoftGraph\Me::mailFolders($tokenResponse['access_token']); 356 | 357 | } else { 358 | $output->writeln("\n ERROR Failed to retrieve a valid access token.\n"); 359 | 360 | return []; 361 | } 362 | } else { 363 | if (! empty($response['error']['code'])) { 364 | $output->writeln("\n ERROR An unexpected api error occurred of type '" . $response['error']['code'] . "'.\n"); 365 | } else { 366 | $output->writeln("\n ERROR An unexpected api error occurred.\n"); 367 | } 368 | 369 | return []; 370 | } 371 | } 372 | 373 | return !empty($response['value']) ? $response['value'] : []; 374 | } 375 | 376 | public function parseInboundEmail($message, $output) 377 | { 378 | $processedThread = $this->mailboxService->processMail($message); 379 | $responseMessage = $processedThread['message']; 380 | 381 | if ( 382 | isset($processedThread['content']['from']) 383 | && !empty($processedThread['content']['from']) 384 | ) { 385 | $responseMessage = "Received email from " . $processedThread['content']['from']. ". " . $responseMessage; 386 | } 387 | 388 | if ( 389 | (isset($processedThread['content']['ticket']) 390 | && !empty($processedThread['content']['ticket'])) 391 | && (isset($processedThread['content']['thread']) 392 | && !empty($processedThread['content']['thread'])) 393 | ) { 394 | $responseMessage .= " [tickets/" . $processedThread['content']['ticket'] . "/#" . $processedThread['content']['ticket'] . "]"; 395 | } else if ( 396 | isset($processedThread['content']['ticket']) 397 | && !empty($processedThread['content']['ticket']) 398 | ) { 399 | $responseMessage .= " [tickets/" . $processedThread['content']['ticket'] . "]"; 400 | } 401 | 402 | return [$processedThread, $responseMessage]; 403 | } 404 | 405 | protected function isSecureConnectionAvailable() 406 | { 407 | $headers = [CURLOPT_NOBODY => true, CURLOPT_HEADER => false]; 408 | $curlHandler = curl_init('https://' . $this->container->getParameter('uvdesk.site_url')); 409 | 410 | curl_setopt_array($curlHandler, $headers); 411 | curl_exec($curlHandler); 412 | 413 | $isSecureRequestAvailable = curl_errno($curlHandler) === 0 ? true : false; 414 | curl_close($curlHandler); 415 | 416 | return $isSecureRequestAvailable; 417 | } 418 | 419 | public function parseOutlookInboundEmail($detailedMessage, $output) 420 | { 421 | $processedThread = $this->mailboxService->processOutlookMail($detailedMessage); 422 | $responseMessage = $processedThread['message']; 423 | 424 | if ( 425 | isset($processedThread['content']['from']) 426 | && !empty($processedThread['content']['from']) 427 | ) { 428 | $responseMessage = "Received email from " . $processedThread['content']['from']. ". " . $responseMessage; 429 | } 430 | 431 | if ( 432 | (isset($processedThread['content']['ticket']) 433 | && !empty($processedThread['content']['ticket'])) 434 | && (isset($processedThread['content']['thread']) 435 | && !empty($processedThread['content']['thread'])) 436 | ) { 437 | $responseMessage .= " [tickets/" . $processedThread['content']['ticket'] . "/#" . $processedThread['content']['ticket'] . "]"; 438 | } else if ( 439 | isset($processedThread['content']['ticket']) 440 | && !empty($processedThread['content']['ticket']) 441 | ) { 442 | $responseMessage .= " [tickets/" . $processedThread['content']['ticket'] . "]"; 443 | } 444 | 445 | return [$processedThread, $responseMessage]; 446 | } 447 | } -------------------------------------------------------------------------------- /Controller/MailboxChannel.php: -------------------------------------------------------------------------------- 1 | isAccessAuthorized('ROLE_ADMIN')) { 26 | return $this->redirect($this->generateUrl('helpdesk_member_dashboard')); 27 | } 28 | 29 | return $this->render('@UVDeskMailbox//listConfigurations.html.twig'); 30 | } 31 | 32 | public function createMailboxConfiguration(Request $request, EntityManagerInterface $entityManager, UserService $userService, MailboxService $mailboxService, TranslatorInterface $translator, SwiftMailerService $swiftMailer) 33 | { 34 | if (! $userService->isAccessAuthorized('ROLE_ADMIN')) { 35 | return $this->redirect($this->generateUrl('helpdesk_member_dashboard')); 36 | } 37 | 38 | $microsoftAppCollection = $entityManager->getRepository(MicrosoftApp::class)->findBy(['isEnabled' => true, 'isVerified' => true]); 39 | $microsoftAccountCollection = $entityManager->getRepository(MicrosoftAccount::class)->findAll(); 40 | 41 | $microsoftAppCollection = array_map(function ($microsoftApp) { 42 | return [ 43 | 'id' => $microsoftApp->getId(), 44 | 'name' => $microsoftApp->getName(), 45 | ]; 46 | }, $microsoftAppCollection); 47 | 48 | $microsoftAccountCollection = array_map(function ($microsoftAccount) { 49 | return [ 50 | 'id' => $microsoftAccount->getId(), 51 | 'name' => $microsoftAccount->getName(), 52 | 'email' => $microsoftAccount->getEmail(), 53 | ]; 54 | }, $microsoftAccountCollection); 55 | 56 | # load swift mailer configuration 57 | $swiftMailerConfigurationCollection = $swiftMailer->parseSwiftMailerConfigurations(); 58 | 59 | if ($request->getMethod() == 'POST') { 60 | $params = $request->request->all(); 61 | 62 | $smtpConfiguration = null; 63 | $imapConfiguration = null; 64 | 65 | // IMAP Configuration 66 | if (! empty($params['imap']['transport'])) { 67 | $imapConfiguration = IMAP\Configuration::createTransportDefinition($params['imap']['transport'], !empty($params['imap']['host']) ? trim($params['imap']['host'], '"') : null); 68 | 69 | if ($imapConfiguration instanceof IMAP\Transport\AppTransportConfigurationInterface) { 70 | if ($params['imap']['transport'] == 'outlook_oauth') { 71 | $microsoftAccount = $entityManager->getRepository(MicrosoftAccount::class)->findOneById($params['imap']['username']); 72 | 73 | if (empty($microsoftAccount)) { 74 | $this->addFlash('warning', 'No configuration details were found for the provided microsoft account.'); 75 | 76 | return $this->render('@UVDeskMailbox//manageConfigurations.html.twig', [ 77 | 'microsoftAppCollection' => $microsoftAppCollection, 78 | 'microsoftAccountCollection' => $microsoftAccountCollection, 79 | ]); 80 | } 81 | 82 | $params['imap']['username'] = $microsoftAccount->getEmail(); 83 | $params['imap']['client'] = $microsoftAccount->getMicrosoftApp()->getClientId(); 84 | 85 | $imapConfiguration 86 | ->setClient($params['imap']['client']) 87 | ->setUsername($params['imap']['username']) 88 | ; 89 | } else { 90 | $this->addFlash('warning', 'The resolved IMAP configuration is not configured for any valid available app.'); 91 | 92 | return $this->render('@UVDeskMailbox//manageConfigurations.html.twig', [ 93 | 'microsoftAppCollection' => $microsoftAppCollection, 94 | 'microsoftAccountCollection' => $microsoftAccountCollection, 95 | ]); 96 | } 97 | } else if ($imapConfiguration instanceof IMAP\Transport\SimpleTransportConfigurationInterface) { 98 | $imapConfiguration 99 | ->setUsername($params['imap']['username']) 100 | ; 101 | } else { 102 | $imapConfiguration 103 | ->setUsername($params['imap']['username']) 104 | ->setPassword(urlencode($params['imap']['password'])) 105 | ; 106 | } 107 | } 108 | 109 | // SMTP Configuration 110 | if ( 111 | ! empty($params['smtp']['transport']) 112 | && 'swiftmailer_id' !== $params['smtp']['transport'] 113 | ) { 114 | $smtpConfiguration = SMTP\Configuration::createTransportDefinition($params['smtp']['transport'], !empty($params['smtp']['host']) ? trim($params['smtp']['host'], '"') : null); 115 | 116 | if ($smtpConfiguration instanceof SMTP\Transport\AppTransportConfigurationInterface) { 117 | if ($params['smtp']['transport'] == 'outlook_oauth') { 118 | $microsoftAccount = $entityManager->getRepository(MicrosoftAccount::class)->findOneById($params['smtp']['username']); 119 | 120 | if (empty($microsoftAccount)) { 121 | $this->addFlash('warning', 'No configuration details were found for the provided microsoft account.'); 122 | 123 | return $this->render('@UVDeskMailbox//manageConfigurations.html.twig', [ 124 | 'microsoftAppCollection' => $microsoftAppCollection, 125 | 'microsoftAccountCollection' => $microsoftAccountCollection, 126 | 'swiftmailerConfigurations' => $swiftMailerConfigurationCollection, 127 | ]); 128 | } 129 | 130 | $params['smtp']['username'] = $microsoftAccount->getEmail(); 131 | $params['smtp']['client'] = $microsoftAccount->getMicrosoftApp()->getClientId(); 132 | 133 | $smtpConfiguration 134 | ->setClient($params['smtp']['client']) 135 | ->setUsername($params['smtp']['username']) 136 | ; 137 | } else { 138 | $this->addFlash('warning', 'The resolved SMTP configuration is not configured for any valid available app.'); 139 | 140 | return $this->render('@UVDeskMailbox//manageConfigurations.html.twig', [ 141 | 'microsoftAppCollection' => $microsoftAppCollection, 142 | 'microsoftAccountCollection' => $microsoftAccountCollection, 143 | 'swiftmailerConfigurations' => $swiftMailerConfigurationCollection, 144 | ]); 145 | } 146 | } else if ($smtpConfiguration instanceof SMTP\Transport\ResolvedTransportConfigurationInterface) { 147 | $smtpConfiguration 148 | ->setUsername($params['smtp']['username']) 149 | ->setPassword(urlencode($params['smtp']['password'])) 150 | ; 151 | } else { 152 | $smtpConfiguration 153 | ->setHost($params['smtp']['host']) 154 | ->setPort((int) $params['smtp']['port']) 155 | ->setUsername($params['smtp']['username']) 156 | ->setPassword(urlencode($params['smtp']['password'])) 157 | ->setSenderAddress(!empty($params['smtp']['senderAddress']) ? $params['smtp']['senderAddress'] : null) 158 | ; 159 | } 160 | } 161 | 162 | if ( 163 | empty($imapConfiguration) 164 | && empty($smtpConfiguration) 165 | ) { 166 | $this->addFlash('warning', 'Invalid mailbox details provided. Mailbox needs to have at least IMAP or SMTP settings defined.'); 167 | } else { 168 | $mailboxConfiguration = $mailboxService->parseMailboxConfigurations(); 169 | 170 | // SwiftMailer Configuration 171 | if (! empty($params['swiftmailer_id'])) { 172 | foreach ($swiftMailerConfigurationCollection as $configuration) { 173 | if ($configuration->getId() == $params['swiftmailer_id']) { 174 | $swiftmailerConfiguration = $configuration; 175 | break; 176 | } 177 | } 178 | } 179 | 180 | $mailbox = new Mailbox(!empty($params['id']) ? $params['id'] : null); 181 | $mailbox 182 | ->setName($params['name']) 183 | ->setIsEnabled(!empty($params['isEnabled']) && 'on' == $params['isEnabled'] ? true : false) 184 | ->setIsEmailDeliveryDisabled(!empty($params['isEmailDeliveryDisabled']) && 'on' == $params['isEmailDeliveryDisabled'] ? true : false) 185 | ; 186 | 187 | if (! empty($imapConfiguration)) { 188 | $mailbox 189 | ->setImapConfiguration($imapConfiguration) 190 | ; 191 | } 192 | 193 | if (! empty($smtpConfiguration)) { 194 | $mailbox 195 | ->setSmtpConfiguration($smtpConfiguration) 196 | ; 197 | } 198 | 199 | if (! empty($swiftmailerConfiguration)) { 200 | $mailbox 201 | ->setSwiftMailerConfiguration($swiftmailerConfiguration); 202 | ; 203 | } 204 | 205 | $mailboxConfiguration->addMailbox($mailbox); 206 | 207 | if (! empty($params['isDefault']) && 'on' == $params['isDefault']) { 208 | $mailboxConfiguration 209 | ->setDefaultMailbox($mailbox) 210 | ; 211 | } 212 | 213 | file_put_contents($mailboxService->getPathToConfigurationFile(), (string) $mailboxConfiguration); 214 | 215 | $this->addFlash('success', $translator->trans('Mailbox successfully created.')); 216 | 217 | return new RedirectResponse($this->generateUrl('helpdesk_member_mailbox_settings')); 218 | } 219 | } 220 | 221 | return $this->render('@UVDeskMailbox//manageConfigurations.html.twig', [ 222 | 'microsoftAppCollection' => $microsoftAppCollection, 223 | 'microsoftAccountCollection' => $microsoftAccountCollection, 224 | 'swiftmailerConfigurations' => $swiftMailerConfigurationCollection, 225 | ]); 226 | } 227 | 228 | public function updateMailboxConfiguration($id, Request $request, EntityManagerInterface $entityManager, UserService $userService, MailboxService $mailboxService, TranslatorInterface $translator, SwiftMailerService $swiftMailer) 229 | { 230 | if (! $userService->isAccessAuthorized('ROLE_ADMIN')) { 231 | return $this->redirect($this->generateUrl('helpdesk_member_dashboard')); 232 | } 233 | 234 | $mailboxConfiguration = $mailboxService->parseMailboxConfigurations(); 235 | 236 | $mailbox = $mailboxConfiguration->getMailboxById($id); 237 | 238 | if (empty($mailbox)) { 239 | return new Response('', 404); 240 | } 241 | 242 | $microsoftAppCollection = $entityManager->getRepository(MicrosoftApp::class)->findBy(['isEnabled' => true, 'isVerified' => true]); 243 | $microsoftAccountCollection = $entityManager->getRepository(MicrosoftAccount::class)->findAll(); 244 | 245 | $microsoftAppCollection = array_map(function ($microsoftApp) { 246 | return [ 247 | 'id' => $microsoftApp->getId(), 248 | 'name' => $microsoftApp->getName(), 249 | ]; 250 | }, $microsoftAppCollection); 251 | 252 | $microsoftAccountCollection = array_map(function ($microsoftAccount) { 253 | return [ 254 | 'id' => $microsoftAccount->getId(), 255 | 'name' => $microsoftAccount->getName(), 256 | 'email' => $microsoftAccount->getEmail(), 257 | ]; 258 | }, $microsoftAccountCollection); 259 | 260 | # load swift mailer configuration 261 | $swiftMailerConfigurationCollection = $swiftMailer->parseSwiftMailerConfigurations(); 262 | 263 | if ($request->getMethod() == 'POST') { 264 | $params = $request->request->all(); 265 | 266 | $smtpConfiguration = null; 267 | $imapConfiguration = null; 268 | 269 | // IMAP Configuration 270 | if (!empty($params['imap']['transport'])) { 271 | $imapConfiguration = IMAP\Configuration::createTransportDefinition($params['imap']['transport'], !empty($params['imap']['host']) ? trim($params['imap']['host'], '"') : null); 272 | 273 | if ($imapConfiguration instanceof IMAP\Transport\AppTransportConfigurationInterface) { 274 | if ($params['imap']['transport'] == 'outlook_oauth') { 275 | $microsoftAccount = $entityManager->getRepository(MicrosoftAccount::class)->findOneById($params['imap']['username']); 276 | 277 | if (empty($microsoftAccount)) { 278 | $this->addFlash('warning', 'No configuration details were found for the provided microsoft account.'); 279 | 280 | return $this->render('@UVDeskMailbox//manageConfigurations.html.twig', [ 281 | 'microsoftAppCollection' => $microsoftAppCollection, 282 | 'microsoftAccountCollection' => $microsoftAccountCollection, 283 | 'swiftmailerConfigurations' => $swiftMailerConfigurationCollection, 284 | ]); 285 | } 286 | 287 | $params['imap']['username'] = $microsoftAccount->getEmail(); 288 | $params['imap']['client'] = $microsoftAccount->getMicrosoftApp()->getClientId(); 289 | 290 | $imapConfiguration 291 | ->setClient($params['imap']['client']) 292 | ->setUsername($params['imap']['username']) 293 | ; 294 | } else { 295 | $this->addFlash('warning', 'The resolved IMAP configuration is not configured for any valid available app.'); 296 | 297 | return $this->render('@UVDeskMailbox//manageConfigurations.html.twig', [ 298 | 'microsoftAppCollection' => $microsoftAppCollection, 299 | 'microsoftAccountCollection' => $microsoftAccountCollection, 300 | 'swiftmailerConfigurations' => $swiftMailerConfigurationCollection, 301 | ]); 302 | } 303 | } else if ($imapConfiguration instanceof IMAP\Transport\SimpleTransportConfigurationInterface) { 304 | $imapConfiguration 305 | ->setUsername($params['imap']['username']) 306 | ; 307 | } else { 308 | $imapConfiguration 309 | ->setUsername($params['imap']['username']) 310 | ->setPassword(urlencode($params['imap']['password'])) 311 | ; 312 | } 313 | } 314 | 315 | // SMTP Configuration 316 | if ( 317 | ! empty($params['smtp']['transport']) 318 | && 'swiftmailer_id' !== $params['smtp']['transport'] 319 | ) { 320 | $smtpConfiguration = SMTP\Configuration::createTransportDefinition($params['smtp']['transport'], !empty($params['smtp']['host']) ? trim($params['smtp']['host'], '"') : null); 321 | 322 | if ($smtpConfiguration instanceof SMTP\Transport\AppTransportConfigurationInterface) { 323 | if ($params['smtp']['transport'] == 'outlook_oauth') { 324 | $microsoftAccount = $entityManager->getRepository(MicrosoftAccount::class)->findOneById($params['smtp']['username']); 325 | 326 | if (empty($microsoftAccount)) { 327 | $this->addFlash('warning', 'No configuration details were found for the provided microsoft account.'); 328 | 329 | return $this->render('@UVDeskMailbox//manageConfigurations.html.twig', [ 330 | 'microsoftAppCollection' => $microsoftAppCollection, 331 | 'microsoftAccountCollection' => $microsoftAccountCollection, 332 | 'swiftmailerConfigurations' => $swiftMailerConfigurationCollection, 333 | ]); 334 | } 335 | 336 | $params['smtp']['username'] = $microsoftAccount->getEmail(); 337 | $params['smtp']['client'] = $microsoftAccount->getMicrosoftApp()->getClientId(); 338 | 339 | $smtpConfiguration 340 | ->setClient($params['smtp']['client']) 341 | ->setUsername($params['smtp']['username']) 342 | ; 343 | } else { 344 | $this->addFlash('warning', 'The resolved SMTP configuration is not configured for any valid available app.'); 345 | 346 | return $this->render('@UVDeskMailbox//manageConfigurations.html.twig', [ 347 | 'microsoftAppCollection' => $microsoftAppCollection, 348 | 'microsoftAccountCollection' => $microsoftAccountCollection, 349 | 'swiftmailerConfigurations' => $swiftMailerConfigurationCollection, 350 | ]); 351 | } 352 | } else if ($smtpConfiguration instanceof SMTP\Transport\ResolvedTransportConfigurationInterface) { 353 | $smtpConfiguration 354 | ->setUsername($params['smtp']['username']) 355 | ->setPassword(urlencode($params['smtp']['password'])) 356 | ; 357 | } else { 358 | $smtpConfiguration 359 | ->setHost($params['smtp']['host']) 360 | ->setPort((int) $params['smtp']['port']) 361 | ->setUsername($params['smtp']['username']) 362 | ->setPassword(urlencode($params['smtp']['password'])) 363 | ->setSenderAddress(!empty($params['smtp']['senderAddress']) ? $params['smtp']['senderAddress'] : null) 364 | ; 365 | } 366 | } 367 | 368 | if (empty($imapConfiguration) && empty($smtpConfiguration)) { 369 | $this->addFlash('warning', 'Invalid mailbox details provided. Mailbox needs to have at least IMAP or SMTP settings defined.'); 370 | } else { 371 | $mailboxConfiguration->removeMailbox($mailbox); 372 | 373 | $mailbox = new Mailbox($params['id']); 374 | 375 | // SwiftMailer Configuration 376 | if (! empty($params['swiftmailer_id'])) { 377 | foreach ($swiftMailerConfigurationCollection as $configuration) { 378 | if ($configuration->getId() == $params['swiftmailer_id']) { 379 | $swiftmailerConfiguration = $configuration; 380 | break; 381 | } 382 | } 383 | } 384 | 385 | $mailbox 386 | ->setName($params['name']) 387 | ->setIsEnabled(!empty($params['isEnabled']) && 'on' == $params['isEnabled'] ? true : false); 388 | 389 | if (! empty($imapConfiguration)) { 390 | $mailbox 391 | ->setImapConfiguration($imapConfiguration) 392 | ; 393 | } 394 | 395 | if (! empty($smtpConfiguration)) { 396 | $mailbox 397 | ->setSmtpConfiguration($smtpConfiguration) 398 | ; 399 | } 400 | 401 | if (! empty($swiftmailerConfiguration) && empty($smtpConfiguration)) { 402 | $mailbox 403 | ->setSwiftMailerConfiguration($swiftmailerConfiguration); 404 | ; 405 | } 406 | 407 | $mailboxConfiguration->addMailbox($mailbox); 408 | 409 | if (! empty($params['isDefault']) && 'on' == $params['isDefault']) { 410 | $mailboxConfiguration 411 | ->setDefaultMailbox($mailbox) 412 | ; 413 | } 414 | 415 | file_put_contents($mailboxService->getPathToConfigurationFile(), (string) $mailboxConfiguration); 416 | 417 | $this->addFlash('success', $translator->trans('Mailbox successfully updated.')); 418 | 419 | return new RedirectResponse($this->generateUrl('helpdesk_member_mailbox_settings')); 420 | } 421 | } 422 | 423 | return $this->render('@UVDeskMailbox//manageConfigurations.html.twig', [ 424 | 'mailbox' => $mailbox, 425 | 'microsoftAppCollection' => $microsoftAppCollection, 426 | 'microsoftAccountCollection' => $microsoftAccountCollection, 427 | 'swiftmailerConfigurations' => $swiftMailerConfigurationCollection, 428 | ]); 429 | } 430 | } -------------------------------------------------------------------------------- /Controller/MailboxChannelXHR.php: -------------------------------------------------------------------------------- 1 | mailboxService = $mailboxService; 23 | $this->translator = $translator; 24 | $this->kernel = $kernel; 25 | } 26 | 27 | public function processRawContentMail(Request $request) 28 | { 29 | $rawEmail = file_get_contents($this->kernel->getProjectDir(). "/rawEmailContent.txt"); 30 | 31 | if ($rawEmail != false && !empty($rawEmail)) { 32 | $this->mailboxService->processMail($rawEmail); 33 | } else { 34 | dump("Empty Text file not allow"); 35 | } 36 | 37 | exit(0); 38 | } 39 | 40 | public function loadMailboxesXHR(Request $request) 41 | { 42 | $mailboxConfiguration = $this->mailboxService->parseMailboxConfigurations(); 43 | 44 | $defaultMailbox = $mailboxConfiguration->getDefaultMailbox(); 45 | 46 | $collection = array_map(function ($mailbox) use ($defaultMailbox) { 47 | return [ 48 | 'id' => $mailbox->getId(), 49 | 'name' => $mailbox->getName(), 50 | 'isEnabled' => $mailbox->getIsEnabled(), 51 | ]; 52 | }, array_values($mailboxConfiguration->getMailboxes())); 53 | 54 | return new JsonResponse($collection ?? []); 55 | } 56 | 57 | public function removeMailboxConfiguration($id, Request $request) 58 | { 59 | $mailboxService = $this->mailboxService; 60 | $existingMailboxConfiguration = $mailboxService->parseMailboxConfigurations(); 61 | 62 | foreach ($existingMailboxConfiguration->getMailboxes() as $configuration) { 63 | if ($configuration->getId() == $id) { 64 | $mailbox = $configuration; 65 | 66 | break; 67 | } 68 | } 69 | 70 | if (empty($mailbox)) { 71 | return new JsonResponse([ 72 | 'alertClass' => 'danger', 73 | 'alertMessage' => "No mailbox found with id '$id'.", 74 | ], 404); 75 | } 76 | 77 | $mailboxConfiguration = new MailboxConfiguration(); 78 | 79 | foreach ($existingMailboxConfiguration->getMailboxes() as $configuration) { 80 | if ($configuration->getId() == $id) { 81 | continue; 82 | } 83 | 84 | $mailboxConfiguration->addMailbox($configuration); 85 | } 86 | 87 | file_put_contents($mailboxService->getPathToConfigurationFile(), (string) $mailboxConfiguration); 88 | 89 | return new JsonResponse([ 90 | 'alertClass' => 'success', 91 | 'alertMessage' => $this->translator->trans('Mailbox configuration removed successfully.'), 92 | ]); 93 | } 94 | 95 | public function processMailXHR(Request $request, MailboxService $mailboxService) 96 | { 97 | if ("POST" != $request->getMethod()) { 98 | return new JsonResponse([ 99 | 'success' => false, 100 | 'message' => 'Request not supported.' 101 | ], 500); 102 | } else if (null == $request->get('email')) { 103 | return new JsonResponse([ 104 | 'success' => false, 105 | 'message' => 'Missing required email data in request content.' 106 | ], 500); 107 | } 108 | 109 | try { 110 | $processedThread = $mailboxService->processMail($request->get('email')); 111 | } catch (\Exception $e) { 112 | return new JsonResponse([ 113 | 'success' => false, 114 | 'message' => $e->getMessage() 115 | ], 500); 116 | } 117 | 118 | $responseMessage = $processedThread['message']; 119 | 120 | if (!empty($processedThread['content']['from'])) { 121 | $responseMessage = "Received email from " . $processedThread['content']['from']. ". " . $responseMessage; 122 | } 123 | 124 | if (!empty($processedThread['content']['ticket']) && !empty($processedThread['content']['thread'])) { 125 | $responseMessage .= " [tickets/" . $processedThread['content']['ticket'] . "/#" . $processedThread['content']['ticket'] . "]"; 126 | } else if (!empty($processedThread['content']['ticket'])) { 127 | $responseMessage .= " [tickets/" . $processedThread['content']['ticket'] . "]"; 128 | } 129 | 130 | return new JsonResponse([ 131 | 'success' => true, 132 | 'message' => $responseMessage, 133 | ]); 134 | } 135 | 136 | public function processOutlookMailXHR(Request $request, MailboxService $mailboxService) 137 | { 138 | if ("POST" != $request->getMethod()) { 139 | return new JsonResponse([ 140 | 'success' => false, 141 | 'message' => 'Request not supported.' 142 | ], 500); 143 | } else if (null == $request->get('email')) { 144 | return new JsonResponse([ 145 | 'success' => false, 146 | 'message' => 'Missing required email data in request content.' 147 | ], 500); 148 | } 149 | 150 | try { 151 | $processedThread = $mailboxService->processOutlookMail($request->get('email')); 152 | } catch (\Exception $e) { 153 | return new JsonResponse([ 154 | 'success' => false, 155 | 'message' => $e->getMessage(), 156 | 'params' => $request->get('email') 157 | ], 500); 158 | } 159 | 160 | $responseMessage = $processedThread['message']; 161 | 162 | if (! empty($processedThread['content']['from'])) { 163 | $responseMessage = "Received email from " . $processedThread['content']['from']. ". " . $responseMessage; 164 | } 165 | 166 | if ( 167 | ! empty($processedThread['content']['ticket']) 168 | && !empty($processedThread['content']['thread']) 169 | ) { 170 | $responseMessage .= " [tickets/" . $processedThread['content']['ticket'] . "/#" . $processedThread['content']['ticket'] . "]"; 171 | } else if (! empty($processedThread['content']['ticket'])) { 172 | $responseMessage .= " [tickets/" . $processedThread['content']['ticket'] . "]"; 173 | } 174 | 175 | return new JsonResponse([ 176 | 'success' => true, 177 | 'message' => $responseMessage, 178 | ]); 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /DependencyInjection/Configuration.php: -------------------------------------------------------------------------------- 1 | getRootNode('uvdesk_mailbox') 14 | ->children() 15 | ->node('emails', 'array') 16 | ->children() 17 | ->node('delimiter', 'scalar')->defaultValue('<-- Please add content above this line -->')->end() 18 | ->node('enable_delimiter', 'boolean')->defaultValue(false)->end() 19 | ->end() 20 | ->end() 21 | ->node('default_mailbox', 'scalar')->defaultValue(null)->end() 22 | ->node('mailboxes', 'array') 23 | ->arrayPrototype() 24 | ->children() 25 | ->node('name', 'scalar')->cannotBeEmpty()->end() 26 | ->node('enabled', 'boolean')->defaultTrue()->end() 27 | ->node('disable_outbound_emails', 'boolean')->defaultFalse()->end() 28 | ->node('use_strict_mode', 'boolean')->defaultFalse()->end() 29 | ->node('imap_server', 'array') 30 | ->children() 31 | ->node('host', 'scalar')->cannotBeEmpty()->end() 32 | ->node('username', 'scalar')->cannotBeEmpty()->end() 33 | ->node('client', 'scalar')->end() 34 | ->node('password', 'scalar')->end() 35 | ->node('type', 'scalar')->end() 36 | ->end() 37 | ->end() 38 | ->node('smtp_swift_mailer_server', 'array') 39 | ->children() 40 | ->node('mailer_id', 'scalar')->defaultValue(null) 41 | ->end() 42 | ->end() 43 | ->end() 44 | ->node('smtp_server', 'array') 45 | ->children() 46 | ->node('host', 'scalar')->cannotBeEmpty()->end() 47 | ->node('port', 'scalar')->end() 48 | ->node('username', 'scalar')->cannotBeEmpty()->end() 49 | ->node('client', 'scalar')->end() 50 | ->node('password', 'scalar')->end() 51 | ->node('type', 'scalar')->end() 52 | ->node('sender_address', 'scalar')->defaultValue(null) 53 | ->end() 54 | ->end() 55 | ->end() 56 | ->end() 57 | ->end() 58 | ->end() 59 | ->end(); 60 | 61 | return $treeBuilder; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /DependencyInjection/UVDeskExtension.php: -------------------------------------------------------------------------------- 1 | load('services.yaml'); 27 | 28 | // Register automations conditionally if AutomationBundle has been added as an dependency. 29 | if (array_key_exists('UVDeskAutomationBundle', $container->getParameter('kernel.bundles'))) { 30 | $services->load('automations.yaml'); 31 | } 32 | 33 | // Load bundle configurations 34 | $configuration = $this->getConfiguration($configs, $container); 35 | foreach ($this->processConfiguration($configuration, $configs) as $param => $value) { 36 | switch ($param) { 37 | case 'emails': 38 | foreach ($value as $field => $fieldValue) { 39 | $container->setParameter("uvdesk.emails.$field", $fieldValue); 40 | } 41 | break; 42 | case 'mailboxes': 43 | $container->setParameter("uvdesk.mailboxes", array_keys($value)); 44 | 45 | foreach ($value as $mailboxId => $mailboxDetails) { 46 | $mailboxDetails['email'] = $mailboxDetails['imap_server']['username']; 47 | 48 | $container->setParameter("uvdesk.mailboxes.$mailboxId", $mailboxDetails); 49 | } 50 | break; 51 | default: 52 | break; 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /EventListener/Mailer.php: -------------------------------------------------------------------------------- 1 | mailboxService = $mailboxService; 17 | } 18 | 19 | public function onMailerConfigurationUpdated(ConfigurationUpdatedEvent $event) 20 | { 21 | $isUpdateRequiredFlag = false; 22 | $updatedConfiguration = $event->getUpdatedMailerConfiguration(); 23 | $existingConfiguration = $event->getExistingMailerConfiguration(); 24 | 25 | if ($updatedConfiguration->getId() == $existingConfiguration->getId()) { 26 | // We only need to update if the mailer configuration's id has changed 27 | // or if it has been disabled. 28 | 29 | return; 30 | } 31 | 32 | $mailboxConfiguration = $this->mailboxService->parseMailboxConfigurations(true); 33 | 34 | foreach ($mailboxConfiguration->getMailboxes() as $existingMailbox) { 35 | if ($existingMailbox->getMailerConfiguration()->getId() == $existingConfiguration->getId()) { 36 | // Disable mailbox and update configuration 37 | $mailbox = new Mailbox($existingMailbox->getId()); 38 | $mailbox->setName($existingMailbox->getName()) 39 | ->setIsEnabled($existingMailbox->getIsEnabled()) 40 | ->setImapConfiguration($existingMailbox->getImapConfiguration()) 41 | ->setMailerConfiguration($updatedConfiguration); 42 | 43 | $isUpdateRequiredFlag = true; 44 | $mailboxConfiguration->removeMailbox($existingMailbox); 45 | $mailboxConfiguration->addMailbox($mailbox); 46 | } 47 | } 48 | 49 | if (true === $isUpdateRequiredFlag) { 50 | file_put_contents($this->mailboxService->getPathToConfigurationFile(), (string) $mailboxConfiguration); 51 | } 52 | 53 | return; 54 | } 55 | 56 | public function onMailerConfigurationRemoved(ConfigurationRemovedEvent $event) 57 | { 58 | $isUpdateRequiredFlag = false; 59 | $configuration = $event->getMailerConfiguration(); 60 | $mailboxConfiguration = $this->mailboxService->parseMailboxConfigurations(); 61 | 62 | foreach ($mailboxConfiguration->getMailboxes() as $existingMailbox) { 63 | if (null != $existingMailbox->getMailerConfiguration() && $existingMailbox->getMailerConfiguration()->getId() == $configuration->getId()) { 64 | // Disable mailbox and update configuration 65 | $mailbox = new Mailbox($existingMailbox->getId()); 66 | $mailbox->setName($existingMailbox->getName()) 67 | ->setIsEnabled(false) 68 | ->setImapConfiguration($existingMailbox->getImapConfiguration()); 69 | 70 | $isUpdateRequiredFlag = true; 71 | $mailboxConfiguration->removeMailbox($existingMailbox); 72 | $mailboxConfiguration->addMailbox($mailbox); 73 | } 74 | } 75 | 76 | if (true === $isUpdateRequiredFlag) { 77 | file_put_contents($this->mailboxService->getPathToConfigurationFile(), (string) $mailboxConfiguration); 78 | } 79 | 80 | return; 81 | } 82 | } -------------------------------------------------------------------------------- /EventListener/Swiftmailer.php: -------------------------------------------------------------------------------- 1 | container = $container; 23 | $this->requestStack = $requestStack; 24 | $this->swiftMailer = $swiftMailer; 25 | $this->mailboxService = $mailboxService; 26 | } 27 | 28 | public function onSwiftMailerConfigurationUpdated(ConfigurationUpdatedEvent $event) 29 | { 30 | $isUpdateRequiredFlag = false; 31 | $updatedConfiguration = $event->getUpdatedSwiftMailerConfiguration(); 32 | $existingConfiguration = $event->getExistingSwiftMailerConfiguration(); 33 | 34 | if ($updatedConfiguration->getId() == $existingConfiguration->getId()) { 35 | // We only need to update if the swiftmailer configuration's id has changed 36 | // or if it has been disabled. 37 | 38 | return; 39 | } 40 | 41 | $mailboxConfiguration = $this->mailboxService->parseMailboxConfigurations(true); 42 | 43 | foreach ($mailboxConfiguration->getMailboxes() as $existingMailbox) { 44 | if ($existingMailbox->getSwiftmailerConfiguration()->getId() == $existingConfiguration->getId()) { 45 | // Disable mailbox and update configuration 46 | $mailbox = new Mailbox($existingMailbox->getId()); 47 | $mailbox->setName($existingMailbox->getName()) 48 | ->setIsEnabled($existingMailbox->getIsEnabled()) 49 | ->setImapConfiguration($existingMailbox->getImapConfiguration()) 50 | ->setSwiftMailerConfiguration($updatedConfiguration); 51 | 52 | $isUpdateRequiredFlag = true; 53 | $mailboxConfiguration->removeMailbox($existingMailbox); 54 | $mailboxConfiguration->addMailbox($mailbox); 55 | } 56 | } 57 | 58 | if (true === $isUpdateRequiredFlag) { 59 | file_put_contents($this->mailboxService->getPathToConfigurationFile(), (string) $mailboxConfiguration); 60 | } 61 | 62 | return; 63 | } 64 | 65 | public function onSwiftMailerConfigurationRemoved(ConfigurationRemovedEvent $event) 66 | { 67 | $isUpdateRequiredFlag = false; 68 | $configuration = $event->getSwiftMailerConfiguration(); 69 | $mailboxConfiguration = $this->mailboxService->parseMailboxConfigurations(); 70 | 71 | foreach ($mailboxConfiguration->getMailboxes() as $existingMailbox) { 72 | if (null != $existingMailbox->getSwiftmailerConfiguration() && $existingMailbox->getSwiftmailerConfiguration()->getId() == $configuration->getId()) { 73 | // Disable mailbox and update configuration 74 | $mailbox = new Mailbox($existingMailbox->getId()); 75 | $mailbox->setName($existingMailbox->getName()) 76 | ->setIsEnabled(false) 77 | ->setImapConfiguration($existingMailbox->getImapConfiguration()); 78 | 79 | $isUpdateRequiredFlag = true; 80 | $mailboxConfiguration->removeMailbox($existingMailbox); 81 | $mailboxConfiguration->addMailbox($mailbox); 82 | } 83 | } 84 | 85 | if (true === $isUpdateRequiredFlag) { 86 | file_put_contents($this->mailboxService->getPathToConfigurationFile(), (string) $mailboxConfiguration); 87 | } 88 | 89 | return; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Open Software License ("OSL") v. 3.0 2 | 3 | This Open Software License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: 4 | 5 | Licensed under the Open Software License version 3.0 6 | 7 | 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: 8 | 9 | 1. to reproduce the Original Work in copies, either alone or as part of a collective work; 10 | 11 | 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; 12 | 13 | 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, with the proviso that copies of Original Work or Derivative Works that You distribute or communicate shall be licensed under this Open Software License; 14 | 15 | 4. to perform the Original Work publicly; 16 | 17 | 5. to display the Original Work publicly. 18 | 19 | 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. 20 | 21 | 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. 22 | 23 | 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. 24 | 25 | 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). 26 | 27 | 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. 28 | 29 | 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. 30 | 31 | 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. 32 | 33 | 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including 'fair use' or 'fair dealing'). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). 34 | 35 | 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. 36 | 37 | 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. 38 | 39 | 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. 40 | 41 | 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. 42 | 43 | 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. 44 | 45 | 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. 46 | 47 | 16. Modification of This License. This License is Copyright (C) 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

4 | 5 |

6 | Latest Stable Version 7 | Total Downloads 8 | License 9 | connect on gitter 10 |

11 | 12 | The **Mailbox** component enables your [UVDesk Community][1] helpdesk to automatically fetch incoming emails from multiple email sources, such as Gmail, Outlook, and custom email servers. It seamlessly converts these emails into structured support tickets, ensuring that each customer query is organized and easily trackable. This integration eliminates the need for manual email sorting, streamlining your support workflow by automatically categorizing, prioritizing, and routing tickets to the appropriate teams. The Mailbox component enhances operational efficiency by ensuring no email is overlooked and that every query is promptly addressed, providing a smoother experience for both your support team and customers. 13 | 14 | Installation 15 | -------------- 16 | 17 | Before installing, make sure that you have [Composer][2] installed. 18 | 19 | To require mailbox-component into your helpdesk project, simply run the following composer command from your project root: 20 | 21 | ```bash 22 | $ composer require uvdesk/mailbox-component 23 | ``` 24 | 25 | License 26 | -------------- 27 | 28 | The **Mailbox** component and libraries included within the bundle are released under the [OSL-3.0 license][3] 29 | 30 | [1]: https://www.uvdesk.com/ 31 | [2]: https://getcomposer.org/ 32 | [3]: https://github.com/uvdesk/mailbox-component/blob/master/LICENSE.txt -------------------------------------------------------------------------------- /Resources/config/routes.yaml: -------------------------------------------------------------------------------- 1 | uvdesk_mailbox_module_member_routing_resources: 2 | resource: "routes/private.yaml" 3 | prefix: /{_locale}/%uvdesk_site_path.member_prefix%/ 4 | requirements: 5 | _locale: '%app_locales%' 6 | defaults: 7 | _locale: '%locale%' 8 | 9 | uvdesk_mailbox_module_public_routing_resources: 10 | resource: "routes/public.yaml" 11 | prefix: / 12 | requirements: 13 | _locale: '%app_locales%' 14 | defaults: 15 | _locale: '%locale%' 16 | -------------------------------------------------------------------------------- /Resources/config/routes/private.yaml: -------------------------------------------------------------------------------- 1 | helpdesk_member_mailbox_settings: 2 | path: /settings/mailbox 3 | controller: Webkul\UVDesk\MailboxBundle\Controller\MailboxChannel::loadMailboxes 4 | 5 | helpdesk_member_mailbox_load_configurations_xhr: 6 | path: /settings/mailbox/xhr 7 | controller: Webkul\UVDesk\MailboxBundle\Controller\MailboxChannelXHR::loadMailboxesXHR 8 | 9 | helpdesk_member_mailbox_create_configuration: 10 | path: /settings/mailbox/create 11 | controller: Webkul\UVDesk\MailboxBundle\Controller\MailboxChannel::createMailboxConfiguration 12 | 13 | helpdesk_member_mailbox_update_configuration: 14 | path: /settings/mailbox/update/{id} 15 | controller: Webkul\UVDesk\MailboxBundle\Controller\MailboxChannel::updateMailboxConfiguration 16 | defaults: { id: ''} 17 | 18 | helpdesk_member_mailbox_remove_configuration_xhr: 19 | path: /settings/mailbox/remove/{id} 20 | controller: Webkul\UVDesk\MailboxBundle\Controller\MailboxChannelXHR::removeMailboxConfiguration 21 | defaults: { id: ''} 22 | 23 | helpdesk_member_mailbox_direct_convert_mail: 24 | path: /processRawEmail 25 | controller: Webkul\UVDesk\MailboxBundle\Controller\MailboxChannelXHR::processRawContentMail 26 | 27 | helpdesk_member_outlook_mailbox_notification: 28 | path: /mailbox/outlook/listener 29 | controller: Webkul\UVDesk\MailboxBundle\Controller\MailboxChannelXHR::processOutlookMailXHR 30 | 31 | helpdesk_member_mailbox_notification: 32 | path: /mailbox/listener 33 | controller: Webkul\UVDesk\MailboxBundle\Controller\MailboxChannelXHR::processMailXHR 34 | -------------------------------------------------------------------------------- /Resources/config/routes/public.yaml: -------------------------------------------------------------------------------- 1 | helpdesk_member_mailbox_notification: 2 | path: /mailbox/listener 3 | controller: Webkul\UVDesk\MailboxBundle\Controller\MailboxChannelXHR::processMailXHR 4 | -------------------------------------------------------------------------------- /Resources/config/services/automations.yaml: -------------------------------------------------------------------------------- 1 | services: 2 | Webkul\UVDesk\MailboxBundle\Workflow\Events\: 3 | resource: '../../../Workflow/Events/*' 4 | arguments: ['@service_container', '@request_stack', '@doctrine.orm.entity_manager'] 5 | tags: 6 | - { name: uvdesk.automations.workflow.events } 7 | 8 | Webkul\UVDesk\MailboxBundle\Workflow\Actions\: 9 | resource: '../../../Workflow/Actions/*' 10 | arguments: ['@service_container', '@request_stack', '@doctrine.orm.entity_manager'] 11 | tags: 12 | - { name: uvdesk.automations.workflow.actions } 13 | -------------------------------------------------------------------------------- /Resources/config/services/services.yaml: -------------------------------------------------------------------------------- 1 | services: 2 | _defaults: 3 | autowire: true 4 | autoconfigure: true 5 | public: false 6 | 7 | Webkul\UVDesk\MailboxBundle\: 8 | resource: '../../../*' 9 | exclude: '../../../{DependencyInjection,Entity,Package,Templates,Migrations,Tests}' 10 | 11 | Webkul\UVDesk\MailboxBundle\Controller\: 12 | resource: '../../../Controller/*' 13 | tags: ['controller.service_arguments'] 14 | 15 | Webkul\UVDesk\MailboxBundle\Console\: 16 | resource: '../../../Console/*' 17 | exclude: '../../../Console/{UTF8Symbol.php,ANSIEscapeSequence.php}' 18 | 19 | Webkul\UVDesk\MailboxBundle\EventListener\Swiftmailer: 20 | tags: 21 | - { name: uvdesk.event_listener, event: swiftmailer.configuration.updated, method: onSwiftMailerConfigurationUpdated } 22 | - { name: uvdesk.event_listener, event: swiftmailer.configuration.removed, method: onSwiftMailerConfigurationRemoved } 23 | 24 | # Public aliases 25 | uvdesk.mailbox: 26 | public: true 27 | class: Webkul\UVDesk\MailboxBundle\Services\MailboxService 28 | -------------------------------------------------------------------------------- /Resources/views/listConfigurations.html.twig: -------------------------------------------------------------------------------- 1 | {% extends "@UVDeskCoreFramework/Templates/layout.html.twig" %} 2 | 3 | {% block title %}Mailbox Settings{% endblock %} 4 | 5 | {% block templateCSS %} 6 | 116 | {% endblock %} 117 | 118 | {% block pageContent %} 119 |
120 | {# Append Panel Aside #} 121 | {% set asideTemplate = 'Webkul\\UVDesk\\CoreFrameworkBundle\\Dashboard\\AsideTemplate' %} 122 | {% set asideSidebarReference = 'Webkul\\UVDesk\\CoreFrameworkBundle\\UIComponents\\Dashboard\\Panel\\Sidebars\\Settings' %} 123 | 124 | {{ uvdesk_extensibles.getRegisteredComponent(asideTemplate).renderSidebar(asideSidebarReference) | raw }} 125 | 126 |
127 |
128 |
129 |

{{ 'Mailbox Settings'|trans }}

130 |
131 | 132 | 135 |
136 | 137 |
138 |
139 |
140 |
141 | {% endblock %} 142 | 143 | {% block footer %} 144 | {{ parent() }} 145 | 146 | 154 | 155 | 183 | 184 | 305 | {% endblock %} -------------------------------------------------------------------------------- /Resources/views/manageConfigurations.html.twig: -------------------------------------------------------------------------------- 1 | {% extends "@UVDeskCoreFramework//Templates//layout.html.twig" %} 2 | 3 | {% block title %} 4 | {{ 'Mailbox Settings'|trans }} 5 | {% endblock %} 6 | 7 | {% block pageContent %} 8 | 27 | 28 |
29 | {# Append Panel Aside #} 30 | {% set asideTemplate = 'Webkul\\UVDesk\\CoreFrameworkBundle\\Dashboard\\AsideTemplate' %} 31 | {% set asideSidebarReference = 'Webkul\\UVDesk\\CoreFrameworkBundle\\UIComponents\\Dashboard\\Panel\\Sidebars\\Settings' %} 32 | 33 | {{ uvdesk_extensibles.getRegisteredComponent(asideTemplate).renderSidebar(asideSidebarReference) | raw }} 34 | 35 |
36 | {% if mailbox is defined and mailbox.id is not empty %} 37 |

{{ 'Update Mailbox'|trans }}

38 | {% else %} 39 |

{{ 'Add Mailbox'|trans }}

40 | {% endif %} 41 | 42 |
43 | 44 |
45 | {# Mailer Id #} 46 |
47 | 48 | 49 |
50 | {% if mailbox is defined and mailbox.id is not empty %} 51 | 52 | {% else %} 53 | 54 | {% endif %} 55 |
56 |
57 | 58 | {# Mailer Name #} 59 |
60 | 61 | 62 |
63 | {% if mailbox is defined and mailbox.name is not empty %} 64 | 65 | {% else %} 66 | 67 | {% endif %} 68 |
69 |
70 | 71 | {# Status #} 72 |
73 | 86 |
87 | 88 | {# Default Mailbox #} 89 |
90 | 103 |
104 | 105 |
106 | 107 | {# IMAP Settings #} 108 |

{{ 'Incoming Mail'|trans }}

109 |

{{ 'Manage how you wish to retrieve and process emails from your mailbox.'|trans }}

110 | 111 |
112 | 113 | 114 | {% if mailbox is defined and mailbox.imapConfiguration is not empty %} 115 | 123 | {% else %} 124 | 132 | {% endif %} 133 |
134 | 135 |
136 | 137 |
138 | 139 | {# SMTP Settings #} 140 |

{{ 'Outgoing Mail'|trans }}

141 |

{{ 'Manage how you wish to send emails from your mailbox.'|trans }}

142 | 143 |
144 | 145 | 146 | {% if mailbox is defined %} 147 | 153 | 154 | 173 | {% else %} 174 | 180 | {% endif %} 181 |
182 | 183 |
184 | 185 |
186 | 187 | {% if mailbox is defined and mailbox.id is not empty %} 188 | 189 | {% else %} 190 | 191 | {% endif %} 192 |
193 |
194 |
195 | {% endblock %} 196 | 197 | {% block footer %} 198 | {{ parent() }} 199 | 200 | 233 | 234 | 255 | 256 | 277 | 278 | 299 | 300 | 346 | 347 | 368 | 369 | 415 | 416 | 439 | 440 | 705 | 706 | 726 | {% endblock %} 727 | -------------------------------------------------------------------------------- /Routing/RoutingResource.php: -------------------------------------------------------------------------------- 1 | ' 6 | # enable_delimiter: true 7 | 8 | # Specify id of the mailbox you want to use as default for sending emails when no other "configured" mailbox is found. 9 | # Applies to all emails sent through the system & in cases of tickets where the original source mailbox of the created 10 | # ticket is no longer available. 11 | default_mailbox: ~ 12 | 13 | # Configure your mailboxes here 14 | mailboxes: ~ 15 | # mailbox_id: 16 | # name: 'Mailbox' 17 | # enabled: true 18 | # disable_outbound_emails: false 19 | # use_strict_mode: false 20 | 21 | # # Incoming email settings 22 | # # IMAP settings to use for fetching emails from mailbox 23 | # imap_server: 24 | # host: ~ 25 | # username: ~ 26 | # password: ~ 27 | 28 | # # Outgoing email settings 29 | # # SMTP settings to use for sending emails from mailbox 30 | # smtp_server: 31 | # host: ~ 32 | # port: ~ 33 | # username: ~ 34 | # password: ~ 35 | # sender_address: ~ 36 | # 37 | # # For app transport method 38 | # type: ~ 39 | # client: ~ 40 | -------------------------------------------------------------------------------- /Templates/Mailbox/IMAP/AppConfiguration.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Templates/Mailbox/IMAP/DefaultConfiguration.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Templates/Mailbox/IMAP/SimpleConfiguration.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Templates/Mailbox/Mailbox.php: -------------------------------------------------------------------------------- 1 | ' 9 | # enable_delimiter: true 10 | 11 | # Specify id of the mailbox you want to use as default for sending emails when no other "configured" mailbox is found. 12 | # Applies to all emails sent through the system & in cases of tickets where the original source mailbox of the created 13 | # ticket is no longer available. 14 | TEMPLATE; 15 | 16 | if ($this->getDefaultMailbox() == null) { 17 | $template .= <<