> Marko wrote:
>
> Najprej pozdravljam vse udeležence
>
> Imam eno zanimivo vprašanje...je mogoče že kdo napisu kakšno skripto
> za linux sistem, ki bi ob prispetju novega maila prebrala Zadevo oz.
> Subject sporočila ter ga posredoval preko SMS na GSM telefon.
>
> Vsaka pomoč oz. celo skripta ;-) bo dobrodošla.
>
> Lep pozdrav
> Marko
Jaz uporabljam en moj proggy (malo sem ga pokomentiral):
/* Mail 2 GSM sender with subject exclusion */
/* Quick And Dirty code by Aky */
#include <stdio.h>
#include <unistd.h>
#include <strings.h>
/* Tukaj vpises poti do datotek: */
/*
Vse besede, ki se nahajajo v tem fajlu, vsaka v svoji vrsti; ce se
pojavijo v subjectu se ta mail ne bo forwardiral na SMS
*/
#define RCFILE "/home/aky/gsm/pmfilter.rc"
// Kam naj zmece napake
#define ERRLOGFILE "/home/aky/gsm/error.log"
// Klasicni logfile
#define LOGFILE "/home/aky/gsm/sent.log"
// Stevilka tvojega GSMa
#define GSMNUM "041xxxxxx"
// najvecje stevilo vrstic v RCFILE
char *Excludes[100];
int IsInSubject(char *line, char *what){
int i, len, wlen, x;
len=strlen(line);
wlen=strlen(what);
if (len<wlen) return 0;
i=0;
while (i<=(len-wlen)){
if (!strncmp(line, what, wlen)) return 1;
line++; i++;
}
return 0;
}
char *SaveSubject(char *line){
char buff[255];
int i, len;
line+=8;
if (line[0]==' ') line++;
len=strlen(line)-1;
i=0;
while (i<=len)
buff[i]=line[i++];
buff[i]='\0';
return strdup(buff);
}
char *SaveFrom(char *line){
char buff[255];
int i, len;
line+=5;
if (line[0]==' ') line++;
len=strlen(line)-1;
i=0;
while (i<=len)
buff[i]=line[i++];
buff[i]='\0';
return strdup(buff);
}
void ErrLog(char *line){
FILE *logf;
logf=fopen(ERRLOGFILE, "a");
fprintf(logf, line);
fclose(logf);
}
void Log(char *line){
FILE *logf;
logf=fopen(LOGFILE, "a");
fprintf(logf, line);
fclose(logf);
}
int ReadConfig(){
FILE *cnf;
int i, j;
char line[1023];
if ((cnf=fopen(RCFILE, "r"))==NULL){
Log("Can not open config file.\n");
exit(1);
}
i=0;
while ((fgets(line, 1023, cnf))!=NULL){
line[strlen(line)-1]='\0';
Excludes[i++]=(char *)strdup(line);
}
return i;
}
void main(){
char line[1023], *subject, *from;
int sbj=0, i, ncnf;
char cmdstr[1023], DATUM[255], ToLog[1023];
FILE *dateproc;
ncnf=ReadConfig();
while (gets(line)!=NULL){
if (!strncasecmp(line, "from:", 5))
from=SaveFrom(line);
if (!strncasecmp(line, "subject:", 8)){
subject=SaveSubject(line);
for (i=0; i<ncnf; i++)
if (IsInSubject(line, Excludes[i])) sbj=1;
}
}
if (sbj==0){
if (strlen(subject)<3) exit(0);
sprintf(ToLog, "Subject: %s\nFrom: %s\n", subject, from);
ToLog[160]='\0';
sprintf(cmdstr, "echo \"%s\" | /bin/mail -s SMS
[EMAIL PROTECTED]", ToLog, GSMNUM);
system(cmdstr);
dateproc=popen("/bin/date +\"%T; %d %h %Y\"", "r");
fgets(DATUM, 255, dateproc);
pclose(dateproc);
DATUM[strlen(DATUM)-1]='\0';
sprintf(ToLog, "SMS From: %s [%s], Msg: %s\n", from, DATUM,
subject);
Log(ToLog);
}
}
Bye,
A.