TheFarSide
11-06-2002, 10:09 AM
Since I've been taking classes for a whole 5 weeks now with C++, I've been designated to create an application here for work (ugh).
Basically, as an email hits our mail server, Declude software checks it for a virus, and also assigns a weight to the email, depending on how much it thinks it's a spam email. Anything above a weight of 20 gets set to the side to be hand pushed or deleted by us, and repeat offenders get put on the mail server blacklist.
This gets tedious.
So this program is basically invoked on a command line (in an NT environment), with variables being passed to it as command line arguments.
(EDIT: an example of how this will be called -
c:\program.exe 50 chansen@continentaloffice.com )
Hopefully this paste doesn't get mangled too much. This is what I have so far, which does most of what I need it to, with the exception of two things.
1. If blacklist.txt is not there, it needs to be able to create it.
2. This program gets run hundreds of times a day, and each time needs to seek the end of blacklist.txt and start the output there.
Neither of these things are addressed in my text, nor have I found anything in my limited net searching.
/*
*****************************************************
* Author- : Cameron Hansen
*
* Program- : Taking two variables from a command line
* : argument for an email blacklist. The
* : first variable is the weight sent from
* : the scanning software. If the weight is
* : higher than 20, add the email (second
* : variable) to the text file. The command
* : line syntax is:
* : "c:\program.exe weight email_address"
*
*
* Created : 11/05/02
*
* Modified : 11/06/02 - Altered the array conversion
* : for argv[1] to accept up to 3 digits
* : instead of two.
*
****************************************************
*/
#include <iostream>
#include <string> // Eventually for working with argv[2]
#include <fstream> // For file I/O
using std::cin;
using std::cout;
using std::endl;
// The total number of arguments (counting the program name)
// is stored into argc, while each argument is stored in the
// array, argv.
int main(int argc, char *argv[])
{
int i;
int j;
int k;
int m;
// Check to see if the correct number of variables are
// being sent. If not, end the program.
if(argc != 3)
{
return 0;
}
else
{
// Check to see if it's a 3 digit number
if (argv[1][2]==0)
{
// If not, check to see if it's a 2 digit number
if (argv[1][1]==0)
{
// If not, convert to an int from acsii
i = argv[1][0] - 48;
j = 0;
k = i;
}
// If it's a 2 digit number, convert it to an int
else
{
j = argv[1][0] - 48;
m = argv[1][1] - 48;
k = (j * 10) + m;
}
}
// If it's a 3 digit number, conver it to an int
else
{
i = argv[1][0] - 48;
j = argv[1][1] - 48;
m = argv[1][2] - 48;
k = (i * 100) + (j * 10) + m;
}
// Open blacklist.txt
ofstream BlackList;
BlackList.open("blacklist.txt");
// If the email weight is higher than 20, put them on the blacklist
if (k > 20)
{
BlackList << k << argv[2] << endl;
}
// Close blacklist.txt
BlackList.close();
}
}
EDIT: Looks like only the comments at the start got mushed, hooray.
Basically, as an email hits our mail server, Declude software checks it for a virus, and also assigns a weight to the email, depending on how much it thinks it's a spam email. Anything above a weight of 20 gets set to the side to be hand pushed or deleted by us, and repeat offenders get put on the mail server blacklist.
This gets tedious.
So this program is basically invoked on a command line (in an NT environment), with variables being passed to it as command line arguments.
(EDIT: an example of how this will be called -
c:\program.exe 50 chansen@continentaloffice.com )
Hopefully this paste doesn't get mangled too much. This is what I have so far, which does most of what I need it to, with the exception of two things.
1. If blacklist.txt is not there, it needs to be able to create it.
2. This program gets run hundreds of times a day, and each time needs to seek the end of blacklist.txt and start the output there.
Neither of these things are addressed in my text, nor have I found anything in my limited net searching.
/*
*****************************************************
* Author- : Cameron Hansen
*
* Program- : Taking two variables from a command line
* : argument for an email blacklist. The
* : first variable is the weight sent from
* : the scanning software. If the weight is
* : higher than 20, add the email (second
* : variable) to the text file. The command
* : line syntax is:
* : "c:\program.exe weight email_address"
*
*
* Created : 11/05/02
*
* Modified : 11/06/02 - Altered the array conversion
* : for argv[1] to accept up to 3 digits
* : instead of two.
*
****************************************************
*/
#include <iostream>
#include <string> // Eventually for working with argv[2]
#include <fstream> // For file I/O
using std::cin;
using std::cout;
using std::endl;
// The total number of arguments (counting the program name)
// is stored into argc, while each argument is stored in the
// array, argv.
int main(int argc, char *argv[])
{
int i;
int j;
int k;
int m;
// Check to see if the correct number of variables are
// being sent. If not, end the program.
if(argc != 3)
{
return 0;
}
else
{
// Check to see if it's a 3 digit number
if (argv[1][2]==0)
{
// If not, check to see if it's a 2 digit number
if (argv[1][1]==0)
{
// If not, convert to an int from acsii
i = argv[1][0] - 48;
j = 0;
k = i;
}
// If it's a 2 digit number, convert it to an int
else
{
j = argv[1][0] - 48;
m = argv[1][1] - 48;
k = (j * 10) + m;
}
}
// If it's a 3 digit number, conver it to an int
else
{
i = argv[1][0] - 48;
j = argv[1][1] - 48;
m = argv[1][2] - 48;
k = (i * 100) + (j * 10) + m;
}
// Open blacklist.txt
ofstream BlackList;
BlackList.open("blacklist.txt");
// If the email weight is higher than 20, put them on the blacklist
if (k > 20)
{
BlackList << k << argv[2] << endl;
}
// Close blacklist.txt
BlackList.close();
}
}
EDIT: Looks like only the comments at the start got mushed, hooray.