home *** CD-ROM | disk | FTP | other *** search
- #include "defs.h"
-
- extern char *FileNameToNewsGroup (char *filename);
- extern char *NewsGroupToFileName (char *newsgroup);
-
- static LIST msgList;
-
- ART *currentArticle;
-
- /************************************************************************/
-
- /*
- * As each gadget in the GadDefs array above is created, it is assigned a UserID
- * field value, incremented from zero. The following defines are useful for switch
- * statements, etc. Enum would also work. Be careful, if you add new gadgets in
- * the middle of the initializations above, because you will need to renumber these
- * defines.
- */
- static enum GADGET_IDS {
- ARTLIST_ID,
- HIDEHEADERS_ID,
- HIDEREAD_ID,
- SORT_ID,
- QUIT_ID,
- PREV_ID,
- NEXT_ID,
- NEXTUNREAD_ID,
- NEXTTHREAD_ID,
- CATCHUP_ID,
- PREVGROUP_ID,
- NEXTGROUP_ID,
- FROM_ID,
- ORGANIZATION_ID,
- DATE_ID,
- SUBJECT_ID,
- MSGLIST_ID,
- STATUS_ID,
- SAVE_ID,
- REPLY_ID,
- FORWARD_ID,
- FOLLOWUP_ID,
- POST_ID,
- PRINT_ID,
- MAXGADGET,
- };
-
- static GADGET *gadgetArray[MAXGADGET];
-
- static char *sortLabels[] = { "Number", "From", "Subject", 0 };
-
- static short viewHeight; // height of MSGLIST listview in character lines
- static short viewTop = 0; // top line of MSGLIST view (for GTLV_Top pagedown
- static short messageLines = 0; // number of lines in message
-
- /*
- * Misc tags arrays
- */
- static TAGS nullTags[] = { GT_Underscore, '_', TAG_DONE,0 };
- static TAGS disableTags[] = { GT_Underscore, '_', GA_Disabled,TRUE, TAG_DONE,0 };
- static TAGS enableTags[] = { GT_Underscore, '_', GA_Disabled,FALSE, TAG_DONE,0 };
-
- static TAGS sortTags[] = {
- GT_Underscore, '_',
- GTCY_Labels, &sortLabels[0],
- GTCY_Active, 0,
- TAG_DONE, 0,
- };
-
- static TAGS artListTags[] = {
- GT_Underscore, '_',
- GTLV_Top, 0,
- GTLV_Labels, 0,
- GTLV_ReadOnly, FALSE,
- GTLV_ScrollWidth, 16,
- #ifdef MYKE_REMOVED_THIS
- GTLV_ShowSelected, NULL,
- #endif
- GTBB_Recessed, FALSE,
- TAG_DONE, 0,
- };
-
- static TAGS msgListTags[] = {
- GT_Underscore, '_',
- GTLV_Top, 0,
- GTLV_Labels, &msgList,
- GTLV_ReadOnly, TRUE,
- GTLV_ScrollWidth, 16,
- GTBB_Recessed, TRUE,
- TAG_DONE, 0,
- };
-
- static char *nullText = "";
- static TAGS textTags[] = {
- GT_Underscore, '_',
- GTTX_Text, (ULONG)"",
- GTTX_CopyText, TRUE,
- GTTX_Border, TRUE,
- TAG_DONE, 0,
- };
-
- /*
- * The Array of Gadget definitions. To create a new gadget, add an initializer
- * here, and create the necessary tags...
- */
- static GADDEF gadDefs[] = {
- artListTags, LISTVIEW_KIND,0,0,0,0, NG_HIGHLABEL, "",
- nullTags, CHECKBOX_KIND, 0,0,0,0, NG_HIGHLABEL, "Hide Headers:",
- disableTags, CHECKBOX_KIND, 0,0,0,0, NG_HIGHLABEL, "Hide Read Messages:",
- sortTags, CYCLE_KIND, 0,0,0,0, NG_HIGHLABEL, "Sort By:",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "_Groups",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "_prev",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "_next",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "_unread",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "_thread",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "_Catch up",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "_Prev Group",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "_Next Group",
- textTags, TEXT_KIND, 0,0,0,0, NG_HIGHLABEL, "From:",
- textTags, TEXT_KIND, 0,0,0,0, NG_HIGHLABEL, "Org:",
- textTags, TEXT_KIND, 0,0,0,0, NG_HIGHLABEL, "Date:",
- textTags, TEXT_KIND, 0,0,0,0, NG_HIGHLABEL, "Subj:",
- msgListTags, LISTVIEW_KIND, 0,0,0,0, NG_HIGHLABEL, "",
- textTags, TEXT_KIND, 0,0,0,0, NG_HIGHLABEL, "",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "_Save",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "_Reply",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "Forward",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "_FollowUp",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "Post",
- enableTags, BUTTON_KIND, 0,0,0,0, NG_HIGHLABEL, "Print",
- 0,0,0,0,0,0,0,0,
- };
-
- static GADGET *gList = 0;
-
- static void LayoutGadgets(font,width,height,top)
- FONT *font;
- short width,height,top;
- {
- short i, x,y, fh, lh;
- RPORT rPort, *rp = &rPort;
-
- InitRastPort(rp);
- SetFont(rp, font);
- y = top+INTERHEIGHT/2;
-
- lh = (windowHeight/50);
- if (lh > 10) lh = 10;
- fh = rp->TxHeight+2;
- gadDefs[ARTLIST_ID].left = INTERWIDTH;
- gadDefs[ARTLIST_ID].top = y;
- gadDefs[ARTLIST_ID].width = width-INTERWIDTH-INTERWIDTH;
- gadDefs[ARTLIST_ID].height = lh*fh+INTERHEIGHT;
- y += lh*fh+INTERHEIGHT+2;
-
- fh = topazRP->TxHeight+2;
- x = INTERWIDTH;
- gadDefs[HIDEHEADERS_ID].left = x + TextLen(topazRP, gadDefs[HIDEHEADERS_ID].text)+20;
- gadDefs[HIDEHEADERS_ID].top = y;
- gadDefs[HIDEHEADERS_ID].width = 12;
- gadDefs[HIDEHEADERS_ID].height = fh+2;
- x = gadDefs[HIDEHEADERS_ID].left + gadDefs[HIDEHEADERS_ID].width + INTERWIDTH;
-
- gadDefs[HIDEREAD_ID].left = x + TextLen(topazRP, gadDefs[HIDEREAD_ID].text)+20;
- gadDefs[HIDEREAD_ID].top = y;
- gadDefs[HIDEREAD_ID].width = 12;
- gadDefs[HIDEREAD_ID].height = fh+2;
- x = gadDefs[HIDEREAD_ID].left + gadDefs[HIDEREAD_ID].width + INTERWIDTH;
-
- gadDefs[SORT_ID].left = x + TextLen(topazRP, gadDefs[SORT_ID].text)+20;
- gadDefs[SORT_ID].top = y;
- gadDefs[SORT_ID].width = TextLen(topazRP, "Subject")+24;
- gadDefs[SORT_ID].height = fh+2;
- x = gadDefs[SORT_ID].left + gadDefs[SORT_ID].width + INTERWIDTH;
-
- y += fh+4;
-
- x = INTERWIDTH;
- for (i=QUIT_ID; i<=NEXTGROUP_ID; i++) {
- gadDefs[i].left = x;
- gadDefs[i].top = y;
- gadDefs[i].width = TextLen(topazRP, gadDefs[i].text)+4;
- gadDefs[i].height = fh+4;
- x += gadDefs[i].width + INTERWIDTH;
- }
-
- y += fh+4+INTERHEIGHT;
-
- for (i=FROM_ID; i<=SUBJECT_ID; i++) {
- gadDefs[i].left = INTERWIDTH+48;
- gadDefs[i].top = y;
- gadDefs[i].width = width - 48-INTERWIDTH-INTERWIDTH;
- gadDefs[i].height = fh+2;
- y += fh+INTERHEIGHT;
- }
-
- fh = rp->TxHeight+2;
- gadDefs[MSGLIST_ID].left = INTERWIDTH;
- gadDefs[MSGLIST_ID].top = y;
- gadDefs[MSGLIST_ID].width = width-INTERWIDTH-INTERWIDTH;
- gadDefs[MSGLIST_ID].height = height-y-fh-fh-INTERHEIGHT-INTERHEIGHT;
- y += gadDefs[MSGLIST_ID].height;
-
- fh = topazRP->TxHeight+2;
- viewHeight = gadDefs[MSGLIST_ID].height/fh;
- gadDefs[STATUS_ID].left = INTERWIDTH;
- gadDefs[STATUS_ID].top = y;
- gadDefs[STATUS_ID].width = width-INTERWIDTH-INTERWIDTH;
- gadDefs[STATUS_ID].height = fh+2;
- y += fh+4;
-
- x = INTERWIDTH;
- for (i=SAVE_ID; i<=PRINT_ID; i++) {
- gadDefs[i].left = x;
- gadDefs[i].top = y;
- gadDefs[i].width = TextLen(topazRP, gadDefs[i].text)+4;
- gadDefs[i].height = fh+2;
- x += gadDefs[i].width+INTERWIDTH;
- }
- y += fh+4;
- }
-
- /************************************************************************/
-
- void CloseArticles() {
- if (!gList) return;
- if (RemoveGList(mainWindow, gList, -1) == -1) {
- printf("RemoveGList() failed\n");
- return;
- }
- FreeGadgets(gList);
- gList = 0;
- ClearWindow();
- RefreshGList(mainWindow->FirstGadget, mainWindow, 0, -1);
- GT_RefreshWindow(mainWindow, NULL);
- }
-
- /************************************************************************/
-
- GLIST *NextGroup() {
- GLIST *gp = currentGroup;
-
- do {
- if (groupList.lh_TailPred == (NODE *)gp)
- gp = (GLIST *)groupList.lh_Head;
- else
- gp = (GLIST *)gp->node.ln_Succ;
- } while (!gp->articles && gp != currentGroup);
- return gp;
- }
-
- GLIST *PrevGroup() {
- GLIST *gp = currentGroup;
-
- do {
- if (groupList.lh_Head == (NODE *)gp)
- gp = (GLIST *)groupList.lh_TailPred;
- else
- gp = (GLIST *)gp->node.ln_Pred;
- } while (!gp->articles && gp != currentGroup);
- return gp;
- }
-
- void SortArticles() {
- switch (currentGroup->sortActive) {
- case 0: SortArticlesByNumber(¤tGroup->artList); break;
- case 1: SortArticlesByFrom(¤tGroup->artList); break;
- case 2: SortArticlesBySubject(¤tGroup->artList); break;
- }
- }
-
- void Save(void) {
- ART *ap = currentArticle;
- char temp[256], work[256];
- char filename[256];
- FILE *fp, *outfp;
- int fd;
- ULONG size, count = 0, pct;
-
- if (!AslRequestTags(saveReq, TAG_DONE)) return;
- strcpy(filename, saveReq->rf_Dir);
- AddPart(filename, saveReq->rf_File, 256);
-
- strcpy(temp, uunews);
- AddPart(temp, NewsGroupToFileName (currentGroup->groupName), 256);
- sprintf(work, "%d", ap->filenum);
- AddPart(temp, work, 256);
-
- fd = open(temp, O_READ);
- if (fd == -1) return;
- size = lseek(fd, 0, 2); lseek(fd, 0, 0);
- close(fd);
- fp = fopen(temp, "r");
- if (!fp) return;
- outfp = fopen(filename, "w");
- if (!outfp) { fclose(fp); return; }
- while (fgets(temp, 256, fp)) {
- count += strlen(temp);
- pct = 100*count/size;
- if (GuageRequest(pct,"GRn - Please Wait...", " Saving ", "Abort")) break;
- fprintf(outfp, "%s", temp);
- }
- GuageRequest(1000,"GRn - Please Wait...", " Saving ", "Abort");
- fclose(outfp); fclose(fp);
- }
-
- void Print(void) {
- ART *ap = currentArticle;
- char temp[256], work[256];
- FILE *fp, *outfp;
- int fd;
- ULONG size, count = 0, pct;
-
- strcpy(temp, uunews);
- AddPart(temp, NewsGroupToFileName (currentGroup->groupName), 256);
- sprintf(work, "%d", ap->filenum);
- AddPart(temp, work, 256);
-
- fd = open(temp, O_READ);
- if (fd == -1) return;
- size = lseek(fd, 0, 2); lseek(fd, 0, 0);
- close(fd);
- fp = fopen(temp, "r");
- if (!fp) return;
- outfp = fopen("prt:", "w");
- if (!outfp) { fclose(fp); return; }
- while (fgets(temp, 256, fp)) {
- count += strlen(temp);
- pct = 100*count/size;
- if (GuageRequest(pct,"GRn - Please Wait...", " Printing ", "Abort")) break;
- fprintf(outfp, temp);
- }
- GuageRequest(1000,"GRn - Please Wait...", " Printing ", "Abort");
- fprintf(outfp, "%c", 12);
- fclose(outfp); fclose(fp);
- }
-
- void ExpandTabs(char *buf) {
- short col = 0;
- static char work [512]; /* static for efficiency on entry */
- char *pd = &work[0], *ps = buf;
-
- while (1) {
- switch (*ps) {
- case '\t': do {
- *pd++ = ' '; col++;
- } while ((col%8) && col < 510);
- ps++;
- if (col >= 510) {
- *pd++ = '\0';
- strcpy(buf, work);
- return;
- }
- break;
- case '\0': *pd++ = '\0';
- strcpy(buf, work);
- return;
- default: *pd++ = *ps++; col++; break;
- }
- }
- }
-
- void ShowMessage(ART *ap) {
- FILE *fp;
- char temp[512], work[512], *ps;
- NODE *np;
- GLIST *gp;
- BOOL headerDone = 0;
- BOOL flag = !0;
- static char artStatus[256], org[512], date[512];
- short len;
- int found_date; /* found the Date: header */
- int found_org; /* found the Organization: header */
-
- messageLines = 0;
- if (currentArticle == ap) flag = 0;
- currentArticle = ap;
- GT_SetGadgetAttrs(gadgetArray[MSGLIST_ID], mainWindow, NULL, GTLV_Labels, ~0, TAG_DONE);
- FreeListNodes(&msgList, TRUE);
-
- strcpy(temp, uunews);
- AddPart(temp, NewsGroupToFileName (currentGroup->groupName), 512);
- sprintf(work, "%d", ap->filenum);
- AddPart(temp, work, 512);
-
- NewList(&msgList);
- fp = fopen(temp, "r");
- if (!fp) {
- t_printf ("Couldn't open '%s' (group = '%s', number = %d)\n",
- temp, currentGroup->groupName, ap->filenum);
- return;
- }
- org[0] = '\0';
- found_date = found_org = 0;
- while (fgets(temp, 512, fp)) {
- temp[strlen(temp)-1] = '\0'; /* trim trailing newline */
- ExpandTabs(temp);
-
- /* Note: Headers ARE case sensitive per RFC. */
- if (!headerDone && (found_date == 0 || found_org == 0)) {
- /* stop looking when the headers are gone */
- if (!strncmp (temp, "Date: ", 6)) {
- strcpy(date, &temp [6]);
- found_date = 1;
- }
- else
- if (!strncmp (temp, "Organization: ", 14)) {
- strcpy (org, &temp [14]);
- found_org = 1;
- }
- }
- if (temp [0] == '\0') {
- if (!headerDone && currentGroup->hideHeaders) {
- headerDone = !0; continue;
- }
- headerDone = !0;
- }
- if (currentGroup->hideHeaders && !headerDone && strncmp(temp, "X-NewsSoftware:", 15)) continue;
- ps = &temp[0];
- if (temp[0] == '\0') strcpy(temp, " ");
- while (strlen(ps)) {
- strncpy(work, ps, wrapCol);
- work[wrapCol] = '\0';
- len = strlen(work);
- if (len == wrapCol && strlen(ps) > wrapCol)
- strcat(work, "\\");
- //
- // These malloc()'s KILL performance. There MUST
- // be a better way.....
- //
- np = (NODE *) malloc (sizeof (NODE));
- if (!np) {
- fclose(fp);
- return;
- }
- np->ln_Name = (char *) malloc (strlen (work) + 1);
- if (!np->ln_Name) {
- fclose (fp);
- free (np);
- return;
- }
- strcpy(np->ln_Name, work);
- AddTail(&msgList, np);
- messageLines++;
- ps = &ps[len];
- }
- }
- fclose(fp);
- if (ap->state == UNREAD) {
- treeDirty = !0;
- if (currentGroup->unread) currentGroup->unread--;
- }
- ap->state = READ;
- sprintf(ap->node.ln_Name, "%s %6d %-32.32s %.64s",
- ap->state?" READ ":"UNREAD ",
- ap->filenum,
- ap->from,
- ap->subject
- );
- GT_SetGadgetAttrs(gadgetArray[MSGLIST_ID], mainWindow, NULL, GTLV_Labels, &msgList, TAG_DONE);
- if (flag) {
- GT_SetGadgetAttrs(gadgetArray[MSGLIST_ID], mainWindow, NULL, GTLV_Top, 0, TAG_DONE);
- viewTop = 0;
- }
- gp = NextGroup();
- sprintf(artStatus, " *** Article %6d (%d remaining) Next Group is %s",
- ap->filenum,
- currentGroup->unread,
- currentGroup != gp ? gp->groupName : "No More"
- );
- GT_SetGadgetAttrs(gadgetArray[STATUS_ID], mainWindow, NULL, GTTX_Text, artStatus, TAG_DONE);
- GT_SetGadgetAttrs(gadgetArray[FROM_ID], mainWindow, NULL, GTTX_Text, ap->from, TAG_DONE);
- GT_SetGadgetAttrs(gadgetArray[ORGANIZATION_ID], mainWindow, NULL, GTTX_Text, org, TAG_DONE);
- GT_SetGadgetAttrs(gadgetArray[DATE_ID], mainWindow, NULL, GTTX_Text, date, TAG_DONE);
- GT_SetGadgetAttrs(gadgetArray[SUBJECT_ID], mainWindow, NULL, GTTX_Text, ap->subject, TAG_DONE);
- GT_SetGadgetAttrs(gadgetArray[ARTLIST_ID], mainWindow, NULL, GTLV_Top, ap->index, TAG_DONE);
- GT_RefreshWindow(mainWindow, NULL);
- return;
- }
-
- void NextArticle() {
- if (currentGroup->artList.lh_TailPred == (NODE *)currentArticle) return;
- ShowMessage((ART *)currentArticle->node.ln_Succ);
- }
-
- void PrevArticle() {
- if (currentGroup->artList.lh_Head == (NODE *)currentArticle) return;
- ShowMessage((ART *)currentArticle->node.ln_Pred);
- }
-
- void Post(BOOL followupFlag) {
- char fname[256], rname[256], from[512], subject[512], msgid[256], refs[512], groups[512], temp[512];
- char work[256];
- FILE *fp, *outfp, *reffp;
-
- if (followupFlag) {
- strcpy(temp, uunews);
- AddPart(temp, NewsGroupToFileName (currentGroup->groupName), 256);
- sprintf(fname, "%d", currentArticle->filenum);
- AddPart(temp, fname, 256);
-
- fp = fopen(temp, "r");
- if (!fp) {
- t_printf(mainWindow, "Can't open %s for input", temp);
- return;
- }
- // parse header
- from[0] = msgid[0] = refs[0] = 0;
- while (fgets(temp, 512, fp)) {
- temp[strlen(temp)-1] = '\0';
- if (temp[0] == '\0') break;
- if (!strncmp(temp, "From: ", 6))
- strcpy(from, &temp[6]);
- else if (!strnicmp(temp, "Message-ID: ", 12)) {
- strcpy(msgid, &temp[12]);
- }
- else if (!strnicmp(temp, "References: ", 12)) {
- strcpy(refs, &temp[12]);
- }
- else if (!strnicmp(temp, "Newsgroups: ", 12)) {
- strcpy(groups, &temp[12]);
- }
- else if (!strnicmp(temp, "Subject: ", 9)) {
- strcpy(subject, &temp[9]);
- }
- }
- }
- sprintf(fname, "t:%s%x-text.txt", userName, FindTask(0));
- unlink(fname);
- outfp = fopen(fname, "w");
- if (!outfp) {
- t_printf(mainWindow, "Can't open %s for output", fname);
- fclose(fp);
- return;
- }
- if (followupFlag)
- fprintf(outfp, "Newsgroups: %s\n", groups);
- else
- fprintf(outfp, "Newsgroups: %s\n", currentGroup->groupName);
-
- if (followupFlag) {
- if (!strnicmp(subject, "re:", 3))
- fprintf(outfp, "Subject: %s\n", subject);
- else
- fprintf(outfp, "Subject: Re: %s\n", subject);
- }
- else
- fprintf(outfp, "Subject: \n");
- fprintf(outfp, "Distribution: world\n\n");
-
- if (followupFlag) {
- if (msgid[0])
- fprintf(outfp, "In article %s ", msgid);
- else
- fprintf(outfp, "In article ??? ");
- if (from[0])
- fprintf(outfp, "%s writes:\n", from);
- else
- fprintf(outfp, "??? writes:\n");
- while (fgets(temp, 512, fp)) {
- fprintf(outfp, ">%s", temp);
- }
- fclose(fp);
- }
- fprintf(outfp, "\n--\n");
-
- strcpy(temp, uulib);
- sprintf(work, "%s.signature", userName);
- AddPart(temp, work, 256);
- fp = fopen(temp, "r");
- if (!fp) {
- strcpy(temp, uunews);
- AddPart(temp, NewsGroupToFileName (currentGroup->groupName), 256);
- AddPart(temp, work, 256);
- fp = fopen(temp, "r");
- }
- if (!fp) {
- strcpy(temp, uulib);
- AddPart(temp, ".signature", 256);
- fp = fopen(temp, "r");
- }
- if (!fp) {
- fprintf(outfp, ".signature under construction\n");
- }
- else {
- while (fgets(temp, 512, fp)) {
- fprintf(outfp, "%s", temp);
- }
- fclose(fp);
- }
- fclose(outfp);
- sprintf(temp, "%s %s", newsEditor, fname);
- Execute(temp, 0,0);
- if (!SendItRequest()) return;
- sprintf(rname, "t:%s%x-refs.txt", userName, FindTask(0));
- unlink(rname);
- outfp = fopen(rname, "w");
- if (followupFlag) {
- if (refs[0] || msgid[0]) {
- if (outfp) {
- fprintf(outfp, "References: ");
- if (refs[0]) fprintf(outfp, "%s ", refs);
- if (msgid[0]) fprintf(outfp, "%s", msgid);
- fprintf(outfp, "\n");
- }
- }
- }
-
- // append user.nrefs to the refs file
- if (outfp) {
- strcpy(temp, uulib);
- sprintf(work, "%s.nrefs", userName);
- AddPart(temp, work, 256);
- reffp = fopen(temp, "r");
- if (reffp) {
- while (fgets(temp, 512, reffp)) fprintf(outfp, "%s", temp);
- fclose(reffp);
- }
- }
- if (outfp) fprintf(outfp, "X-NewsSoftware: %s\n", GRN_VERSION);
- if (outfp) {
- fclose(outfp);
- sprintf(temp, "RUN <nil: >nil: %s %s -R %s -x %s -x %s",
- postNews, fname, rname, fname, rname
- );
-
-
- }
- else {
- sprintf(temp, "RUN <nil: >nil: %s %s -x %s",
- postNews, fname, fname
- );
- }
- Execute(temp, 0,0);
- GT_RefreshWindow(mainWindow, NULL);
- }
-
- void Mail(BOOL replyFlag) {
- char fname[256], from[512], subject[512], msgid[256], temp[512], work[256];
- FILE *fp, *outfp;
-
- strcpy(temp, uunews);
- AddPart(temp, NewsGroupToFileName (currentGroup->groupName), 256);
- sprintf(fname, "%d", currentArticle->filenum);
- AddPart(temp, fname, 256);
-
- fp = fopen(temp, "r");
- if (!fp) {
- t_printf(mainWindow, "Can't open %s for input", temp);
- return;
- }
- // parse header
- from[0] = msgid[0] = 0;
- while (fgets(temp, 512, fp)) {
- temp[strlen(temp)-1] = '\0';
- if (temp[0] == '\0') break;
- if (!strncmp(temp, "From: ", 6) && from[0] == '\0') {
- strcpy(from, &temp[6]);
- }
- else if (!strncmp(temp, "Reply-To: ", 10)) {
- strcpy(from, &temp[10]);
- }
- else if (!strncmp(temp, "Message-ID: ", 12)) {
- strcpy(msgid, &temp[12]);
- }
- else if (!strncmp(temp, "Subject: ", 9)) {
- strcpy(subject, &temp[9]);
- }
- }
- sprintf(fname, "t:%s%x-text.txt", userName, FindTask(0));
- unlink(fname);
- outfp = fopen(fname, "w");
- if (!outfp) {
- t_printf(mainWindow, "Can't open %s for output", fname);
- fclose(fp);
- return;
- }
- if (from[0] && replyFlag)
- fprintf(outfp, "To: %s\n", from);
- else
- fprintf(outfp, "To: \n");
-
- if (!subject[0])
- fprintf(outfp, "Subject: NO SUBJECT\n");
- else if (!strnicmp(subject, "re:", 3))
- fprintf(outfp, "Subject: FYI: %s\n", subject);
- else
- fprintf(outfp, "Subject: FYI: %s\n", subject);
-
- if (msgid[0])
- fprintf(outfp, "References: %s\n", msgid);
-
- fprintf(outfp, "X-NewsSoftware: %s\n\n", GRN_VERSION);
-
- if (msgid[0])
- fprintf(outfp, "In article %s ", msgid);
- else
- fprintf(outfp, "In article ??? ");
- if (replyFlag)
- fprintf(outfp, "you wrote:\n");
- else if (from[0])
- fprintf(outfp, "%s writes:\n", from);
- else
- fprintf(outfp, "??? writes:\n");
- while (fgets(temp, 512, fp)) {
- fprintf(outfp, ">%s", temp);
- }
- fclose(fp);
- fprintf(outfp, "\n--\n");
-
- strcpy(temp, uulib);
- sprintf(work, "%s.signature", userName);
- AddPart(temp, work, 256);
- fp = fopen(temp, "r");
- if (!fp) {
- strcpy(temp, uulib);
- AddPart(temp, ".signature", 256);
- fp = fopen(temp, "r");
- }
- if (!fp) {
- fprintf(outfp, ".signature under construction\n");
- }
- else {
- while (fgets(temp, 512, fp)) {
- fprintf(outfp, "%s", temp);
- }
- fclose(fp);
- }
- fclose(outfp);
- sprintf(temp, "%s %s", mailEditor, fname);
- Execute(temp, 0,0);
- if (!TwoGadgetRequest("GRn - Request", " Send it off? ", "_YES", "_NO")) return;
- sprintf(temp, "%s >nil: <%s -f %s",
- sendMail, fname, userName
- );
- Execute(temp, 0,0);
- unlink(fname);
- }
-
- /************************************************************************/
-
- BOOL ParseThread(char *filename, char *refs, char *msgid) {
- char temp[512], *ps;
- FILE *fp;
-
- fp = fopen(filename, "r");
- if (!fp) return 0;
- if (refs) *refs = 0;
- if (msgid) *msgid = 0;
- while (fgets(temp, 512, fp)) {
- temp[strlen(temp)-1] = '\0';
- if (!strlen(temp)) break;
- if (!strnicmp(temp, "References:", 11)) {
- ps = &temp[11];
- while (*ps == ' ') ps++;
- strcpy(refs, ps);
- }
- else if (!strnicmp(temp, "Message-ID:", 11)) {
- ps = &temp[11];
- while (*ps == ' ') ps++;
- strcpy(msgid, ps);
- }
- }
- fclose(fp);
- return !0;
- }
-
- char *ArticleName(ART *ap) {
- static char temp1[256], temp2[256];
-
- strcpy(temp1, uunews);
- AddPart(temp1, NewsGroupToFileName (currentGroup->groupName), 256);
- sprintf(temp2, "%d", ap->filenum);
- AddPart(temp1, temp2, 256);
- return &temp1[0];
- }
-
- BOOL RefCmp(char *ref1, char *ref2) {
- char r1[256], r2[256], *pd, *ps;
-
- while (*ref1) {
- // get a reference from ref1 into r1
- pd = &r1[0];
- while (*ref1 && *ref1 != '<') ref1++;
- if (*ref1 == '\0') return 0;
- while (*ref1 && *ref1 != '>') *pd++ = *ref1++;
- if (*ref1 == '>') *pd++ = *ref1++;
- *pd = '\0';
- // now compare against all refs in ref2
- ps = ref2;
- while (*ref2) {
- // get a reference from ref2 into r2
- pd = &r2[0];
- while (*ps && *ps != '<') ps++;
- if (*ps == '\0') return 0;
- while (*ps && *ps != '>') *pd++ = *ps++;
- if (*ps == '>') *pd++ = *ps++;
- *pd = '\0';
- if (!stricmp(r1, r2)) return !0;
- }
- }
- return 0;
- }
-
- BOOL NextThread() {
- ART *ap;
- char myrefs[512], myid[256], refs[512], msgid[256], subj[256], *ps;
-
- ps = currentArticle->subject;
- while (*ps == ' ') ps++;
- if (!strnicmp(ps, "re:", 3)) ps = &ps[3];
- while (*ps == ' ') ps++;
- strcpy(subj, ps);
- if (!ParseThread(ArticleName(currentArticle), myrefs, myid)) return 0;
- ap = currentArticle;
- do {
- if (currentGroup->artList.lh_TailPred == (NODE *)ap)
- ap = (ART *)currentGroup->artList.lh_Head;
- else
- ap = (ART *)ap->node.ln_Succ;
- if (ap->state == UNREAD) {
- if (!ParseThread(ArticleName(ap), refs, msgid)) continue;
- ps = ap->subject;
- while (*ps == ' ') ps++;
- if (!strnicmp(ps, "re:", 3)) ps = &ps[3];
- while (*ps == ' ') ps++;
- if (RefCmp(myid, refs) || RefCmp(myrefs, refs) || RefCmp(msgid, myrefs) || !stricmp(subj, ps)) {
- ShowMessage(ap);
- return !0;
- }
- }
- } while (ap != currentArticle);
- return 0;
- }
-
- /************************************************************************/
-
- /*
- * void ProcessGadget(id, code);
- * UWORD id; gadgetID of gadget to process
- * UWORD code; IntuiMessage Code
- *
- * Synopsis:
- * Process IDCMP message for GadTools gadget. Simply prints an appropriate string
- * into the event listview, unless it is palette related (handles palette appropriately).
- */
- static void ProcessGadget(UWORD id, UWORD code) {
- /* GADGET *gad = gadgetArray[id]; */
- ART *ap;
- GLIST *gp;
-
- switch (id) {
- case HIDEHEADERS_ID:
- currentGroup->hideHeaders = !currentGroup->hideHeaders;
- treeDirty = !0;
- GT_SetGadgetAttrs(gadgetArray[HIDEHEADERS_ID], mainWindow, NULL,
- GTCB_Checked, currentGroup->hideHeaders?TRUE:FALSE,
- TAG_DONE
- );
- ShowMessage(currentArticle);
- break;
- case HIDEREAD_ID:
- currentGroup->hideRead = !currentGroup->hideRead;
- treeDirty = !0;
- GT_SetGadgetAttrs(gadgetArray[HIDEREAD_ID], mainWindow, NULL,
- GTCB_Checked, currentGroup->hideRead?TRUE:FALSE,
- TAG_DONE
- );
- break;
- case NEXTGROUP_ID:
- gp = NextGroup();
- if (gp != currentGroup) {
- mode = NEXTGROUPS_MODE;
- currentGroup = gp;
- }
- break;
- case PREVGROUP_ID:
- gp = PrevGroup();
- if (gp != currentGroup) {
- mode = PREVGROUPS_MODE;
- currentGroup = gp;
- }
- break;
- case QUIT_ID:
- mode = GROUPS_MODE;
- break;
- case SORT_ID:
- currentGroup->sortActive = code;
- treeDirty = !0;
- GT_SetGadgetAttrs(gadgetArray[ARTLIST_ID], mainWindow, NULL, GTLV_Labels, ~0, TAG_DONE);
- SortArticles();
- GT_SetGadgetAttrs(gadgetArray[ARTLIST_ID], mainWindow, NULL, GTLV_Labels, ¤tGroup->artList, TAG_DONE);
- ShowMessage(currentArticle);
- break;
- case ARTLIST_ID:
- ap = (ART *)FindListItem(¤tGroup->artList, code);
- if (!ap)
- printf("Error: Can't FindListItem(%d)\n", code);
- else {
- ShowMessage(ap);
- }
- break;
- case PREV_ID:
- PrevArticle();
- break;
- case NEXT_ID:
- NextArticle();
- break;
- case NEXTUNREAD_ID:
- ap = currentArticle;
- do {
- if (currentGroup->artList.lh_TailPred == (NODE *)ap)
- ap = (ART *)currentGroup->artList.lh_Head;
- else
- ap = (ART *)ap->node.ln_Succ;
- if (ap->state == UNREAD) {
- ShowMessage(ap);
- return;
- }
- } while (ap != currentArticle);
- break;
- case NEXTTHREAD_ID:
- if (!NextThread()) {
- ap = currentArticle;
- do {
- if (currentGroup->artList.lh_TailPred == (NODE *)ap)
- ap = (ART *)currentGroup->artList.lh_Head;
- else
- ap = (ART *)ap->node.ln_Succ;
- if (ap->state == UNREAD) {
- ShowMessage(ap);
- return;
- }
- } while (ap != currentArticle);
- }
- break;
- case CATCHUP_ID:
- Catchup();
- mode = NEXTGROUPS_MODE;
- break;
- case REPLY_ID:
- Mail(TRUE);
- break;
- case FOLLOWUP_ID:
- Post(TRUE);
- break;
- case POST_ID:
- Post(FALSE);
- break;
- case FORWARD_ID:
- Mail(FALSE);
- break;
- case PRINT_ID:
- Print();
- break;
- case SAVE_ID:
- Save();
- break;
- default:
- t_printf(mainWindow, "ProcessGadget - id = %d", id); break;
- }
- }
-
- static void IDCMPFunc(IMSG *m) {
- GLIST *gp;
- ART *ap;
-
- switch (m->Class) {
- case IDCMP_CLOSEWINDOW:
- mode = ABORT_MODE;
- break;
- case IDCMP_VANILLAKEY:
- switch (m->Code) {
- case 'F': Post(TRUE); break;
- case 'R': Mail(TRUE); break;
- case 'n': NextArticle(); break;
- case 'p': PrevArticle(); break;
- case 'C': Catchup();
- mode = NEXTGROUPS_MODE;
- break;
- case 'N': gp = NextGroup();
- if (gp == currentGroup) break;
- mode = NEXTGROUPS_MODE;
- currentGroup = gp;
- break;
- case 'b':
- case 'P': gp = PrevGroup();
- if (gp == currentGroup) break;
- mode = PREVGROUPS_MODE;
- currentGroup = gp;
- break;
- case ' ': viewTop += viewHeight-2;
- if (viewTop > messageLines-viewHeight)
- viewTop = messageLines-viewHeight;
- if (viewTop < 0) viewTop = 0;
- GT_SetGadgetAttrs(gadgetArray[MSGLIST_ID], mainWindow, NULL,
- GTLV_Top, viewTop, TAG_DONE);
- break;
- case 'G': mode = GROUPS_MODE; break;
- case 'S': Save(); break;
- case 't': if (!NextThread()) {
- ap = currentArticle;
- do {
- if (currentGroup->artList.lh_TailPred == (NODE *)ap)
- ap = (ART *)currentGroup->artList.lh_Head;
- else
- ap = (ART *)ap->node.ln_Succ;
- if (ap->state == UNREAD) {
- ShowMessage(ap);
- return;
- }
- } while (ap != currentArticle);
- }
- break;
- case 'u': ap = currentArticle;
- do {
- if (currentGroup->artList.lh_TailPred == (NODE *)ap)
- ap = (ART *)currentGroup->artList.lh_Head;
- else
- ap = (ART *)ap->node.ln_Succ;
- if (ap->state == UNREAD) {
- ShowMessage(ap);
- return;
- }
- } while (ap != currentArticle);
- break;
- }
- break;
- case IDCMP_RAWKEY:
- switch (m->Code) {
- case 0x4c: // up key
- if (viewTop) viewTop--;
- if (viewTop < 0) viewTop = 0;
- GT_SetGadgetAttrs(gadgetArray[MSGLIST_ID], mainWindow, NULL,
- GTLV_Top, viewTop, TAG_DONE);
- break;
- case 0x4d: // down key
- viewTop++;
- if (viewTop > messageLines-viewHeight)
- viewTop = messageLines-viewHeight;
- if (viewTop < 0) viewTop = 0;
- GT_SetGadgetAttrs(gadgetArray[MSGLIST_ID], mainWindow, NULL,
- GTLV_Top, viewTop, TAG_DONE);
- break;
- }
-
- }
- }
-
- void ArticlesWindow() {
- ART *ap;
- UWORD n = 0;
-
- if (!currentGroup || currentGroup->articles == 0) {
- mode = GROUPS_MODE;
- return;
- }
- NewList(&msgList);
- LayoutGadgets(defaultFont, prefWidth,windowHeight, screenTop);
- gList = CreateGadgets(&gadgetArray[0], &gadDefs[0]);
- AddGList(mainWindow, gList, -1, -1, 0);
- RefreshGList(gList, mainWindow, 0, -1);
- GT_RefreshWindow(mainWindow, NULL);
-
- GT_SetGadgetAttrs(gadgetArray[ARTLIST_ID], mainWindow, NULL, GTLV_Labels, ~0, TAG_DONE);
- for (ap=(ART *)currentGroup->artList.lh_Head; ap->node.ln_Succ; ap = (ART *)ap->node.ln_Succ) {
- sprintf(ap->node.ln_Name, "%s %6d %-32.32s %s",
- ap->state?" READ ":"UNREAD ",
- ap->filenum,
- ap->from,
- ap->subject
- );
- }
- SortArticles();
- GT_SetGadgetAttrs(gadgetArray[ARTLIST_ID], mainWindow, NULL, GTLV_Labels, ¤tGroup->artList, TAG_DONE);
- GT_SetGadgetAttrs(gadgetArray[SORT_ID], mainWindow, NULL, GTCY_Active, currentGroup->sortActive, TAG_DONE);
- if (currentGroup->unread == 0) { // show last READ message
- for (ap=(ART *)currentGroup->artList.lh_Head; ap->node.ln_Succ; ap = (ART *)ap->node.ln_Succ) {
- n++;
- }
- ShowMessage((ART *)currentGroup->artList.lh_TailPred);
- }
- else { // show first unread message
- for (ap=(ART *)currentGroup->artList.lh_Head; ap->node.ln_Succ; ap = (ART *)ap->node.ln_Succ) {
- if (ap->state == UNREAD) break;
- n++;
- }
- ShowMessage(ap);
- }
- #ifdef MYKE_REMOVED_THIS
- GT_SetGadgetAttrs(gadgetArray[ARTLIST_ID], mainWindow, NULL,
- GTLV_Selected, n,
- GTLV_Top, n,
- TAG_DONE
- );
- #endif
-
- t_printf(mainWindow, "GRn - %s", currentGroup->groupName);
- GT_SetGadgetAttrs(gadgetArray[HIDEHEADERS_ID], mainWindow, NULL,
- GTCB_Checked, currentGroup->hideHeaders?TRUE:FALSE,
- TAG_DONE
- );
- GT_SetGadgetAttrs(gadgetArray[HIDEREAD_ID], mainWindow, NULL,
- GTCB_Checked, currentGroup->hideRead?TRUE:FALSE,
- TAG_DONE
- );
- while (mode == ARTICLES_MODE) {
- WaitPort (mainWindow->UserPort);
- EventHandler(mainWindow, ProcessGadget, IDCMPFunc, NULL);
- }
- FreeListNodes(&msgList, TRUE);
- CloseArticles();
- }
-