root/trunk/splitem.c

Revision 389, 9.6 kB (checked in by heitor.barbieri, 3 weeks ago)

essage first commit

Line 
1/* ======================= splitem: split uupc/e-mail ====================== */
2/*                                                                           */
3/*                                                      A. O. Tardelli       */
4/*                                                      BRM, 01/03/93        */
5/* ========================================================================= */
6
7#include <stdio.h>
8#include <string.h>
9
10#include "cisis.h"      /* CISIS Interface */
11#include "cirun.h"      /* runtime area and defines by AOT */
12
13
14void main(argc,argv)
15int argc;
16char *argv[];
17{
18    char buffer[BUFSIZ+1];
19    char filout[BUFSIZ+1];
20
21    LONGX nmsgs,xmsg,ext;
22    FILE *fpin,*fpout;
23    char *leftp,*outp,*filp,*extp;
24
25    char *dbnp=NULL;
26    RECSTRU *recp;
27    LONGX crec,irec,mfn;
28    char buffup[MAXMFRL+BUFSIZ],*batchp;
29    int emptyline,moveheader,amat;
30    int trace=1,tell=1,notzero=1;
31    int day,month,year,hour,min,sec;
32    char dax[3+1],mox[3+1],buffx[BUFSIZ];
33    char *fstrp="From ";
34    int ismozilla=0;
35
36    if (argc < 3 || argc > 4) {
37        printf("%s",cicopyr("Utility AOT/SPLITEM"));
38        printf("\n");
39        printf("splitem <msgs> <filin> [<pfxout>|isis=<dbn>] \n");
40        printf("\n");
41        printf("msgs        numero maximo de e-mails em cada arquivo de saida\n");
42        printf("filin       nome do arquivo a ser dividido (mailbox) \n");
43        printf("pfxout      prefixo dos arquivos que serao gerados (pfxout.001)\n");
44        printf("\n");
45        printf("isis=<dbn>  write a record to <dbn> (Date/From/To/Cc/Subject)\n");
46        printf("            and the msg in <dbn>.mfn for each input e-mail\n");
47        printf("            (needs <msgs> set to 1, or 0) \n");
48        printf("\n");
49        printf("Ex: splitem 10 mailsent x\n");
50        printf("\n");
51        printf("    grava os 10 primeiros e-mails de mailsent em x.001\n");
52        printf("          os 10 seguintes em x.002\n");
53        printf("          etc\n");
54        printf("\n");
55        exit(1);
56    }
57
58    if (sscanf(argv[1],"%"_LD_,&nmsgs) != 1) {
59        printf("<msgs> invalido: %s\n",argv[1]);
60        exit(1);
61    }
62    /* if (nmsgs < 1) nmsgs=1; */
63
64    filp=argv[2];
65    if ((fpin=fopen(filp,"r+b")) == NULL) {
66        printf("impossivel abrir o arquivo '%s'\n",filp);
67        exit(1);
68    }
69
70    if (argc > 3) {
71        outp=argv[3];
72        if (strncmp(outp,"isis=",5) == 0) {
73            outp+=5; dbnp=outp;
74            if (nmsgs != 0 && nmsgs != 1) {
75                printf("invalid <msgs> for option isis: %s\n",argv[1]);
76                exit(1);
77            }
78            if (nmsgs == 0) notzero=0;
79            trace=0;
80        }
81    }
82    else
83        outp=argv[2];
84
85    if (trace) {
86        printf("+++ numero de e-mails de cada arquivo de saida ...... %"_LD_"\n",nmsgs);
87        printf("+++ nome do arquivo a ser dividido .................. %s\n",filp);
88        printf("+++ prefixo dos arquivos que serao gerados .......... %s\n",outp);
89    }
90
91    strcpy(filout,outp); extp=filout+strlen(outp);
92
93    ext=1;
94    if (notzero) {
95        sprintf(extp,".%03"_LD_,ext);
96        if (trace) printf("+++ gerando arquivo %s...\n",filout);
97        if ((fpout=fopen(filout,"w+b")) == NULL) {
98            printf("impossivel criar o arquivo '%s'\n",filout);
99            exit(1);
100        }
101    }
102    if (dbnp) {
103        if (trace) printf("+++ criando %s...\n",dbnp);
104        recisis0(dbnp);
105        RECORD(crec=nrecs,dbnp,0L);
106        RECORD(irec=nrecs,dbnp,mfn=1L); buffup[0]='\0';
107    }
108
109    leftp=fgets(buffer,BUFSIZ,fpin);
110    if (strlen(buffer)>1) if (buffer[strlen(buffer)-2] == '\r') {
111        buffer[strlen(buffer)-2] = '\n';
112        buffer[strlen(buffer)-1] = '\0';
113        ismozilla=1;
114        fstrp="From - ";
115    }
116    xmsg=0; emptyline=1; moveheader=0;
117
118    while (leftp) {
119#if UUPC
120        if (*buffer == 0x01 && buffer[1] == 0x01) xmsg++;
121#endif
122        /* ^J^JFrom mmori@brm.bireme.br Tue Mar 30 11:06:40 SAT 1999^J */
123        if (emptyline) if (strncmp(buffer,/*"From ",5*/fstrp,strlen(fstrp)) == 0) {
124            if (dbnp) {
125                if (xmsg) {
126                    if (fldupdat(irec,buffup)) fatal("splitem/fldupdat1");
127                    recupdat(crec,irec);
128                    mfn++;
129                }
130                RECORD(irec,dbnp,mfn); RECrc=RCNORMAL; MFRstatus=ACTIVE;
131                buffup[0]='\0'; batchp=buffup; moveheader=1;
132            }
133            xmsg++;
134        }
135        if ((xmsg-1) == nmsgs) {
136            if (notzero) {
137                fclose(fpout);
138                ext++;
139                sprintf(extp,".%03"_LD_,ext);
140                if (trace) printf("+++ gerando arquivo %s...\n",filout);
141                if ((fpout=fopen(filout,"w+b")) == NULL) {
142                    printf("impossivel criar o arquivo '%s'\n",filout);
143                    exit(1);
144                }
145            }
146            xmsg=1;
147        }
148        if ((xmsg-1) == nmsgs) {
149            if (notzero) {
150                if (fputs(buffer,fpout) == EOF) {
151                    printf("*** erro na gravacao de %s\n",filout);
152                    exit(1);
153                }
154            }
155        }
156        if (dbnp) {
157          if (moveheader == 1) {
158                sprintf(batchp,"h10 %d %s",strlen(filout),filout);
159                batchp+=strlen(batchp);
160                sprintf(batchp,"h11 %d %s",strlen(buffer)-1,buffer);
161                batchp+=strlen(batchp);
162                moveheader=2; amat=0;
163          }
164          if (moveheader) {
165              if (buffer[0]=='\n') moveheader=0;
166              if (buffer[0]!=' ') amat=0;
167          }
168          if (moveheader) {
169            if (strncmp(buffer,"Date: ",6) == 0) {
170                sprintf(batchp,"h1 %d %s",strlen(buffer)-1,buffer);
171                batchp+=strlen(batchp);
172                /* Date: Tue, 05 Oct 1999 13:43:56 -0300 */
173                sscanf(buffer+6,"%3c, %d %3c %d %d:%d:%d",
174                               dax,&day,mox,&year,&hour,&min,&sec);
175                month=0;
176                if (strncmp(mox,"Jan",3) == 0) month=1;
177                if (strncmp(mox,"Feb",3) == 0) month=2;
178                if (strncmp(mox,"Mar",3) == 0) month=3;
179                if (strncmp(mox,"Apr",3) == 0) month=4;
180                if (strncmp(mox,"May",3) == 0) month=5;
181                if (strncmp(mox,"Jun",3) == 0) month=6;
182                if (strncmp(mox,"Jul",3) == 0) month=7;
183                if (strncmp(mox,"Aug",3) == 0) month=8;
184                if (strncmp(mox,"Sep",3) == 0) month=9;
185                if (strncmp(mox,"Oct",3) == 0) month=10;
186                if (strncmp(mox,"Nov",3) == 0) month=11;
187                if (strncmp(mox,"Dez",3) == 0) month=12;
188                sprintf(buffx,"%04d%02d%02d %02d%02d%02d",
189                                 year,month,day,hour,min,sec);
190                sprintf(batchp,"h12 %d %s",strlen(buffx),buffx);
191                batchp+=strlen(batchp);
192            }
193            if (strncmp(buffer,"From: ",6) == 0) {
194                sprintf(batchp,"h2 %d %s",strlen(buffer)-1,buffer);
195                batchp+=strlen(batchp);
196            }
197            if (strncmp(buffer,"To: ",4) == 0 || amat==3) {
198                sprintf(batchp,"h3 %d %s",strlen(buffer)-1,buffer);
199                batchp+=strlen(batchp); amat=3;
200            }
201            if (strncmp(buffer,"Cc: ",2) == 0 || amat==4) {
202                sprintf(batchp,"h2 %d %s",strlen(buffer)-1,buffer);
203                batchp+=strlen(batchp); amat=4;
204            }
205            if (strncmp(buffer,"Subject: ",9) == 0) {
206                sprintf(batchp,"h5 %d %s",strlen(buffer)-1,buffer);
207                batchp+=strlen(batchp); amat=5;
208            }
209          }
210        }
211        emptyline=0; if (!buffer[1]) if (buffer[0]=='\n') emptyline=1;
212        leftp=fgets(buffer,BUFSIZ,fpin);
213        if (ismozilla) if (strlen(buffer)>1) if (buffer[strlen(buffer)-2] == '\r') {
214            buffer[strlen(buffer)-2] = '\n';
215            buffer[strlen(buffer)-1] = '\0';
216        }
217    }
218
219    if (dbnp) {
220        if (buffup) {
221            if (fldupdat(irec,buffup)) fatal("splitem/fldupdat2");
222            recupdat(crec,irec);
223        }
224        if (tell) printf("splitem: %"_LD_" records written to %s\n",VMF0nxtmfn(crec)-1,dbnp);
225    }
226    exit(0);
227}
228
229/*
2300........1.........2.........3.........4.........5.........6.........7.........8
23112345678901234567890123456789012345678901234567890123456789012345678901234567890
232Tue Oct  5 13:45:24 SAT 1999
233From spd-l-admin@listas.bireme.br Tue Oct  5 13:45:24 SAT 1999
234Received: from listas.bireme.br (listas.bireme.br [200.6.42.35])
235        by brm.bireme.br (8.9.3/8.9.3) with ESMTP id NAA01462;
236        Tue, 5 Oct 1999 13:45:22 -0300 (SAT)
237Received: from listas.bireme.br (localhost [127.0.0.1])
238        by listas.bireme.br (8.9.1a/8.9.1) with ESMTP id NAA21807;
239        Tue, 5 Oct 1999 13:45:11 -0200
240Received: from brm.bireme.br (brm.bireme.br [200.6.42.33])
241        by listas.bireme.br (8.9.1a/8.9.1) with ESMTP id NAA21798
242        for <spd-l@listas.bireme.br>; Tue, 5 Oct 1999 13:45:10 -0200
243Received: from bireme.br ([200.6.42.94])
244        by brm.bireme.br (8.9.3/8.9.3) with ESMTP id NAA01459;
245        Tue, 5 Oct 1999 13:45:19 -0300 (SAT)
246Message-ID: <37FA2ACC.B1059D79@bireme.br>
247Date: Tue, 05 Oct 1999 13:43:56 -0300
248From: Joao Rodolfo Suarez de Oliveira <jrodolfo@bireme.br>
249X-Mailer: Mozilla 4.7 [en] (Win95; I)
250X-Accept-Language: en
251MIME-Version: 1.0
252To: SPD-1 <spd-l@brm.bireme.br>, Julio Cesar T Takayama <julio@bireme.br>,
253        Silvia <silvia@brm.bireme.br>
254Content-Type: text/plain; charset=us-ascii
255Content-Transfer-Encoding: 7bit
256Subject: [Spd-l] Apresentacoes em PowerPoint do Curso BVS
257Sender: spd-l-admin@listas.bireme.br
258Errors-To: spd-l-admin@listas.bireme.br
259X-Mailman-Version: 1.0rc2
260Precedence: bulk
261List-Id: SPD - Users <spd-l.listas.bireme.br>
262X-BeenThere: spd-l@listas.bireme.br
263Status: RO
264X-Status:
265X-Keywords:
266X-UID: 94
267
268...
269*/
Note: See TracBrowser for help on using the browser.