Exemplo n.º 1
0
void SmtpConnectionHandler::run()
{
	QTcpSocket tcpSocket; 
	tcpSocket.setSocketDescriptor( _socketDescriptor );

	QString from;
	QString replyAddress;
	QStringList destinations;
	QByteArray mailContent;
	ByteArrayList attachments;

	bool result = receiveMail( tcpSocket, from, replyAddress, destinations, mailContent, attachments );
	tcpSocket.abort();
	if( false == result )
		return;


	// at this point we make some checks to ensure that all the parameters we have are ok

	result = checkMailAddress( from );
	if( false == result )
		return;

	result = checkMailAddress( replyAddress );
	if( false == result )
		return;

	foreach( QString destination, destinations )
	{
		result = checkMailAddress( destination );
		if( false == result )
			return;
	}
Exemplo n.º 2
0
void saacproto_Message_recv( int fd,
                             char* id_from,
                             char* charname_from,
                             char* id_to,
                             char* charname_to,
                             char* message,
                             int option )
{
    receiveMail( id_from, charname_from,
                       id_to, charname_to, message, option ,0,0);
}
Exemplo n.º 3
0
int readMail( char *dir )
{
    int i, read_count=0;
    for( i=0; i<256; i++){
        char dirname[1000];
        DIR *d;

        snprintf(dirname, sizeof( dirname ), "%s/0x%x", dir, i );
        d = opendir(dirname);
        if(d == NULL ){
			mkdir( dirname, 0755);
			log("创建 %s\n", dirname);
            continue;
        }
        while(1){
            struct dirent *de;        
            de = readdir( d );
            if( de == NULL )break;
            if( de->d_name[0] != '.' ){
                char filename[1000];
                FILE *fp;
                struct stat s;
                snprintf( filename, sizeof( filename),
                          "%s/%s", dirname, de->d_name );
                if( stat( filename, &s ) < 0 ){
                    continue;
                }
                if( !(s.st_mode & S_IFREG)) continue;
                fp = fopen( filename, "r" );
                if( fp == NULL ){
                    log( "不能打开文件 %s %s\n",filename,strerror(errno));
                    continue;
                }
                {
                    char line[16384];
                    char toid[1000] , fromid[1000];
                    char tochar[CHARNAME_MAX*2+1];
                    char fromchar[CHARNAME_MAX*2+1];
                    char text[TEXT_MAX*2+1];
                    int opt=0;
                    toid[0] = fromid[0] = tochar[0] =
                        fromchar[0] = text[0] = 0;
                    fgets( line, sizeof(line), fp );                    
                    chop(line);
                    if( strncmp( TO_ID_HEAD , line, strlen(TO_ID_HEAD) )==0){
                        snprintf( toid , sizeof( toid ),"%s",
                                  line+strlen(TO_ID_HEAD ));
                    }
                    fgets( line, sizeof( line ), fp );
                    chop(line);
                    if( strncmp( TO_CHAR_HEAD, line,strlen(TO_CHAR_HEAD))==0){
                        snprintf( tochar, sizeof( tochar ), "%s",
                                  line+strlen( TO_CHAR_HEAD ));
                        makeStringFromEscaped( tochar );
                    }
                    fgets( line, sizeof( line ),fp );
                    chop(line);                    
                    if( strncmp( FROM_ID_HEAD,line,strlen(FROM_ID_HEAD))==0){
                        snprintf( fromid, sizeof( fromid ),"%s",
                                  line + strlen( FROM_ID_HEAD ));
                    }
                    fgets( line,sizeof(line),fp);
                    chop(line);                    
                    if(strncmp(FROM_CHAR_HEAD,line,strlen(FROM_CHAR_HEAD))==0){
                        snprintf( fromchar, sizeof( fromchar ),
                                  line + strlen(FROM_CHAR_HEAD ));
                        makeStringFromEscaped( fromchar );
                    }
                    fgets( line,sizeof(line),fp);
                    chop(line);                    
                    if( strncmp( OPTION_HEAD,line, strlen(OPTION_HEAD))==0){
                        opt = atoi( line + strlen( OPTION_HEAD ) );
                    }
					fgets( line, sizeof( line),fp);
                    chop(line);                    
                    if( strncmp(TEXT_HEAD,line,strlen(TEXT_HEAD))==0){
                        snprintf( text, sizeof( text), "%s",
                                  line + strlen( TEXT_HEAD ));
                        makeStringFromEscaped( text );
                    }
                    if( toid[0] == 0 || fromid[0] == 0 ||
                        tochar[0] == 0 || fromchar[0] == 0 ||
                        text[0] == 0 ){
                        log( "有问题邮件! %s 接收ID[%c] 接收名字[%c]"
                             " 发送ID[%c] 发送名字[%c] 文本[%c]\n",
                             filename,
                             toid[0], tochar[0], fromid[0], fromchar[0],
                             text[0] );
                        // Nuke +1 1027: Close for safe
                        fclose(fp);
                        continue;
                    }
                    receiveMail( fromid, fromchar,
                                 toid, tochar,
                                 text, opt , 1,
                                 strtoul(de->d_name,NULL,10));
                    read_count++;                    
                }
                fclose(fp);

            }
        }
        closedir(d);
    }
    log( "读取邮件: 在'%s'目录里读取到 %d 封邮件 \n", dir, read_count );
    return 0;
}