/* count the messages in a mailbox */ static void countMessages(Pop3 pc, const char *mbox_filename) { FILE *F; char buf[BUF_SIZE]; int is_header = 0; int next_from_is_start_of_header = 1; int count_from = 0, count_status = 0; int len_from = strlen(FROM_STR), len_status = strlen(STATUS_STR); int pseudo_mail = 0; F = openMailbox(pc, mbox_filename); if (F == NULL) return; /* count message */ while (fgets(buf, BUF_SIZE, F)) { // The first message usually is automatically created by POP3/IMAP // clients for internal record keeping and is ignored // (not displayed) by most email clients. if (is_header && !strncmp(buf, "X-IMAP: ", 8)) { pseudo_mail = 1; } if (buf[0] == '\n') { /* a newline by itself terminates the header */ if (is_header) is_header = 0; else next_from_is_start_of_header = 1; } else if (!strncmp(buf, FROM_STR, len_from)) { /* A line starting with "From" is the beginning of a new header. "From" in the text of the mail should get escaped by the MDA. If your MDA doesn't do that, it is broken. */ if (next_from_is_start_of_header) is_header = 1; if (is_header) count_from++; } else { next_from_is_start_of_header = 0; if (is_header && !strncmp(buf, STATUS_STR, len_status) && strrchr(buf, 'R')) { count_status++; } } } if (count_from && pseudo_mail) { count_from--; if (count_status) count_status--; } DM(pc, DEBUG_INFO, "from: %d status: %d\n", count_from, count_status); pc->TotalMsgs = count_from; pc->UnreadMsgs = count_from - count_status; fclose(F); }
void VoiceboxDialog::doMailboxStart() { openMailbox(); doListOverview(); if (new_msgs.empty() && saved_msgs.empty()) { state = Bye; } else { enqueueCurMessage(); } }
int main(int argc, char *argv[]) { int pid = -1; //PID float temp = 0; //inital temperature from command line float downTemp = 0; float parentTemp = 0; float upTemp = 0; //parses command line arguments and updates pid and initial temperature/exits on fail if(!getArgumentValues(parseArguments(argc, argv), pid, temp)) exit(0); mqd_t mqueue; /*message queue*/ mqd_t parent; mqd_t child_1; mqd_t child_2; struct mq_attr ma; ma.mq_flags = 0; ma.mq_maxmsg = 10; ma.mq_msgsize = 33; ma.mq_curmsgs = 0; float child1Value; float child2Value; //sendFloat(mqueue, temp); //qout << receiveFloat(mqueue); //mq_close(mqueue); //mq_unlink(P0); switch(pid){ case 0: { mqueue = openMailbox(P0, ma); child_1 = openMailbox(P1, ma); child_2 = openMailbox(P2, ma); sendFloat(child_1, temp, 0.0); //false flags as sent down sendFloat(child_2, temp, 0.0); break; } case 1: parent = openMailbox(P0, ma); mqueue = openMailbox(P1, ma); child_1 = openMailbox(P3, ma); child_2 = openMailbox(P4, ma); break; case 2: parent = openMailbox(P0, ma); mqueue = openMailbox(P2, ma); child_1 = openMailbox(P5, ma); child_2 = openMailbox(P6, ma); break; case 3: parent = openMailbox(P1, ma); mqueue = openMailbox(P3, ma); break; case 4: parent = openMailbox(P1, ma); mqueue = openMailbox(P4, ma); break; case 5: parent = openMailbox(P2, ma); mqueue = openMailbox(P5, ma); break; case 6: parent = openMailbox(P2, ma); mqueue = openMailbox(P6, ma); break; } bool isStable = false; while(!isStable) { if(pid == 0) { if(numMessages(mqueue) > 1) { float cPid = 10; float c2Pid = 10; float child1Value = receiveFloat(mqueue, cPid); float child2Value = receiveFloat(mqueue, c2Pid); upTemp = (temp + child1Value + child2Value)/3.0; qout << "Process " << pid << " current temperature " << upTemp << endl; if(qAbs(upTemp - temp) <= .01) { temp = upTemp; isStable = true; sendFloat(child_1, temp, 20); sendFloat(child_2, temp, 20); } else { temp = upTemp; sendFloat(child_1, temp, pid); sendFloat(child_2, temp, pid); } } } if(pid == 1 || pid == 2) { if(hasMessages(mqueue)) { float rPid = 10; float value = receiveFloat(mqueue, rPid); if(rPid == 20) { isStable = true; sendFloat(child_1, temp, 20); sendFloat(child_1, temp, 20); } else if(rPid == 0) { float downTemp = (temp + value)/2.0; temp = downTemp; sendFloat(child_1, downTemp, pid); sendFloat(child_2, downTemp, pid); } else if(rPid == 3 || rPid == 4 || rPid == 5 || rPid == 6) { float child1_value = value; float sPid = 10; float child2_value = receiveFloat(mqueue, sPid); if(sPid == 3 || sPid == 4 || sPid == 5 || sPid == 6) { upTemp = (temp + child1_value + child2_value)/3.0; temp = upTemp; qout << "Process " << pid << " current temperature " << upTemp << endl; sendFloat(parent, upTemp, pid); } } } } if(pid == 3 || pid == 4 || pid == 5 || pid ==6) { if(hasMessages(mqueue)) { float rPid; parentTemp = receiveFloat(mqueue, rPid); if(rPid == 20) { isStable = true; } else { downTemp = (temp + parentTemp)/2.0; temp = downTemp; sendFloat(parent, downTemp, pid); //true flags it as sent up qout << "Process " << pid << " current temperature " << downTemp << endl; } } } } qout << "Process " << pid << " final temperature " << temp << endl; mq_close(parent); mq_close(child_1); mq_close(child_2); mq_close(mqueue); mq_unlink(P0); mq_unlink(P1); mq_unlink(P2); mq_unlink(P3); mq_unlink(P4); mq_unlink(P5); mq_unlink(P6); return 0; } /*end main()*/