Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8971049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:51:37+00:00 2026-06-15T17:51:37+00:00

I’m trying to make simple IMAP client using winsock/OpenSSL, is this possible without additional

  • 0

I’m trying to make simple IMAP client using winsock/OpenSSL, is this possible without additional libraries? If so, how to send request and get responce? Server is responding only once,even without request,after that i’m sending request and application stuck at SSL_read(..) function,than timeout and BYE.How to make proper request?
enter image description here

bool RequestQueue(const char* serverName)
{
    SOCKET      hSocket = INVALID_SOCKET;
    char        receiveBuf[512];
    ZeroMemory(receiveBuf,512); 
    char        requestBuf[512];
    ZeroMemory(requestBuf,512); 
    sockaddr_in sockAddr = {0};
    bool        bSuccess = true;

    //SSL
    SSL* ssl;
    SSL_CTX* ctx;

    try
    {       
        //Look up hostname and fill sockaddr_in structure
        cout<< "Looking up hostname "<<serverName<<"...";
        FillSockAddr(&sockAddr,serverName,IMAP_SERVER_PORT);
        cout<< "found.\n";

        //creating socket
        cout<<"Creating socket..";
        if((hSocket = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP)) == INVALID_SOCKET)
            throw exception("could not create socket!");
        cout<<"created.\n";

            //Connect to server
        cout<<"Attempting to connect to "<< inet_ntoa(sockAddr.sin_addr)
            <<":"<<IMAP_SERVER_PORT<<" ...";
        if(connect(hSocket,(sockaddr*)(&sockAddr),sizeof(sockAddr))!= 0)
            throw exception("could not connect!");

        cout<<"connected\n";

        ctx = SSL_CTX_new(SSLv23_client_method());
        if(!ctx)
            throw exception("SSL_CTX_new error");

        ssl = SSL_new(ctx);
        SSL_CTX_free(ctx);
        if(!ssl)
            throw exception("ssl initializing error");

        SSL_set_fd(ssl,hSocket);
        if(SSL_connect(ssl) != 1)
            throw exception("SSL_connect error");

        int reqLen;
        int retLen;
        cout<<"==============\n";
        cout<<"====begin=====\n";
        cout<<"==============\n";

        retLen = SSL_read(ssl,receiveBuf,sizeof(receiveBuf));
        if(retLen<0)
            throw exception("SSL_read error.");
        cout<<"S: "<<receiveBuf;

        strcpy(requestBuf,"a001 CAPABILITY");
        reqLen = strlen(requestBuf);
        SSL_write(ssl,requestBuf,reqLen);
        cout<<"C: "<<requestBuf<<endl;  

        ZeroMemory(receiveBuf,sizeof(receiveBuf));
        retLen = SSL_read(ssl,receiveBuf,sizeof(receiveBuf));
        if(retLen<0)
            throw exception("SSL_read error.");

        cout<<"S: "<<receiveBuf;                    
    }
    catch(exception e)
    {
        cout<<"Error : "<<e.what()<<endl;
    }
    if(hSocket != INVALID_SOCKET)
    {
        SSL_shutdown(ssl);
        closesocket(hSocket);
        SSL_free(ssl);      
    }

    return bSuccess;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:51:39+00:00Added an answer on June 15, 2026 at 5:51 pm

    I didn’t analyze your code deeply, but I can see one obvious issue.
    According to the RFC 3501:

    All interactions transmitted by client and server are in the form of
    lines, that is, strings that end with a CRLF. The protocol receiver
    of an IMAP4rev1 client or server is either reading a line, or is
    reading a sequence of octets with a known count followed by a line.

    In your code you’re not terminating the command with CRLF. Try replacing

    strcpy(requestBuf,"a001 CAPABILITY");
    

    with

    strcpy(requestBuf,"a001 CAPABILITY\r\n");
    

    Also, you’d better start without SSL and add it later – this will simplify debugging a lot (i.e. with Wireshark).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.