0 votes

Hello, im am trying to create an asp.net mvc app. I am stucked at a point and i dont have any clue how to solve it.

In a controller i am trying to store imap data in a session

imap has CurrentFolder {Limilabs.Client.IMAP.FolderStatus}

Session["user"] = new LoginModels() { UserLogin = address, Address = address, Password = password, UserImap = imap};

In a different controller i want to get the data back,

var sessionData = this.Session["user"] as LoginModels;
imap2 = sessionData.UserImap;

imap2 CurrentFolder will be null.

Im tried to give it directly

imap2.CurrentFolder = sessionData.UserImap.CurrentFolder; 

it isnt possible, visual studio tells me its readOnly. Is there any way to get this information, or its only work if i login the user again?

Best Regards: Alex Cserodi

by (420 points)

1 Answer

+1 vote

Imap.CurrentFolder is a read-only property.

To change the currently selected folder use Imap.Select method:

using (Imap imap = new Imap())
{
    imap.Connect("imap.example.com");    // or ConnectSSL for SSL
    imap.UseBestLogin("user", "password");


    imap.Select("Sent items");


    List<long> uids = imap.GetAll();

    foreach (long uid in uids)
    {
        IMail email = new MailBuilder()
            .CreateFromEml(imap.GetMessageByUID(uid));
        string subject = email.Subject;
    }
    imap.Close();
}
by (300k points)
...