Mail Fetching - Error while processing attachment and inline image.

Mail Fetching - Error while processing attachment and inline image.

Issue
  1. During the process of fetching emails, attachments are dropped as a result of the presence of directory traversal characters.
  2. Furthermore, an issue arises when processing inline images, this particular error related to inline images results in the stop of the email fetching process
Attachment error trace
[10:29:22:721]|[09-25-2023]|[com.manageengine.servicedesk.v3api.utils.AttachmentAPIUtil]|[SEVERE]|[110]: Exception while writing Attachment file| 
java.nio.file.InvalidPathException: Illegal char <:> at index 43:
at sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)
at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
at sun.nio.fs.WindowsPath.parse(WindowsPath.java:94)
at sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:255)
at java.io.File.toPath(File.java:2273)
at com.manageengine.servicedesk.v3api.utils.AttachmentAPIUtil.uploadStreamAsAttachment(AttachmentAPIUtil.java:1624)
at com.manageengine.servicedesk.mailutils.MailAPI.uploadAttachment(MailAPI.java:2830)
at com.manageengine.servicedesk.mailutils.ModuleHandler.handleMailObject(ModuleHandler.java:111)
at com.adventnet.servicedesk.mailutils.MailProcessor.processEMail(MailProcessor.java:71)
at com.manageengine.servicedesk.mail.core.fetcher.EwsMailFetcher.fetchAndProcessMails(EwsMailFetcher.java:159)
at com.manageengine.servicedesk.mail.core.fetcher.MailFetcher.startFetching(MailFetcher.java:306)
at com.adventnet.servicedesk.helpdesk.mail.task.MailFetchingTask.executeTask(MailFetchingTask.java:39)
at com.adventnet.taskengine.internal.SchedulerBean.executeTask(SchedulerBean.java:641)
at sun.reflect.GeneratedMethodAccessor81.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.adventnet.mfw.bean.BeanProxy.lambda$invoke$0(BeanProxy.java:51)
at com.zoho.mickey.api.DefaultCodeBlock.execute(CodeBlock.java:453)
at com.adventnet.mfw.bean.BeanProxy.invoke(BeanProxy.java:48)
at com.sun.proxy.$Proxy5.executeTask(Unknown Source)
at com.adventnet.taskengine.internal.ScheduleExecutor.executeNextTask(ScheduleExecutor.java:334)
at com.adventnet.taskengine.internal.ScheduleExecutor.run(ScheduleExecutor.java:225)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:750)

[10:29:22:721]|[09-25-2023]|[com.manageengine.servicedesk.mailutils.MailAPI]|[INFO]|[110]: Attchment dropped due to : Illegal char <:> at index 43
(OR)
[com.manageengine.servicedesk.v3api.utils.AttachmentAPIUtil]|[SEVERE]|[268]: Exception while writing Attachment file| 
com.adventnet.iam.security.IAMSecurityException: INVALID_FILE_NAME
at com.manageengine.servicedesk.v3api.utils.AttachmentAPIUtil.uploadStreamAsAttachment(AttachmentAPIUtil.java:1607)
at com.manageengine.servicedesk.mailutils.MailAPI.uploadAttachment(MailAPI.java:2830)
at com.manageengine.servicedesk.mailutils.ModuleHandler.handleMailObject(ModuleHandler.java:111)
at com.adventnet.servicedesk.mailutils.MailProcessor.processEMail(MailProcessor.java:71)
at com.manageengine.servicedesk.mail.core.fetcher.JavaMailFetcher.fetchAndProcessMails(JavaMailFetcher.java:209)
at com.manageengine.servicedesk.mail.core.fetcher.MailFetcher.startFetching(MailFetcher.java:306)
at com.adventnet.servicedesk.helpdesk.mail.task.MailFetchingTask.executeTask(MailFetchingTask.java:39)
at com.adventnet.taskengine.internal.SchedulerBean.executeTask(SchedulerBean.java:641)
at sun.reflect.GeneratedMethodAccessor86.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.adventnet.mfw.bean.BeanProxy.lambda$invoke$0(BeanProxy.java:51)
at com.zoho.mickey.api.DefaultCodeBlock.execute(CodeBlock.java:453)
at com.adventnet.mfw.bean.BeanProxy.invoke(BeanProxy.java:48)
at com.sun.proxy.$Proxy2.executeTask(Unknown Source)
at com.adventnet.taskengine.internal.ScheduleExecutor.executeNextTask(ScheduleExecutor.java:334)
at com.adventnet.taskengine.internal.ScheduleExecutor.run(ScheduleExecutor.java:225)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:750)
[com.manageengine.servicedesk.mailutils.MailAPI]|[INFO]|[268]: Attchment dropped due to : INVALID_FILE_NAME|


Inline image error trace
[10:29:22:737]|[09-25-2023]|[com.manageengine.servicedesk.v3api.utils.InlineImageUtil]|[SEVERE]|[110]: Exception while writing image file| 
java.io.IOException: Stream closed
at java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:170)
at java.io.BufferedInputStream.read(BufferedInputStream.java:336)
at java.io.FilterInputStream.read(FilterInputStream.java:107)
at java.nio.file.Files.copy(Files.java:2908)
at java.nio.file.Files.copy(Files.java:3027)
at com.manageengine.servicedesk.v3api.utils.InlineImageUtil.uploadStreamAsImage(InlineImageUtil.java:265)
at com.manageengine.servicedesk.mailutils.MailAPI.uploadInlineImage(MailAPI.java:2882)
at com.manageengine.servicedesk.mailutils.ModuleHandler.handleMailObject(ModuleHandler.java:115)
at com.adventnet.servicedesk.mailutils.MailProcessor.processEMail(MailProcessor.java:71)
at com.manageengine.servicedesk.mail.core.fetcher.EwsMailFetcher.fetchAndProcessMails(EwsMailFetcher.java:159)
at com.manageengine.servicedesk.mail.core.fetcher.MailFetcher.startFetching(MailFetcher.java:306)
at com.adventnet.servicedesk.helpdesk.mail.task.MailFetchingTask.executeTask(MailFetchingTask.java:39)
at com.adventnet.taskengine.internal.SchedulerBean.executeTask(SchedulerBean.java:641)
at sun.reflect.GeneratedMethodAccessor81.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.adventnet.mfw.bean.BeanProxy.lambda$invoke$0(BeanProxy.java:51)
at com.zoho.mickey.api.DefaultCodeBlock.execute(CodeBlock.java:453)
at com.adventnet.mfw.bean.BeanProxy.invoke(BeanProxy.java:48)
at com.sun.proxy.$Proxy5.executeTask(Unknown Source)
at com.adventnet.taskengine.internal.ScheduleExecutor.executeNextTask(ScheduleExecutor.java:334)
at com.adventnet.taskengine.internal.ScheduleExecutor.run(ScheduleExecutor.java:225)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:750)
(OR)
com.manageengine.servicedesk.mailutils.FetcherException: Error while processing inline image
at com.manageengine.servicedesk.mailutils.MailAPI.uploadInlineImage(MailAPI.java:2887)
at com.manageengine.servicedesk.mailutils.ModuleHandler.handleMailObject(ModuleHandler.java:115)
at com.adventnet.servicedesk.mailutils.MailProcessor.processEMail(MailProcessor.java:71)
at com.manageengine.servicedesk.mail.core.fetcher.EwsMailFetcher.fetchAndProcessMails(EwsMailFetcher.java:159)
at com.manageengine.servicedesk.mail.core.fetcher.MailFetcher.startFetching(MailFetcher.java:306)
at com.adventnet.servicedesk.helpdesk.mail.task.MailFetchingTask.executeTask(MailFetchingTask.java:39)
at com.adventnet.taskengine.internal.SchedulerBean.executeTask(SchedulerBean.java:641)
at sun.reflect.GeneratedMethodAccessor81.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.adventnet.mfw.bean.BeanProxy.lambda$invoke$0(BeanProxy.java:51)
at com.zoho.mickey.api.DefaultCodeBlock.execute(CodeBlock.java:453)
at com.adventnet.mfw.bean.BeanProxy.invoke(BeanProxy.java:48)
at com.sun.proxy.$Proxy5.executeTask(Unknown Source)
at com.adventnet.taskengine.internal.ScheduleExecutor.executeNextTask(ScheduleExecutor.java:334)
at com.adventnet.taskengine.internal.ScheduleExecutor.run(ScheduleExecutor.java:225)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:750)
Caused by: java.util.regex.PatternSyntaxException: Unclosed group near index 213
(?i)(src="cid:pcfclogo(200x91pxl_906147ee-00ae-4b50-b77b-dd8156fdd620.png"|src='cid:pcfclogo(200x91pxl_906147ee-00ae-4b50-b77b-dd8156fdd620.png'|src=cid:pcfclogo(200x91pxl_906147ee-00ae-4b50-b77b-dd8156fdd620.png)
at java.util.regex.Pattern.error(Pattern.java:1969)
at java.util.regex.Pattern.accept(Pattern.java:1819)
at java.util.regex.Pattern.group0(Pattern.java:2922)
at java.util.regex.Pattern.sequence(Pattern.java:2065)
at java.util.regex.Pattern.expr(Pattern.java:2010)
at java.util.regex.Pattern.group0(Pattern.java:2919)
at java.util.regex.Pattern.sequence(Pattern.java:2065)
at java.util.regex.Pattern.expr(Pattern.java:2010)
at java.util.regex.Pattern.group0(Pattern.java:2919)
at java.util.regex.Pattern.sequence(Pattern.java:2065)
at java.util.regex.Pattern.expr(Pattern.java:2010)
at java.util.regex.Pattern.compile(Pattern.java:1702)
at java.util.regex.Pattern.<init>(Pattern.java:1352)
at java.util.regex.Pattern.compile(Pattern.java:1028)
at com.manageengine.servicedesk.mailutils.MailAPI.uploadInlineImage(MailAPI.java:2883)
... 22 more


Fix
      Apply the attached fix jar to resolve both of the issues.
Note
      Before applying the .fjar file, kindly verify its compatibility in the "Jar Compatibility" section below.
Steps to apply the fix
1. Download the attached .fjar file.
2. Click here for steps to apply the .fjar file.
3. Restart the application service.
4. Check for the issue.
5. If the issue occurs again, enable the email debug in the application, recreate the issue after enabling the email debug then immediately zip the logs (<server_home>\logs folder. For eg: C:\Program Files\ManageEngine\ServiceDesk\logs folder) and share it with us for analysis. If the size of the log file is huge, you can send it to us using our FTP link https://bonitas2.zohocorp.com/. Select the product as "ServiceDesk Plus" and provide the proper ticket number.Jar Compatibility Details

Jar Compatibility
Build
Compatible Jar
14501, 14502 & 14503
14501_attachmentAndInlineImage.fjar
14504
14504_attachmentAndInlineImage.fjar

Issue ID:
SD-113853
Please verify the mentioned issue ID in the readme. If it's not listed, please wait while we address the issue. Once the fix is implemented in a build, we will update the issue ID in the readme.

                  New to ADSelfService Plus?

                    • Related Articles

                    • Mail Fetching Stopped Due to Inline Image Handling

                      Issue Cause : While fetching a mail, in certain mail servers, cid of inline image is not parsed correctly. Once inline stream is converted to image, cid in src attr will be replaced with image url. cid for uploaded inline image in mail content is not ...
                    • Fix: Mail fetching stops due to invalid characters in the attachment name

                      Issue: Mail fetching being stopped due to invalid characters "?" , ":" in the filename. In this case, the eml file's subject contains ":" character and so, while uploading the .eml as attachment, error is thrown (Only in windows server) Trace: ...
                    • Mail Fetching: Inline Images Dropping Due to Invalid Extension

                      Issue: The inline image's file name from the email doesn't contain the extension. Example: filename = sys_attachment.dosys_id=5bb0751c8303b5dc96a238226daad371 As a result, the inline image gets stripped during the mail fetching process. The sender of ...
                    • Mail fetching - deleted flag issue

                      This message will be thrown, when you have provided a shared mailbox. The concept here is, SDP MSP reads the mail from the configured mailbox and adds it as a request. During the time, if some other application fetches the mail from the same mailbox ...
                    • Mail Fetching : Inline Image URL Replace error.

                      Issue: Mail fetching is stopping due to inline image Handling. The problem with replacing inline image URLs is the underlying cause of the issue. The issue will occur during addition of conversation not in new request creation. ErrorTrace: ...