POP3客户端代码的实现

这个是本学期课程 互联网应用的大作业,由一个独自完成。具体资源可以在我的主页免费下载,应该吧。我记得我设置为免费的。

要求如下:

更加具体的应该去看我的设计报告,这里不能上传。光看下面的代码不太好看懂。

去资源里下载就可以了,免费的。不是免费的踢我,我改一下。有bug踢我。

复制代码请注意:我的注释有的是中文,小心过不了编译器。然后我C语言用的是C99的,环境是乌班图。

1 makefile 用于Linux编译

main.exe:main.out tcp.out logon.out choose.out stat.out list.out retr.out encode.out readLine.out dele.out search.out 
	gcc main.out tcp.out logon.out choose.out stat.out list.out retr.out encode.out readLine.out dele.out search.out  -o main.exe
main.out:main.c
	gcc -c main.c -o main.out
tcp.out:tcp.c
	gcc -c tcp.c -o tcp.out
logon.out:logon.c
	gcc -c logon.c -o logon.out
choose.out:choose.c
	gcc -c choose.c -o choose.out
stat.out:stat.c
	gcc -c stat.c -o stat.out
list.out:list.c
	gcc -c list.c -o list.out
retr.out:retr.c 
	gcc -c retr.c -o retr.out
encode.out:encode.c
	gcc -c encode.c -o encode.out
readLine.out:readLine.c
	gcc -c readLine.c -o readLine.out
dele.out:dele.c
	gcc -c dele.c -o dele.out
search.out:search.c
	gcc -c search.c -o search.out

2 choose() POP3客户端功能选择

#ifndef _CHOOSE_H_
#define _CHOOSE_H_
	int choose();
#endif
#include <unistd.h>
#include <stdio.h>
#include "choose.h"
int choose(){
        int choice = 0;
        puts("-----Here is the main menu!-----");
        puts("UA offers these functions for you:");
        puts("1.check the state of the mailbox");
        puts("2.list all the mails in the mailbox");
        puts("3.display the content of a mail");
        puts("4.delete a main from the mailbox");
        puts("5.keyword search in local mails");
        puts("6.display the subjects of local mails");
        puts("7.quit anyway");
        puts("------End of the main menu------");
        int rec = 0;
        char buf[BUFSIZ];
        do{
		puts("Your choice: ");
                while(rec == 0){
                        rec = read(STDIN_FILENO,buf,sizeof(buf));
                }
                if(rec > 2){
                        puts("Error: too long input!");
                        rec = 0;
                        continue;
                }
                if(buf[0] < '1' || buf[0] > '7'){
                        rec = 0;
                        puts("Error: beyond 1-7!");
                        continue;
                }
                break;
        }while(1 == 1);
        choice = buf[0] - '0';
        return choice;
}

3 dele() 删除邮件

#ifndef _DELE_H_
#define _DELE_H_
	void dele(int cfd);
#endif
#include "dele.h"
#include <unistd.h>
#include <stdio.h>
#include <string.h>
void dele(int cfd){
        int rec = 0;
        char dele[20] = {'D','E','L','E',' ','\0'};
        puts("----DELE----");
        char buf[BUFSIZ];
        //给用户整一个询问功能,免得误删
        char num[10];//用于存放需要删除的序号
        char a;
        int i = 0;
        while((a = getchar())!='\n'){
                num[i] = a;
                ++i;
        }
        num[i] = '\n'; num[i+1] = '\0';
        strcat(dele,num);

        //这里整一个确认
        puts("Are you SURE you want DELETE an email?");
        printf("You command: %s",dele);
        puts("Enter y/Y to confirm and others to CANCEL!");
        printf("You FINAL choice:");
        a = getchar();
        char b;//b是用来清空缓冲区的
        while((b=getchar())!='\n'){

        }
        if(a=='y' || a=='Y'){
                ;//do nothing
        }else return;


        write(cfd,dele,strlen(dele));
        readLine(cfd,buf,sizeof(buf));
        if(buf[0]=='-' && buf[1]=='E' && buf[2]=='R'){
                system("clear");
                puts("From MTA: invalid command!");
                puts("From MTA: or you may not have so many mails!");
                return;
        }
        puts("You have delete one mail!");





}

4 encode() 用于base64解码,本来要命名为decode的,结果命名错了,就一直用下来了

#ifndef _ENCODE_H_
#define _ENCODE_H_
	void encode(char* buf,char*);
#endif
#include "encode.h"
#include <stdio.h>
//encode for very four BASE64 codes 
void toBinary(int num,int* binary){
        int i = 0;
        int j = 0;
        if(num == -1){//处理等号带来的-1的情况,这时需要全为-1 
                for(j=0;j<6;++j){
                        binary[j] = 0;
                }
                return;
        }
        while(num !=0){
                binary[i] = num%2;
                ++i;
                num = num / 2;
        }
        return;
}
void encode(char* password,char* result){
        //password已知是四位了,比如dasf\0,分割与去掉\n的功能需要交给外部解决 
        //result为三位ascii字符,为解码的结果。如果dad\0 
        const char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
        int bit0[6] = {0};//password[0]的二进制表示 
        int bit1[6] = {0};//password[1] 的二进制表示 
        int bit2[6] = {0};//password[2] 的二进制表示 
        int bit3[6] = {0};//password[3] 的二进制表示 
        int count = 0;//=的数量 
        int bit[25];
        //把base64码文变为基于table的数字表示,存放在num中
        int num[4];
        int i = 0; int j = 0;int k = 0;
        for(i=0;i<4;++i){
                for(j=0;j<64;++j){
                        if(password[i]=&
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值