which mime type can I use for .MSG file using FILE object
Asked Answered
O

2

6

I have tried to get MIME-type from the FILE which is uploaded earlier but, it is return ''. Is there any library or code for getting file-type of the outlook files in Angular. ex: for images it is showing 'images/png'. please have a look. for .msg file extension outlook file it is showing

enter image description here

But for .png file, it is showing file type as below

enter image description here

in this site

they mentioned Uncommon file extensions would return an empty string How to overcome this issue??? Please help me out to get the MIME type as application/vnd.ms-outlook application/octet-stream.

Oestrin answered 15/4, 2019 at 10:53 Comment(2)
Are you asking what the MIME type should be, or how to determine it programmatically?Phyle
"I have tried to…": Then provide a minimal reproducible example.Phyle
L
3

I came across the same issue/problem that the browser doesn't return correct mime-type for outlook-msg-files. Instead of application/vnd.ms-outlook the type-property of File shows an empty string.

I used the following workaround (by checking the file-extension) to overcome this problem:

In my file-upload-logic, I test the dragged or selected file(s) if they are from any or more accepted mime-types. If there is a file without given mime-type, then I check the file-extension.

Further validation logic, e.g. if the given file is really of outlook-message-type, can be done on the server-side with your prefered programming language.

    let enableOutlookMimetypeDetection: boolean = true;

    let acceptRegexString: string = "(image/png)|(application/vnd.ms-outlook)"; // maybe you have to escape the slashes in the regex
    let allowOutlookMsgFiles: boolean = enableOutlookMimetypeDetection && acceptRegexString.indexOf("application/vnd.ms-outlook") >= 0;

    let acceptRegex: RegExp = new RegExp(acceptRegexString);
    for (let i: number = 0; i < files.length; i++) {
        if (allowOutlookMsgFiles) {
            if (files[i].name !== null && files[i].name !== undefined && files[i].name.endsWith(".msg")) {
                console.log("outlook msg-file found");
                continue;
            }
        }

        if (!acceptRegex.test(files[i].type)) {
            return false;
        }
    }

    return true;
Lazo answered 26/2, 2020 at 12:35 Comment(0)
B
1

Here is how I deal with 'mail' type files saved from outlook with '.msg' format. You can't change type on a file directly, so you need to make a 'copy' of it and than set a MIME of 'application/vnd.ms-outlook'. Feel free to add more type checks or 'else' cases.

  onHandleFileInput(event: any): void {
    if (event?.target as HTMLInputElement & EventTarget) {
      const f = event?.target?.files[0];

      if (f.type === '' && f.name.endsWith('.msg')) {
        const mailFile = new File([f], f.name, { type: 'application/vnd.ms-outlook' });
        this.uploadFile(mailFile);
      } 
    }
  }
Bruise answered 25/5, 2023 at 13:17 Comment(1)
does this happen only with msg files? are there other exceptions that we should consider?Perreault

© 2022 - 2024 — McMap. All rights reserved.