Sicos1977 / MSGReader

C# Outlook MSG file reader without the need for Outlook
http://sicos1977.github.io/MSGReader
MIT License
489 stars 168 forks source link

MsgReader.Mime.Message.Save(FileInfo fileInfo) does not dispose FileStream #393

Closed sineme closed 7 months ago

sineme commented 9 months ago

Describe the bug MsgReder.Mime.Message.Save(FileInfo fileInfo) does not dispose of the stream it creates.

To Reproduce call MsgReder.Mime.Message.Save(FileInfo fileInfo)

Expected behavior The file stream that is created inside the method should be disposed.

Additional context By not disposing the file stream the program keeps the file handles open, blocking access to the file (i.e. file is used by another process exceptions elsewhere).

    public void Save(FileInfo file)
    {
        if (file == null)
        {
            throw new ArgumentNullException("file");
        }

        Save(file.OpenWrite());
    }

should be

    public void Save(FileInfo file)
    {
        if (file == null)
        {
            throw new ArgumentNullException("file");
        }

        using var messageStream = file.OpenWrite();
        Save(messageStream);
    }
Sicos1977 commented 7 months ago

Fixed