ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/c++/socket++-1.10/test/tsendfiles.C
Revision: 1.1
Committed: Mon Feb 26 15:02:39 2001 UTC (24 years, 10 months ago) by ab11
Content type: text/plain
Branch: MAIN
CVS Tags: PROJECT_COMPLETION
Log Message:
Test programs for Networking class. Unused by the host

File Contents

# Content
1 #include <fstream.h>
2 #include <sockinet.h>
3 #include <pwd.h>
4 #include <stdio.h>
5 #include <unistd.h>
6
7 static int send_cmd(iosockstream&, const char* cmd=0);
8
9 main(int ac, char** av)
10 {
11 if (ac < 3) {
12 cerr << "USAGE: " << av[0] << " recipient-email-addr files...\n";
13 return 1;
14 }
15
16 char rcpt[512];
17 char sender[512];
18 iosockinet sio(sockbuf::sock_stream);
19 sio->connect(sio->localhost(), "smtp", "tcp");
20
21 send_cmd(sio, 0);
22 send_cmd(sio, "HELO");
23
24
25 sprintf(rcpt, "RCPT TO:%s", av[1]);
26
27 passwd* pw = getpwuid( getuid() );
28 sprintf(sender, "MAIL FROM:<%s@%s>", pw->pw_name, sio->localhost());
29
30 for (int i=2; i < ac; i++) {
31 send_cmd(sio, sender);
32 send_cmd(sio, rcpt);
33 send_cmd(sio, "DATA");
34 sio << "\r\n------------------------" << av[i]
35 << "------------------------\r\n" << flush;
36
37 ifstream cin(av[i]);
38 char buf[512];
39 while(cin.getline(buf, 511)) {
40 if (buf[0] == '.' && buf[1] == 0) {
41 cerr << av[0]
42 << ": char '.' on a line of its own\n";
43 return 1;
44 }
45 sio << buf << "\r\n" << flush;
46 }
47 sio << "\r\n.\r\n" << flush;
48 send_cmd(sio, 0);
49 }
50 send_cmd(sio, "QUIT");
51 }
52
53 int send_cmd(iosockstream& s, const char* cmd)
54 {
55 char buf[256];
56 if (cmd) s << cmd << "\r\n" << flush;
57 s.getline(buf, 255);
58 cout << buf << endl;
59 return 0;
60 }