Attachment file extension doesn't come

we are using aspose library to split the email and its attachments.

Some times we found that file extension is not coming in attachment name.we are trying to fetch attachment file name from method attchmnt.getFileName(). We found that this method doesn't provide full file name,instead it provides few charaters of file name and its extension.

In some cases this method is not returning file extension eg. attachment name is "Sample First Report.docx",it is returing file name as "SampleFi" only.

We found there is an another method getLongFileName(), this method howerver provides full file name and its extension. Even in case as mentioned above where getFileName() is not returning file extension, getLongFileName() is returning the extension.

Please could you provide the details of these 2 methods and suggest scenarios where each can be used.

Please provide the update ASAP as we are facing this issue in our production system and we need to apply the fix ASAP.

Thanks.

Hi Sachin,


Thank you for using Aspose.Email.

Attachment.getFileName() represents the display name of the attachment that is displayed in an email client. In order to be sure about getting the file name alonwith extension, please always use the getLongFileName() fucntion, as it returns the complete file name with extention.

Regarding the incomplete filename, can you please provide us a sample file that we can use to analyze this issue and assist you further.

Thanks.

We replaced getFileName() with getLongFileName() but to my surprise in some cases getLongFileName() is coming null while getFileName() is giving value.

Also as suggested by you that getFileName() is same as display name. Actually we see its different. getFileName() actually gives short file name.

Could you please prvide the exact documentation and reference for use of these methods.

Please treat this urgent.

Hi Sachin,


Sorry for the trouble you are facing.

Can you please send us some sample email files that possess this issue? We will investigate this issue and report it to our development team in case it is a bug of our API.

I have again gone though some documentation and support material and would like to share that getFileName() gets a file name string restricted in length to 12 characters that includes a base name of up to eight characters, one character for a period, and up to three characters for a file name extension, while getLongFileName() gets the full file name and extension of the Attachment object.

Looking forward to some sample files for assisting you further.

Hi,

I am attaching a file whose atttzachment’s extension and fileName is not coming.

Please look into it.


Thanks.

Hi Sachin,

I have analyzed the MSG file sent by you and have observed that extension information is not present there. For testing purpose, I pasted a sample inline image in the same message and then executed the following code. It was found that the second image, contains the PR_ATTACH_EXTENSION_W property where as first original inline image does not have this extension property. Therefore, only inline image name can be extracted but not the extension.

There is another attachment property MimeTag, which can be considered to attach extension manually. This property is also demonstrated in the following sample code. "Sample.zip" attached here contains the modified MSG file having additional sample inline image.

Please give it a try and let us know your feedback.
import java.io.FileInputStream;
import com.aspose.email.License;
import com.aspose.email.MapiAttachment;
import com.aspose.email.MapiAttachmentCollection;
import com.aspose.email.MapiMessage;
import com.aspose.email.MapiPropertyTag;
public class TestMain
{
/** * @param args */
public static void main(String[] args)
{
try
{
//Create a stream object containing the license file
FileInputStream fstream=new FileInputStream("E:\\Aspose.Total.Java.lic");

//Instantiate the License class
License license=new License();

//Set the license through the stream object
license.setLicense(fstream);
}
catch(Exception ex)
{
//Printing the exception, if it occurs
System.out.println(ex.toString());
}
String fileName = ("Sample.msg");
MapiMessage message = MapiMessage.fromFile(fileName);
MapiAttachmentCollection attachments = message.getAttachments();

for (int i = 0; i < attachments.size(); i++)
{
MapiAttachment att = (MapiAttachment)attachments.get(i);

if(att.getProperties().contains(MapiPropertyTag.PR_ATTACH_EXTENSION_W))
{
System.out.println("Long File Name = "+ att.getLongFileName() + ", FileName = " + att.getFileName() + ", Extension = " + att.getExtension());
}
else
{
System.out.println("Long File Name = "+ att.getLongFileName() + ", FileName = " + att.getFileName() + ", Extension = " + att.getExtension());
}
System.out.println("Mime Tag = "+ att.getMimeTag());
}
}
}

Following is the output of the sample code where first information is for original inline image, where as second information is about my sample inline image.

Long File Name = 112120315255407602, FileName = 11212031, Extension = null
Mime Tag = image/jpeg
Long File Name = image001.png, FileName = image001.png, Extension = .png
Mime Tag = image/png