1 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
3 // Copyright (c) 2003, OpenBeOS
5 // This software is part of the OpenBeOS distribution and is covered
6 // by the OpenBeOS license.
10 // Author: Santiago (Jacques) Lema
11 // Description: sends an e-mail from the command-line
12 // Created : May 23, 2003
13 // Modified by: Jérome Duval
15 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
18 #include <Application.h>
22 #define APP_SIG "application/x-vnd.OBos-cmd-mail"
24 int main( int argc
, char* argv
[] )
26 BApplication
mailApp(APP_SIG
);
28 // No arguments, show usage
30 fprintf(stdout
,"[OBOS-mail] Sorry: This program can only send mail, not read it.\n");
31 fprintf(stdout
,"usage: /bin/mail [-v] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr ...\n");
36 char *subject
= "No title";
44 for (int i
=1; i
<argc
; i
++) {
45 if (strcmp (argv
[i
], "-v") == 0)
47 else if (strcmp(argv
[i
], "-s") == 0) {
50 } else if (strcmp(argv
[i
], "-c") == 0) {
53 } else if (strcmp(argv
[i
], "-b") == 0) {
65 fprintf(stdout
,"To:\t<%s> \n",to
.String());
66 fprintf(stdout
,"Cc:\t<%s> \n",cc
);
67 fprintf(stdout
,"Bcc:\t<%s> \n",bcc
);
68 fprintf(stdout
,"Subj:\t<%s> \n",subject
);
69 fprintf(stdout
,"Body:\t<%s> \n",body
.String());
73 //check if valid recipients
74 if (strcmp(to
.String(), "") == 0
75 && strcmp(cc
, "") == 0
76 && strcmp(bcc
, "") == 0) {
79 "[Error]\nYou must specify at least one recipient in to,cc or bcc fields.\n");
83 //read each line until we get a single dot "." on a line
84 char line
[32768] = "";
86 printf("Now type your message.\nType '.' alone on a line to send it.\n");
90 if (strcmp(line
, ".") != 0) {
91 body
.Append(line
).Append("\n");
93 //fprintf(stdout,"Line: %s \n",line);
94 } while (strcmp(line
, ".") != 0);
98 fprintf(stdout
, "\nBody:\n%s\n", body
.String());
101 fprintf(stdout
, "\nSending E-mail...\n");
107 mail
.AddHeaderField(B_MAIL_TO
, to
.String());
108 mail
.AddHeaderField(B_MAIL_CC
, cc
);
109 mail
.AddHeaderField(B_MAIL_BCC
, bcc
);
110 mail
.AddHeaderField(B_MAIL_SUBJECT
, subject
);
111 mail
.AddContent(body
.String(),strlen(body
.String()));
112 status_t result
= mail
.Send();
115 fprintf(stdout
, "\nMessage was sent successfully.\n");