Search The ForumSearch   RegisterRegister  LoginLogin

MailBee.NET Objects

 AfterLogic Forum : MailBee.NET Objects
Subject Topic: Attachment SaveToFolder issue Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
mnoreen
Newbie
Newbie


Joined: 17 July 2012
Location: United States
Online Status: Offline
Posts: 19
Posted: 31 March 2020 at 8:06am | IP Logged Quote mnoreen

The SaveToFolder() method on the Attachment class doesn't seem to quite be doing what is documented.

I have a mail message that is loaded, then there's a foreach loop to go through the attachments and calling the SaveToFolder() method on each one. Pretty simple. Except, this one mail message so happens to have the same file attached 2x.

I've stepped through this code in the debugger. The .FileName property is different for both attachments. But the SaveToFolder() method isn't using the FileName property, it appears to be using the .FilenameOriginal property.

If I change the code to pass "false" in the SaveToFolder() method. It will save out the 2nd attachment now with a "[1]" postfix to the filename. But then, that doesn't match the attachment's .filename property.

Back to Top View mnoreen's Profile Search for other posts by mnoreen
 
mnoreen
Newbie
Newbie


Joined: 17 July 2012
Location: United States
Online Status: Offline
Posts: 19
Posted: 31 March 2020 at 8:09am | IP Logged Quote mnoreen

Code:

foreach (Attachment attachment in msg.Attachments)
            {
                if (attachment.IsInline)
                    continue;

                attachment.SaveToFolder(workFolder, false);
            }


This code works in that both files are saved, but the 2nd file is saved with postfix on the filename rather than using the .FileName property from the attachment.
Back to Top View mnoreen's Profile Search for other posts by mnoreen
 
Alex
AfterLogic Support
AfterLogic Support
Avatar

Joined: 19 November 2003
Online Status: Offline
Posts: 2206
Posted: 31 March 2020 at 9:36am | IP Logged Quote Alex

Neither FilenameOriginal nor FileName are assigned to the filename generated by SaveToFolder method. Suffix appended to FileName is to distinguish between attachments with the same name in .Attachments collection. SaveToFolder, on other hand, appends a completely different suffix which is to distinguish between files with the same filename in the target folder. Before SaveToFolder call, it's not known which filename will be actually assigned (we don't know if the file with the same name already exists in that folder or not).

So, SavedAs is assigned AFTER SaveToFolder and it's the only property which can be reliably used as a referenced to the saved file.

Regards,
Alex
Back to Top View Alex's Profile Search for other posts by Alex
 
mnoreen
Newbie
Newbie


Joined: 17 July 2012
Location: United States
Online Status: Offline
Posts: 19
Posted: 01 April 2020 at 9:53am | IP Logged Quote mnoreen

Thank you Alex, I worked around it. I was just going off the code definition/comments that are a part of the Mailbee object browser (for example, I put cursor over the Attachment declaration in my code, hit F12 (Go To Definition).

Code:

       // Remarks:
        //     This method saves the attachment content to the folder under the actual filename
        //     of the attachment (which is taken from MailBee.Mime.Attachment.Filename property).
Back to Top View mnoreen's Profile Search for other posts by mnoreen
 
mnoreen
Newbie
Newbie


Joined: 17 July 2012
Location: United States
Online Status: Offline
Posts: 19
Posted: 06 April 2020 at 12:02pm | IP Logged Quote mnoreen

It's a tricky situation. We want to save then remove all non-inline attachments from an .eml file, and finally resave the .eml. So we reworked the code to call

Code:

SaveAll(string folderName, bool ignoreInlineAttachments)


Then use a reverse iteration to remove the attachments from the MailMessage object.

Code:

for (int i = msg.Attachments.Count - 1; i >= 0; i--)
            {
                if (msg.Attachments.IsInline)
                    continue;

                msg.Attachments.RemoveAt(i);
            }


But this seems like there's a possibility it could get out of sequence. Would it be possible to get a function equivalent to the SaveAll() method with the "ignoreInlineAttachments" parameter?

Back to Top View mnoreen's Profile Search for other posts by mnoreen
 
Alex
AfterLogic Support
AfterLogic Support
Avatar

Joined: 19 November 2003
Online Status: Offline
Posts: 2206
Posted: 07 April 2020 at 1:29am | IP Logged Quote Alex

Sorry, I could not understand what you're asking for.

A function equivalent to the SaveAll() method with the "ignoreInlineAttachments" parameter? - How would it differ from SaveAll with this parameter (which is already there)?

Regards,
Alex

Back to Top View Alex's Profile Search for other posts by Alex
 
mnoreen
Newbie
Newbie


Joined: 17 July 2012
Location: United States
Online Status: Offline
Posts: 19
Posted: 10 April 2020 at 1:26pm | IP Logged Quote mnoreen

I was hoping that there could be RemoveAll(bool ignoreInlineAttachments) method that worked *like* the SaveAll() method w/ that boolean parameter.
Back to Top View mnoreen's Profile Search for other posts by mnoreen
 
Alex
AfterLogic Support
AfterLogic Support
Avatar

Joined: 19 November 2003
Online Status: Offline
Posts: 2206
Posted: 11 April 2020 at 6:14am | IP Logged Quote Alex

Got it now, thanks. No, that would be a too special method for a general-purpose library.

BTW, when do you get "out of sequence" situation?

Regards,
Alex
Back to Top View Alex's Profile Search for other posts by Alex
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump

Powered by Web Wiz Forums version 7.9
Copyright ©2001-2004 Web Wiz Guide