Code Monkey home page Code Monkey logo

Comments (3)

jstedfast avatar jstedfast commented on June 9, 2024

the MimeMessage Load mail make the application memory up until Server kill this app.

Are you Dispose()ing the messages? It sounds like you aren't.

That said, if you are writing an IMAP server, you should probably be using the MimeReader class instead of MimeParser or MimeMessage.Load().

If you implement your IMAP server correctly, you should be able to get away with NEVER needing to load the entire message.

What you need to do is subclass MimeReader and override the On*Begin/End() methods that you are interested in (which is probably most or all of them for your scenario). Use those overrides to cache information about the message headers, MIME headers (for each part), the structure of the message, the stream offsets for the body parts, etc.

Then, if/when the client requests the full message or a body part, you can look up the stream offsets and just stream the substream of the content the client asked for.

from mailkit.

Dylan-Jinx avatar Dylan-Jinx commented on June 9, 2024

@jstedfast I Use MimeKit.ExperimentalMimeParser but it still happens memory surge.and then I try to use MimeMessage.Dispose(). It can drastically reduce memory usage, and I don't know if that's something you're not advocating.After the memory analysis, it was found that the heap size was enlarged because the Dispose method was not executed, which occupied a large amount of memory.So, now I do not have a good solution, I do not know the author you have a good solution.

from mailkit.

jstedfast avatar jstedfast commented on June 9, 2024

I Use MimeKit.ExperimentalMimeParser but it still happens memory surge

Well, obviously, because you are loading messages into memory and messages can be quite large.

I try to use MimeMessage.Dispose(). It can drastically reduce memory usage, and I don't know if that's something you're not advocating.

In your use case, you obviously need to call Dispose() on the messages when you are done with them.

So, now I do not have a good solution, I do not know the author you have a good solution.

I already gave you a solution - DO NOT LOAD MESSAGES INTO MEMORY!

Use the MimeReader class by subclassing it and overriding the On*Begin()/End() and OnHeaderRead() methods to get the information you need such as file/stream offsets, header values, etc.

You do not need to use MimeParser or ExperimentalMimeParser to get the information you need. They might be more convenient, but they are obviously not working out for you, so you need to implement a lower-level solution using MimeReader instead.

from mailkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.