Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Email POP3服务器接收邮件站_Email_Openssl_Pop3 - Fatal编程技术网

Email POP3服务器接收邮件站

Email POP3服务器接收邮件站,email,openssl,pop3,Email,Openssl,Pop3,我正在编写一个用C编写的简单邮件客户端程序,但在接收来自服务器的邮件时遇到了一些问题。成功登录后,我使用命令RETR n,其中n是检索一封邮件的简单数字。我使用SSL连接,问题是没有下载完整的消息,它只是停止,程序阻塞,没有正确完成或根本没有完成。然后,我还在终端中使用openssl对此进行了测试,并得到以下错误: +OK mailbox "max.mustermann" has 4 messages (70911 octets) H miweb004 RETR 1 RENEGOTIATING

我正在编写一个用C编写的简单邮件客户端程序,但在接收来自服务器的邮件时遇到了一些问题。成功登录后,我使用命令RETR n,其中n是检索一封邮件的简单数字。我使用SSL连接,问题是没有下载完整的消息,它只是停止,程序阻塞,没有正确完成或根本没有完成。然后,我还在终端中使用openssl对此进行了测试,并得到以下错误:

+OK mailbox "max.mustermann" has 4 messages (70911 octets) H miweb004
RETR 1
RENEGOTIATING
140235855091344:error:14094153:SSL routines:SSL3_READ_BYTES:no renegotiation:s3_pkt.c:1261:
我用来接收电子邮件的代码是:

//This should download all emails and delete them on the server
int GetAllMessages(BIO *bio) {

    unsigned char command_retr[] = {"RETR 1\n"};

    //Sends command RETR n to the server and retrieve all mails during a loop
    //Loop not added yet and 1 is constant yet, will be changed later
    if( WebSendLine(bio, command_retr, strlen(command_retr)) ) {
        printf("Error in GetAllMesssages: RETR couldn't be send.\n");
        return -1;
    }

    ReceiveEmail(bio);      
}
以及:

我不知道WebRead是做什么的,但是POSIX read可能会返回错误,例如EINTR、EAGAIN或eWoldBlock,因此您真正想要的循环看起来更像这样:

unsigned char buffer[4096];
int nread;

do {
    do {
        nread = WebRead (bio, buffer, sizeof (buffer));
    } while (nread == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
} while (nread > 0 && isend (buffer));
 </td>
            </tr>
        </table>
        <!-- Footer Ende -->
        <!-- /s1 -->
    </td>
    <td width=3D"15" bgcolor=3D"#ffffff"><img src=3D"https://img.ui-po=
接下来,我不知道isend做了什么,但我打赌它是错的,因为它无法在没有访问I的情况下计算出缓冲区中有多少数据


第三,在连接关闭之前,您永远不会从套接字读取0字节,这意味着一旦您读取了RETR响应中的所有数据,您将挂起,直到TCP超时发生,因此您需要实际检查\r\n。\r\n在响应注释中:不要在缓冲区中检查它,因为该字节序列可能分布在多个WebRead调用中。

注释字段有点短,所以这是指jstedfast应答。 所以WebRead只是从服务器读取一些字节,并对openssl头中包含的BIO_read函数进行一些错误检查

//This function should receive and returns a char to the buffer
unsigned char *WebRead(BIO *bio, unsigned char buffer[], int sizeofbuffer) {
int bytes_read; //Temporarily store how many bytes were read: for error checking

bytes_read = BIO_read(bio, buffer, sizeofbuffer);
if( bytes_read == 0 ) {
    //No more data available on an non-blocking connection
    return 0;
}
else if( bytes_read < 0 ) {
    //Error occured, retry and if this fails return  0
    if( ! BIO_should_retry(bio) )
        return 0;
}
return buffer;
}
它只是说BIO_Read返回读取的字节数,或0或-1。在阻塞连接上,它返回0,这表示连接已关闭,而-1表示发生错误

isend函数检查\r\n,好的,它写得不好,您是对的,我不应该只检查缓冲区,但我想这不会导致问题,isend函数必须更改,但我想它不会导致此错误。 因为它返回的不是整封邮件,它只是停在某个地方,我想如果isend会导致这个问题,我会收到整封邮件,然后被卡住,但我得到的最后一点是这样的:

unsigned char buffer[4096];
int nread;

do {
    do {
        nread = WebRead (bio, buffer, sizeof (buffer));
    } while (nread == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
} while (nread > 0 && isend (buffer));
 </td>
            </tr>
        </table>
        <!-- Footer Ende -->
        <!-- /s1 -->
    </td>
    <td width=3D"15" bgcolor=3D"#ffffff"><img src=3D"https://img.ui-po=
我期待着收到你的来信

国王问候
绿色性:-

嗨,首先我要感谢你的帮助。:-我将在下面的另一个答案文本字段中回答您的问题:-