SDK Script sms-to-email.are

sms-to-email.are
/* DESC: This script will forward incoming SMS messages to a given E-mail address.
 * Copyright (C) 2012 NetModule AG, Switzerland
 */
 
 
if (argc < 1 || strlen(argv[1]) == 0) {
    printf("usage: sms-to-email.are <email-rcpt>");
    exit(1);
}
 
rcpt = argv[1];
 
while(1) {
    msgs = nb_sms_list();
    nr_msgs = length(msgs);
 
    if (nr_msgs == 0) {
        sleep(10);
        continue;
    }
 
    for (i=0; i<nr_msgs; i++) {
        msg = nb_sms_retrieve(msgs[i]);
        if (!msg) continue;
 
        nb_syslog("processing message %d of %d (ID %s)",
                   i, nr_msgs, msgs[i]);
 
        subject = "SMS received";
        body = nb_sms_body(msgs[i]);
        sprintf(body, "%s\n", msg);
 
        if (nb_email_send(rcpt, subject, body) != 0) {
            printf("unable to send e-mail\n");
        } else {
            printf("successfully sent e-mail\n");
            nb_sms_delete(msgs[i]);
        }
    }
}
 
exit(0);