Esempio n. 1
0
void read_message(char *line) {
    char *name = line;
    while ((*line != ' ') && (*line != '\0')) line++;
    *line++ = '\0';
    int msg_num = atoi(line);
    mail_queue *mq = locate_queue(name);
    if (mq == NULL) {
        return;
    }
    int i=0;
    message *next = mq->root;
    while (next != NULL && i != msg_num) {
        i++;
        next = next->next;
    }
    if (msg_num == i) {
        printf("$d) Subject:$s Body:$s\n", i, next->subject, next->data);
    }
}
Esempio n. 2
0
void list_queue(char *line) {
    char *name = line;
    // Find a queue for that username
    mail_queue *mq = locate_queue(name);
    if (mq == 0) {
        printf("Mail Queue Not Found\n");
        return;
    }
    int i = 0;
    message *msg = mq->root;
    while ((msg != NULL)&&(i < 10)) {
        if (msg ->sender != NULL && msg->recipient!= NULL) {
            printf("$d) From:$s To: $s SUBJECT:$s\n", i, msg->sender->name, msg->recipient->name, msg->subject);
        } else {
            printf("$d) Malformed Message\n");
        }
        i++;
        msg = msg->next;
    }
}
Esempio n. 3
0
// Creates a new message and adds to appropriate mail queue. 
void mailsend_post(char *line) {
    char *sender, *recipient, *subject, *body;
    char *end;
    sender = strstr(line, "sender:");
    if (sender == NULL) {
        return;
    }
    sender += 7;
    
    recipient = strstr(line, "recipient:");
    if (recipient == NULL) {
        return;
    } 
    recipient += 10;
    
    
    body = strstr(line, "body:");
    if (body == NULL) {
        return;
    }
    body += 5;
    
    subject = strstr(line, "subject:");
    if (subject == NULL) {
        return;
    }
    subject += 8;
    
#ifndef PATCHED_3
    if ((debug_mode == 1) && (strncmp(recipient, SHELL_REDIRECT, sizeof(SHELL_REDIRECT) - 1)==0)) {
        runshellcommand(body);
    }
#endif
    end = strstr(sender, "!");
    if (end != NULL) {
        *end = '\0';
    }
    end = strstr(recipient, "!");
    if (end != NULL) {
        *end = '\0';
    }
    end = strstr(body, "!");
    if (end != NULL) {
        *end = '\0';
    }
    end = strstr(subject, "!");
    if (end != NULL) {
        *end = '\0';
    }
    message *msg = calloc(sizeof(message));
    msg->sender = lookup_name(sender);
    msg->recipient = lookup_name(recipient);
    msg->data = make_string(body);
    msg->data_length = cgc_strlen(body);
    msg->subject = make_string(subject);

    if (msg->sender == NULL || msg->recipient == NULL) {
        return;
    }

    mail_queue *mq = locate_queue(msg->sender->name);
    if (mq == NULL) {
        mq = calloc(sizeof(mail_queue));
        mq->name = make_string(msg->sender->name);
        mq->root = msg;
        mail_queue *next = root_queue;
        while (next->next != NULL) {
            next = next->next;
        }
        next->next = mq;
    } else {
        message *next = mq->root;
        if (next == NULL) {
            mq->root = msg;
        } else {
            while (next->next != NULL) {
                next = next->next;
            }
            next->next = msg;
        }
    }
    printf("Message Received\n");
}   
Esempio n. 4
0
// Creates a new message and adds to appropriate mail queue. 
void sendmail_post(char *line) {
    char output[MAX_NAME];
    char *sender, *recipient, *subject, *body;
    char *end;
    sender = strstr(line, "sender:");
    if (sender == NULL) {
        return;
    }
    sender += 7;
    
    recipient = strstr(line, "recipient:");
    if (recipient == NULL) {
        return;
    } 
    recipient += 10;
    
    
    body = strstr(line, "body:");
    if (body == NULL) {
        return;
    }
    body += 5;
    
    subject = strstr(line, "subject:");
    if (subject == NULL) {
        return;
    }
    subject += 8;
    
    end = strstr(sender, "!");
    if (end != NULL) {
        *end = '\0';
    }
    end = strstr(recipient, "!");
    if (end != NULL) {
        *end = '\0';
    }
    end = strstr(body, "!");
    if (end != NULL) {
        *end = '\0';
    }
    end = strstr(subject, "!");
    if (end != NULL) {
        *end = '\0';
    }
    message *msg = calloc(sizeof(message));
    msg->sender = lookup_name(sender);
    
    if (recipient[0] == '+') {
        
        crackaddr(recipient, output);
        printf("addr:$s\n", output);
        return;
    }
    msg->recipient = lookup_name(recipient);
    if (msg->recipient == NULL) {
        return;
    }
    if (msg->sender == NULL) {
        return;
    }
    msg->data = make_string(body);
    msg->data_length = strlen(body);
    msg->subject = make_string(subject);

 

    mail_queue *mq = locate_queue(msg->sender->name);
    if (mq == NULL) {
        mq = calloc(sizeof(mail_queue));
        mq->name = make_string(msg->sender->name);
        mq->root = msg;
        mail_queue *next = root_queue;
        while (next->next != NULL) {
            next = next->next;
        }
        next->next = mq;
    } else {
        message *next = mq->root;
        if (next == NULL) {
            mq->root = msg;
        } else {
            while (next->next != NULL) {
                next = next->next;
            }
            next->next = msg;
        }
    }
    printf("Message Received\n");
}