home *** CD-ROM | disk | FTP | other *** search
- #include "prefs.h"
- #ifdef LATTICE
- #include <dos.h>
- #endif
- #ifdef DICE
- #include <libraries/dos.h>
- #endif
-
-
-
- Prototype BOOL getline(FILE *,char *,long *);
- Prototype void removeCR(char *);
- Prototype long read_home_box(void);
- Prototype BOOL get_config_entries(void);
- Prototype char *firstnwsp(char *);
-
-
-
- struct FlagItem {
- char *MsgID;
- StatusFlag Stat;
- };
-
-
-
- long
- read_home_box(void)
- {
- FILE *fp;
- struct MailItem *I;
- char Line[MAX_LINELENGTH];
- register char *ptr;
- char **last_data = NULL;
- register int i,c;
- long len,pos;
- BOOL InHeader = FALSE;
- static BOOL FirstAccess = TRUE;
- static struct FlagItem *flgs;
- struct MailItem *act=NULL,*last;
- static int OldMaxArticle = 0;
- char TitleString[1024];
-
- #ifdef DEBUG
- fprintf(stderr,"read_home_box: %s\n",FolderName);
- #endif
-
- if (FirstAccess) {
- #ifdef DEBUG
- fprintf(stderr," first attempt to read folder\n");
- #endif
- OldMaxArticle = 0;
- FirstAccess = FALSE;
- flgs = NULL;
- }
- else {
- #ifdef DEBUG
- fprintf(stderr," keep old msg-ids");
- #endif
- if (flgs) {
- #ifdef DEBUG
- fprintf(stderr,", clear old");
- #endif
- for(i=0;i<OldMaxArticle;i++) {
- if (flgs[i].MsgID)
- free(flgs[i].MsgID);
- }
- free(flgs);
- #ifdef DEBUG
- fprintf(stderr," (ok)");
- #endif
- }
- if (flgs=malloc(MaxArticle*sizeof(struct FlagItem))) {
- #ifdef DEBUG
- fprintf(stderr,", save new");
- #endif
- OldMaxArticle = MaxArticle;
- for(i=0;i<MaxArticle;i++) {
- I = i_th(i+1);
- if (flgs[i].MsgID = malloc(strlen(I->MessageID)+1)) {
- strcpy(flgs[i].MsgID,I->MessageID);
- flgs[i].Stat = I->Status;
- }
- }
- #ifdef DEBUG
- fprintf(stderr," (ok)");
- #endif
- }
- #ifdef DEBUG
- fprintf(stderr,"\n");
- #endif
- }
-
- /* free mailbox */
- while(MailList) {
- #ifdef DEBUG
- fprintf(stderr,"Freeing one old mailbox item...");
- #endif
- I = MailList;
- MailList = MailList->next;
- free(I);
- #ifdef DEBUG
- fprintf(stderr,"ok.\n");
- #endif
- }
-
- MaxArticle=0;
-
- if ((fp=OpenHomeBox())==NULL)
- return(0L);
-
- while (getline(fp,Line,&pos)) {
- #ifdef DEBUG
- /* fprintf(stderr," line: %s\n",Line);*/
- #endif
- if (InHeader) {
- act->TotalLines++;
- if (!act->From && !strnicmp(Line,"From:",5)) {
- ptr = delete_wspaces_begin(Line+5);
- delete_wspaces_end(ptr);
- act->FromName = parse_arpa_from(ptr);
- if (act->From = strdup(ptr))
- last_data = &act->From;
- else
- last_data = NULL;
- }
- else if (!act->MessageID && !strnicmp(Line,"Message-Id:",11)) {
- ptr = delete_wspaces_begin(Line+11);
- delete_wspaces_end(ptr);
- if (act->MessageID = strdup(ptr))
- last_data = &act->MessageID;
- else
- last_data = NULL;
- }
- else if (!act->Cc && !strnicmp(Line,"Cc:",3)) {
- ptr = delete_wspaces_begin(Line+3);
- delete_wspaces_end(ptr);
- if (act->Cc=strdup(ptr))
- last_data = &act->Cc;
- else
- last_data = NULL;
- }
- else if (!act->Bcc && !strnicmp(Line,"Bcc:",4)) {
- ptr = delete_wspaces_begin(Line+4);
- delete_wspaces_end(ptr);
- if (act->Bcc=strdup(ptr))
- last_data = &act->Bcc;
- else
- last_data = NULL;
- }
- else if (!act->Date && !strnicmp(Line,"Date:",5)) {
- register char *p;
- ptr = delete_wspaces_begin(Line+5);
- delete_wspaces_end(ptr);
- if (*ptr<'0' || *ptr>'9') { /* if exists name of day, */
- while (*ptr!=' ') /* skip it */
- ptr++;
- }
- while (*ptr==' ') /* skip spaces */
- ptr++;
- p=ptr;
- while (*p!=' ') /* skip day */
- p++;
- while (*p==' ') /* skip spaces */
- p++;
- while (*p!=' ') /* skip month */
- p++;
- *p='\0';
- if (act->Date=malloc(strlen(ptr)+1)) {
- strcpy(act->Date,ptr);
- if (act->Date[2]==' ') { /* e.g. "13 Aug" */
- act->Date[2]=act->Date[5];
- act->Date[5]=act->Date[1];
- act->Date[1]=act->Date[4];
- act->Date[4]=act->Date[0];
- act->Date[0]=act->Date[3];
- act->Date[3]=' ';
- }
- else if (act->Date[1]==' ') { /* e.g. "7 Sep" */
- act->Date[1]=act->Date[3];
- act->Date[3]=act->Date[0];
- act->Date[0]=act->Date[2];
- act->Date[2]=act->Date[4];
- act->Date[4]=act->Date[3];
- act->Date[3]=' ';
- }
- }
- last_data = NULL;
- }
- else if (!act->RR_To && !strnicmp(Line,"Return-Receipt-To:",18)) {
- ptr = delete_wspaces_begin(Line+18);
- delete_wspaces_end(ptr);
- if (act->RR_To=strdup(ptr))
- last_data = &act->RR_To;
- else
- last_data = NULL;
- }
- else if (!act->RV_To && !strnicmp(Line,"Return-View-To:",15)) {
- ptr = delete_wspaces_begin(Line+15);
- delete_wspaces_end(ptr);
- if (act->RV_To=strdup(ptr))
- last_data = &act->RV_To;
- else
- last_data = NULL;
- }
- else if (!act->To && !strnicmp(Line,"To:",3)) {
- ptr = delete_wspaces_begin(Line+3);
- delete_wspaces_end(ptr);
- act->ToName = parse_arpa_from(ptr);
- if (act->To=strdup(ptr))
- last_data = &act->To;
- else
- last_data = NULL;
- }
- else if (!act->ReplyTo && !strnicmp(Line,"Reply-To:",9)) {
- ptr = delete_wspaces_begin(Line+9);
- delete_wspaces_end(ptr);
- if (act->ReplyTo=strdup(ptr))
- last_data = &act->ReplyTo;
- else
- last_data = NULL;
- }
- else if (!act->Subject && !strnicmp(Line,"Subject:",8)) {
- ptr = delete_wspaces_begin(Line+8);
- delete_wspaces_end(ptr);
- if (act->Subject=strdup(ptr))
- last_data = &act->Subject;
- else
- last_data = NULL;
- }
- else if (!strnicmp(Line,"Priority:",9)) {
- act->Urgent = 1;
- last_data = NULL;
- }
- else if (!strnicmp(Line,"X-Status:",9)) {
- while (c=*ptr++) {
- switch (c) {
- case 'O' :act->Status |= OLD; break;
- case 'R' :act->Status |= READ; break;
- case 'L' :act->Status |= LOGGED; break;
- case 'A' :act->Status |= ANSWERED; break;
- case 'F' :act->Status |= FORWARDED; break;
- case 'B' :act->Status |= BOUNCED; break;
- }
- }
- last_data = NULL;
- act->OldStatus = act->Status;
- }
- else if (last_data && strlen(Line) && (Line[0]==' ' || Line[0]=='\t')) {
- ptr = delete_wspaces_end(Line+1);
- *last_data = realloc(*last_data,strlen(ptr)+3+strlen(*last_data));
- strcat(*last_data,"\n\t");
- strcat(*last_data,ptr);
- }
- else if (!strlen(Line)) {
- act->TextStart=ftell(fp);
- InHeader = FALSE;
- last_data = NULL;
- }
- else
- last_data = NULL;
- }
- else {
- if (!strncmp(Line,"From ",5)) {
- last_data = NULL;
- InHeader = TRUE;
- MaxArticle++;
-
- last = act;
- if (!(act=malloc(sizeof(struct MailItem))))
- clean_exit(20);
-
- setmem(act,sizeof(struct MailItem),0);
-
- if (ReverseSorting) {
- act->next = MailList;
- MailList = act;
- }
- else {
- if (last)
- last->next = act;
- if (!MailList)
- MailList = act;
- }
-
- act->SignatureStart=0;
- act->ArtikelStart=pos;
- if (last) {
- #ifdef DEBUG
- fprintf(stderr,"Aha, (MaxArticle>1): pos=%ld, MaxArt=%d\n",pos,MaxArticle);
- #endif
- #ifdef DEBUG
- I = i_th(MaxArticle-1);
- if (I!=last)
- fprintf(stderr,"Komisch, (I!=last) [%s,%s]\n",I->From,last->From);
- #endif
- last->ArtikelEnd=pos-1;
- if (last->SignatureStart==0)
- last->SignatureStart=last->ArtikelEnd;
- #ifdef DEBUG
- fprintf(stderr,"I->ArtikelEnd[%d]=%ld (%ld)\n",MaxArticle-1,I->ArtikelEnd,last->ArtikelEnd);
- #endif
- }
- act->TextStart=pos;
- act->TotalLines++;
-
- sprintf(TitleString,"Reading in %s, message: %d",FolderName,MaxArticle);
- SetScreenTitle(TitleString);
- }
- else if (!strcmp(Line,"-- ")) { /* signature found */
- act->SignatureStart=pos;
- act->Lines++;
- act->TotalLines++;
- }
- else {
- act->Lines++;
- act->TotalLines++;
- }
- }
- } /* while (getline) */
-
- #ifdef DEBUG
- fprintf(stderr," closing act");
- #endif
-
- fseek(fp,0L,2); /* An das Ende positionieren */
- len=ftell(fp);
- act->ArtikelEnd=len-1;
- if (act->SignatureStart==0)
- act->SignatureStart=act->ArtikelEnd;
- CloseHomeBox(fp);
-
- /*
- if (ReverseSorting) {
- for(i=0;i<(MaxArticle/2);i++) {
- I = Incoming[i];
- Incoming[i] = Incoming[MaxArticle-i-1];
- Incoming[MaxArticle-i-1] = I;
- }
- }
- */
-
- #ifdef DEBUG
- fprintf(stderr," compare old and new message-ids\n");
- #endif
- for(I=MailList;I;I=I->next) {
- for(i=0;i<OldMaxArticle;i++) {
- if (flgs[i].MsgID && I->MessageID) {
- if (strcmp(flgs[i].MsgID,I->MessageID)==0) {
- I->Status = flgs[i].Stat;
- }
- }
- }
- }
-
- #ifdef DEBUG
- fprintf(stderr,"Checking mailbox contents:\n");
- for(I=MailList;I;I=I->next) {
- fprintf(stderr," %s (%ld, %ld, %ld, %ld - %ld, %ld)\n",I->From,
- I->ArtikelStart,I->TextStart,I->SignatureStart,I->ArtikelEnd,I->Lines,I->TotalLines);
- }
- #endif
-
- #ifdef DEBUG
- fprintf(stderr," got %d message(s) from folder %s (%ld)\n",MaxArticle,FolderName,len);
- #endif
- return(len);
- }
-
-
-
- BOOL
- get_config_entries(void)
- {
- FILE *fp;
- char *ptr;
- char line[MAX_LINELENGTH];
-
- if (getenv("Pager")) {
- strcpy(line,getenv("Pager"));
- if (strlen(line))
- Pager = strdup(line);
- }
-
- if (getenv("Editor")) {
- strcpy(line,getenv("Editor"));
- if (strlen(line))
- MailEditor = strdup(line);
- }
-
- if (getenv("Shell")) {
- strcpy(line,getenv("Shell"));
- if (strlen(line))
- Shell = strdup(line);
- }
-
- if (getenv("RealName")) {
- strcpy(line,getenv("RealName"));
- if (strlen(line))
- RealName = strdup(line);
- }
-
- if (getenv("HostName")) {
- strcpy(line,getenv("HostName"));
- if (strlen(line))
- HostName = strdup(line);
- }
-
- if (getenv("DomainName")) {
- strcpy(line,getenv("DomainName"));
- if (strlen(line))
- DomainName = strdup(line);
- }
-
- if (!UserName && getenv("UserName")) {
- strcpy(line,getenv("UserName"));
- if (strlen(line))
- UserName = strdup(line);
- }
-
- if (!(fp=fopen(UULIB_CONFIG,"r"))) {
- fprintf(stderr,"elm: cannot open %s\n",UULIB_CONFIG);
- return(FALSE);
- }
-
- while(fgets(line,MAX_LINELENGTH-1,fp)) {
- removeCR(line);
-
- ptr=firstnwsp(line);
- ptr = delete_wspaces_begin(ptr);
- delete_wspaces_end(ptr);
-
- if (strlen(ptr)>=2 && *ptr=='"' && lastch(ptr)=='"') {
- ptr++;
- ptr[strlen(ptr)-1] = '\0';
- }
-
- if (strlen(ptr)) {
- if (!strnicmp(line,"UserName",8)) {
- if (!UserName) /* if not already set */
- UserName = strdup(ptr);
- }
- else if (!strnicmp(line,"NodeName",8)) {
- if (!HostName) /* if not already set */
- HostName = strdup(ptr);
- }
- else if (!strnicmp(line,"DomainName",10))
- if (!DomainName) /* if not already set */
- DomainName = strdup(ptr);
- }
- }
- fclose(fp);
-
- if (!UserName || !HostName || !DomainName) {
- fprintf(stderr,"elm: %s incomplete\n",UULIB_CONFIG);
- return FALSE;
- }
-
- strcpy(line,UULIB);
- strcat(line,UserName);
- strcat(line,ELM_RC);
- if (!(fp=fopen(line,"r"))) {
- strcpy(line,UULIB);
- strcat(line,ELM_RC);
- if (!(fp=fopen(line,"r"))) {
- fprintf(stderr,"elm: cannot open %s\n",ELM_RC);
- return(FALSE);
- }
- }
-
- while(fgets(line,MAX_LINELENGTH-1,fp)) {
- removeCR(line);
-
- ptr=firstnwsp(line);
- ptr = delete_wspaces_begin(ptr);
- delete_wspaces_end(ptr);
-
- if (strlen(ptr)>=2 && *ptr=='"' && lastch(ptr)=='"') {
- ptr++;
- ptr[strlen(ptr)-1] = '\0';
- }
-
- if (strlen(ptr)) {
- if (!strnicmp(line,"Screen-Width",12))
- Screen_Width = atoi(ptr);
-
- else if (!strnicmp(line,"Screen-Height",13))
- Screen_Height = atoi(ptr);
-
- else if (!strnicmp(line,"Screen-Interlace",16))
- Screen_Interlace = (!strnicmp(ptr,"Yes",3));
-
- else if (!strnicmp(line,"AnswerReturnReceipt",19))
- ReturnReceipt = (!strnicmp(ptr,"Yes",3));
-
- else if (!strnicmp(line,"AnswerReturnView",16))
- ReturnView = (!strnicmp(ptr,"Yes",3));
-
- else if (!strnicmp(line,"RequestReturnReceipt",20))
- WantReturn = (!strnicmp(ptr,"Yes",3));
-
- else if (!strnicmp(line,"RequestReturnView",17))
- WantView = (!strnicmp(ptr,"Yes",3));
-
- else if (!strnicmp(line,"ShowFullHeader",14))
- ShowHeader = (!strnicmp(ptr,"Yes",3));
-
- else if (!strnicmp(line,"ShowSignature",13))
- ShowSig = (!strnicmp(ptr,"Yes",3));
-
- else if (!strnicmp(line,"AlwaysKeep",10))
- AlwaysKeep = (!strnicmp(ptr,"Yes",3));
-
- else if (!strnicmp(line,"AlwaysDelete",12))
- AlwaysDelete = (!strnicmp(ptr,"Yes",3));
-
- else if (!strnicmp(line,"KeepBackup",10))
- KeepBackup = (!strnicmp(ptr,"Yes",3));
-
- else if (!strnicmp(line,"SendmailVersion",15)) {
- if (!strnicmp(ptr,"Feulner",7))
- SendmailVersion = SM_FEULNER;
- else if (!strnicmp(ptr,"Dillon",6))
- SendmailVersion = SM_DILLON;
- else
- SendmailVersion = SM_OTHER;
- }
- else if (!strnicmp(line,"ReceivedFolder",14))
- ReceivedFolder = strdup(ptr);
-
- else if (!strnicmp(line,"SentArchive",11))
- SentArchive = strdup(ptr);
-
- else if (!strnicmp(line,"Editor",6)) {
- if (MailEditor) free(MailEditor);
- MailEditor = strdup(ptr);
- }
- else if (!strnicmp(line,"FullName",8)) {
- if (RealName) free(RealName);
- RealName = strdup(ptr);
- }
- else if (!strnicmp(line,"ReplyIntroduction",17))
- ReplyIntro = strdup(ptr);
-
- else if (!strnicmp(line,"ForwardIntroduction",19))
- ForwardIntro = strdup(ptr);
-
- else if (!strnicmp(line,"PrefixString",12))
- PrefixString = strdup(ptr);
-
- else if (!strnicmp(line,"Color",5))
- ColorData = strdup(ptr);
-
- else if (!strnicmp(line,"Buffers",7)) {
- FileBufferSize = atol(ptr);
- if (FileBufferSize<1024L)
- FileBufferSize = 1024L;
- }
- else if (!strnicmp(line,"StdFontName",11))
- StdFontName = strdup(ptr);
-
- else if (!strnicmp(line,"StdFontSize",11))
- StdFontSize = atoi(ptr);
-
- else if (!strnicmp(line,"PagerFontName",13))
- PagerFontName = strdup(ptr);
-
- else if (!strnicmp(line,"PagerFontSize",13))
- PagerFontSize = atoi(ptr);
-
- else if (!strnicmp(line,"IntuiFontName",13))
- IntuiFontName = strdup(ptr);
-
- else if (!strnicmp(line,"IntuiFontSize",13))
- IntuiFontSize = atoi(ptr);
-
- else if (!strnicmp(line,"Pager",5)) {
- if (Pager) free(Pager);
- if (stricmp(ptr,"builtin"))
- Pager = strdup(ptr);
- else
- Pager = NULL;
- }
- else if (!strnicmp(line,"UseOwnScreen",12))
- UseOwnScreen = (!strnicmp(ptr,"Yes",3));
-
- else if (!strnicmp(line,"ShanghaiWindows",15))
- ShanghaiWindows = (!strnicmp(ptr,"Yes",3));
-
- else if (!strnicmp(line,"ReverseSorting",14))
- ReverseSorting = (!strnicmp(ptr,"Yes",3));
-
- else if (!strnicmp(line,"WorkbenchToFront",16))
- WBToFront = (!strnicmp(ptr,"Yes",3));
-
- else if (!strnicmp(line,"UseCmdClearKludge",17))
- UseCmdClearKludge = (!strnicmp(ptr,"Yes",3));
-
- else if (!strnicmp(line,"PubScreenName",13))
- PubScreenName = strdup(ptr);
-
- else if (!strnicmp(line,"Shell",5)) {
- if (Shell) free(Shell);
- Shell = strdup(ptr);
- }
- else if (!strnicmp(line,"PipeDefault",11))
- PipeDefault = strdup(ptr);
-
- }
- }
- fclose(fp);
-
- if (!SendmailVersion || !PrefixString || !RealName || !ReceivedFolder) {
- fprintf(stderr,"elm: %s incomplete\n",ELM_RC);
- return FALSE;
- }
-
- return TRUE;
- }
-
-
-
- char *
- firstnwsp(char *s)
- {
- while(*s!='\0' && *s!=' ' && *s!='\t')
- s++;
- while((*s != '\0') && (*s == ' ' || *s == '\t'))
- s++;
- return s;
- }
-
-
-
- BOOL
- getline(FILE *fp,char *s,long *p)
- {
- *p=ftell(fp);
- s[MAX_LINELENGTH-1] = '\n';
- if (fgets(s,MAX_LINELENGTH-1,fp)) {
- *strchr(s,'\n')='\0';
- return(TRUE);
- }
- return(FALSE);
- }
-
-
-
- void
- removeCR(char *s)
- {
- if (s=strchr(s,'\n'))
- *s='\0';
- }
-
-