~ubuntu-branches/ubuntu/utopic/edbrowse/utopic

« back to all changes in this revision

Viewing changes to fetchmail.c

  • Committer: Bazaar Package Importer
  • Author(s): Kapil Hari Paranjape
  • Date: 2007-12-05 10:39:04 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20071205103904-zr3kzzu0ym6stg16
Tags: 3.3.1-1
* New upstream version (3.3.1).
  - Messages have been internationalised.
  - Supports LANG environment variable.
  - Includes man page.
* Incorporate upstream man page:
  - debian/rules: Add rule to install upstream man page.
  - debian/edbrowse.1: Not required. Removed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
102
102
                if(ipmask)
103
103
                    ip &= ipmask;
104
104
                if(nipblack == MAXIPBLACK)
105
 
                    errorPrint("1too many ip addresses in blacklist, limit %d",
106
 
                       MAXIPBLACK);
 
105
                    i_printfExit(MSG_ManyIP, MAXIPBLACK);
107
106
                ipblacklist[nipblack] = ip;
108
107
                ipblackmask[nipblack] = ipmask;
109
108
                ipblackcomp[nipblack] = (dotstop == '!');
168
167
    int l;
169
168
    char *p;
170
169
    while(true) {
171
 
        printf("filename: ");
 
170
        i_printf(MSG_FileName);
172
171
        if(defname)
173
172
            printf("[%s] ", defname);
174
173
        if(!fgets(buf, sizeof (buf), stdin))
187
186
        } else
188
187
            defname = 0;
189
188
        if(isnew && fileTypeByName(p, false)) {
190
 
            printf("Sorry, file %s already exists.\n", p);
 
189
            i_printf(MSG_FileExists, p);
191
190
            defname = 0;
192
191
            continue;
193
192
        }
195
194
    }
196
195
}                               /* getFileName */
197
196
 
 
197
static bool ignoreImages;
 
198
 
198
199
static void
199
200
writeAttachment(struct MHINFO *w)
200
201
{
201
202
    const char *atname;
202
 
    if(ismc && w->atimage)
 
203
    if((ismc | ignoreImages) && w->atimage)
203
204
        return;                 /* image ignored */
204
205
    if(w->error64 == BAD64)
205
 
        printf("abbreviated ");
 
206
        i_printf(MSG_Abbreviated);
206
207
    if(w->start == w->end) {
207
 
        printf("empty attachment");
 
208
        i_printf(MSG_AttEmpty);
208
209
        if(w->cfn[0])
209
210
            printf(" %s", w->cfn);
210
 
        printf("\n");
 
211
        nl();
211
212
        atname = "x";
212
213
    } else {
213
 
        printf("attachment ");
 
214
        i_printf(MSG_Att);
214
215
        atname = getFileName((w->cfn[0] ? w->cfn : 0), true);
 
216
/* X is like x, but deletes all future images */
 
217
        if(stringEqual(atname, "X")) {
 
218
            atname = "x";
 
219
            ignoreImages = true;
 
220
        }
215
221
    }
216
222
    if(!ismc && stringEqual(atname, "e")) {
217
223
        int cx, svcx = context;
219
225
            if(!sessionList[cx].lw)
220
226
                break;
221
227
        if(cx == MAXSESSION) {
222
 
            printf("no buffers left, atachment discarded");
 
228
            i_printf(MSG_AttNoBuffer);
223
229
        } else {
224
230
            cxSwitch(cx, false);
225
 
            printf("session %d\n", cx);
 
231
            i_printf(MSG_SessionX, cx);
226
232
            if(!addTextToBuffer((pst) w->start, w->end - w->start, 0))
227
 
                printf("could not copy the attachment into buffer %d", cx);
 
233
                i_printf(MSG_AttNoCopy, cx);
228
234
            else if(w->cfn[0])
229
235
                cw->fileName = cloneString(w->cfn);
230
236
            cxSwitch(svcx, false);      /* back to where we were */
232
238
    } else if(!stringEqual(atname, "x")) {
233
239
        int fh = open(atname, O_WRONLY | O_BINARY | O_CREAT | O_TRUNC, 0666);
234
240
        if(fh < 0) {
235
 
            printf("cannot create file %s, attachment is discarded\n", atname);
 
241
            i_printf(MSG_AttNoSave, atname);
236
242
            if(ismc)
237
243
                exit(1);
238
244
        } else {
239
245
            int nb = w->end - w->start;
240
246
            if(write(fh, w->start, nb) < nb) {
241
 
                printf("cannot write to file %s, attachment is discarded\n");
 
247
                i_printf(MSG_AttNoWrite, atname);
242
248
                if(ismc)
243
249
                    exit(1);
244
250
            }
279
285
 
280
286
    if(!isInteractive) {
281
287
        if(!zapMail)
282
 
            errorPrint
283
 
               ("1fetchmail client is interactive, and cannot run in the background");
 
288
            i_printfExit(MSG_FetchNotBackgnd);
284
289
    }
285
290
 
286
291
    if(!mailDir)
287
 
        errorPrint("1mailbox directory not specified in your .ebrc file");
 
292
        i_printfExit(MSG_NoMailDir);
288
293
    if(chdir(mailDir))
289
 
        errorPrint("1Cannot change directory to %s", mailDir);
 
294
        i_printfExit(MSG_NoDirChange, mailDir);
290
295
 
291
296
    if(!loadAddressBook())
292
297
        showErrorAbort();
296
301
    if(!serverGetLine())
297
302
        showErrorAbort();
298
303
    if(memcmp(serverLine, "+OK ", 4))
299
 
        errorPrint("1Unexpected pop3 introduction <%s>", serverLine);
 
304
        i_printfExit(MSG_BadPopIntro, serverLine);
300
305
    sprintf(serverLine, "user %s%s", login, eol);
301
306
    serverPutGet(serverLine);
302
307
    if(pass) {                  /* I think this is always required */
304
309
        serverPutGet(serverLine);
305
310
    }                           /* password */
306
311
    if(memcmp(serverLine, "+OK", 3))
307
 
        errorPrint("1Could not complete the pop3 login/password sequence <%s>",
308
 
           serverLine);
 
312
        i_printfExit(MSG_PopNotComplete, serverLine);
309
313
 
310
314
/* How many mail messages? */
311
315
    serverPutGet("stat\r\n");
312
316
    if(memcmp(serverLine, "+OK ", 4))
313
 
        errorPrint("1Could not obtain status information on your mailbox <%s>",
314
 
           serverLine);
 
317
        i_printfExit(MSG_NoStatusMailBox, serverLine);
315
318
    nmsgs = atoi(serverLine + 4);
316
319
    if(!nmsgs) {
317
 
        printf("no mail\n");
 
320
        i_puts(MSG_NoMail);
318
321
        serverClose();
319
322
        exit(0);
320
323
    }
325
328
/* the conect will drop when the program exits */
326
329
    }
327
330
 
328
 
    printf("%d messages\n", nmsgs);
 
331
    i_printf(MSG_MessagesX, nmsgs);
329
332
    if(zapMail && nmsgs > 300)
330
333
        nmsgs = 300;
331
334
 
366
369
            while(true) {
367
370
                int nr = tcp_read(mssock, retrbuf, sizeof (retrbuf));
368
371
                if(nr <= 0)
369
 
                    errorPrint
370
 
                       ("1error reading message from the server, errno %d",
371
 
                       errno);
 
372
                    i_printfExit(MSG_ErrorReadMess, errno);
372
373
                if(retr1) {
373
374
/* add null, to make it easy to print the error message, if necessary */
374
375
                    if(nr < sizeof (retrbuf))
375
376
                        retrbuf[nr] = 0;
376
377
                    if(memcmp(retrbuf, "+OK", 3))
377
 
                        errorPrint("cannot fetch mail message %d <%s>", m,
378
 
                           retrbuf);
 
378
                        i_printfExit(MSG_ErrorFetchMess, m, retrbuf);
379
379
                    j = 3;
380
380
                    while(retrbuf[j] != '\n')
381
381
                        ++j;
430
430
                    if(*redirect == '-')
431
431
                        ++redirect, key = 'u';
432
432
                    if(stringEqual(redirect, "x"))
433
 
                        puts("junk");
 
433
                        i_puts(MSG_Junk);
434
434
                    else
435
435
                        printf("> %s\n", redirect);
436
436
                } else if((mailIsSpam | mailIsBlack) && spamCan) {
437
437
                    redirect = spamCan;
438
438
                    key = 'u';
439
 
                    printf("spam");
 
439
                    i_printf(MSG_Spam);
440
440
                    if(lastMailInfo->from[0]) {
441
 
                        printf(" from ");
 
441
                        i_printf(MSG_From);
442
442
                        printf("%s", lastMailInfo->from);
443
443
                    } else if(lastMailInfo->reply[0]) {
444
 
                        printf(" from ");
 
444
                        i_printf(MSG_From);
445
445
                        printf("%s", lastMailInfo->reply);
446
446
                    }
447
 
                    printf("\n");
 
447
                    nl();
448
448
                } else if(!nattach &&   /* drop empty mail message */
449
449
                   cw->dol -
450
450
                   (lastMailInfo->subject != 0) -
451
451
                   (lastMailInfo->from != 0) -
452
452
                   (lastMailInfo->reply != 0) <= 1) {
453
453
                    redirect = "x";
454
 
                    printf("empty\n");
 
454
                    i_puts(MSG_Empty);
455
455
                }
456
456
            }
457
457
            if(redirect)
486
486
 
487
487
                        switch (key) {
488
488
                        case 'q':
489
 
                            puts("quit");
 
489
                            i_puts(MSG_Quit);
490
490
                            serverClose();
491
491
                        case 'x':
492
492
                            exit(0);
493
493
                        case 'n':
494
 
                            puts("next");
 
494
                            i_puts(MSG_Next);
495
495
                            goto afterinput;
496
496
                        case 'd':
497
 
                            puts("delete");
 
497
                            i_puts(MSG_Delete);
498
498
                            delflag = true;
499
499
                            goto afterinput;
500
500
                        case 'i':
501
 
                            puts("ip delete");
 
501
                            i_puts(MSG_IPDelete);
502
502
                            if(!cw->iplist || cw->iplist[0] == -1) {
503
503
                                if(passMail)
504
 
                                    puts("-p option disables this feature");
 
504
                                    i_puts(MSG_POption);
505
505
                                else
506
 
                                    puts(ipbFile ? "none" :
507
 
                                       "no blacklist file specified, feature disabled");
 
506
                                    i_puts(ipbFile ? MSG_None :
 
507
                                       MSG_NoBlackList);
508
508
                            } else {
509
509
                                IP32bit addr;
510
510
                                for(k = 0; (addr = cw->iplist[k]) != NULL_IP;
522
522
                            goto afterinput;
523
523
                        case 'j':
524
524
                        case 'J':
525
 
                            puts("junk");
 
525
                            i_puts(MSG_Junk);
526
526
                            if(!junkSubject(lastMailInfo->subject, key))
527
527
                                continue;
528
528
                            delflag = true;
529
529
                            goto afterinput;
530
530
                        case ' ':
531
531
                            if(displine > cw->dol)
532
 
                                puts("end of message");
 
532
                                i_puts(MSG_EndMessage);
533
533
                            goto nextpage;
534
534
                        case '?':
535
 
                            printf("?\tprint this help message.\n\
536
 
q\tquit this program.\n\
537
 
x\texit without changing anything on the mail server.\n\
538
 
space\tread more of this mail message.\n\
539
 
n\tmove on to the next mail message.\n\
540
 
d\tdelete this message.\n\
541
 
j\tjunk this subject for ten days.\n\
542
 
J\tjunk this subject for a year.\n\
543
 
w\twrite this message to a file and delete it.\n\
544
 
k\tkeep this message in a file, but don't delete it.\n\
545
 
u\twrite this message unformatted to a file, and delete it.\n");
 
535
                            i_puts(MSG_MailHelp);
546
536
                            continue;
547
537
                        case 'k':
548
538
                        case 'w':
549
539
                        case 'u':
550
540
                            break;
551
541
                        default:
552
 
                            puts("not yet implemented");
 
542
                            i_puts(MSG_NYI);
553
543
                            continue;
554
544
                        }       /* switch */
555
545
                    }
569
559
                           open(atname, O_WRONLY | O_TEXT | O_CREAT | O_APPEND,
570
560
                           0666);
571
561
                        if(fh < 0) {
572
 
                            printf("cannot create file %s\n", atname);
 
562
                            i_printf(MSG_NoCreate, atname);
573
563
                            goto savemail;
574
564
                        }
575
565
                        if(exists)
579
569
                        if(key == 'u' || unformatMail) {
580
570
                            if(write(fh, exact, exact_l) < exact_l) {
581
571
                              badsave:
582
 
                                printf("cannot write to file %s\n", atname);
 
572
                                i_printf(MSG_NoWrite, atname);
583
573
                                close(fh);
584
574
                                goto savemail;
585
575
                            }
600
590
                                writeAttachments(lastMailInfo);
601
591
                        }       /* unformat or format */
602
592
                        if(atname != spamCan) {
603
 
                            printf("mail save, %d bytes", fsize);
 
593
                            i_printf(MSG_MailSaved, fsize);
604
594
                            if(exists)
605
 
                                printf(" appended");
606
 
                            printf("\n");
 
595
                                i_printf(MSG_Appended);
 
596
                            nl();
607
597
                        }
608
598
                    }           /* saving to a real file */
609
599
                    goto afterinput;
621
611
            if(!serverPutLine(serverLine))
622
612
                showErrorAbort();
623
613
            if(!serverGetLine())
624
 
                errorPrint("1Sorry, you took too long; mail server hung up.");
 
614
                i_printfExit(MSG_MailTimeOver);
625
615
            if(memcmp(serverLine, "+OK", 3))
626
 
                errorPrint("1unable to delete message <%s>", serverLine);
 
616
                i_printfExit(MSG_UnableDelMail, serverLine);
627
617
        }
628
618
        /* deleted */
629
619
        nzFree(exact);
714
704
            continue;
715
705
        if(*q++ != ':')
716
706
            continue;
717
 
        for(n = 0; mhwords[n]; ++n)
718
 
            if(memEqualCI(mhwords[n], p, q - p))
719
 
                break;
720
 
        if(mhwords[n])
 
707
/* X-Whatever is a mail header word */
 
708
        if(q - p >= 8 && p[1] == '-' && toupper(p[0]) == 'X') {
721
709
            ++k;
 
710
        } else {
 
711
            for(n = 0; mhwords[n]; ++n)
 
712
                if(memEqualCI(mhwords[n], p, q - p))
 
713
                    break;
 
714
            if(mhwords[n])
 
715
                ++k;
 
716
        }
722
717
        if(k >= 4 && k * 2 >= j)
723
718
            return true;
724
719
    }                           /* loop over lines */
759
754
        if(equals) {
760
755
            if(c == '=')
761
756
                continue;
762
 
            runningError("unexpected characters after the encoded attachment");
 
757
            runningError(MSG_AttAfterChars);
763
758
            w->error64 = EXTRA64;
764
759
            break;
765
760
        }
769
764
        }
770
765
        val = unb64(c);
771
766
        if(val & 64) {
772
 
            runningError("invalid characters in the encoded attachment");
 
767
            runningError(MSG_AttBad64);
773
768
            w->error64 = BAD64;
774
769
            break;
775
770
        }
817
812
        *r++ = '=';
818
813
    }
819
814
    w->end = r;
 
815
    *r = 0;
820
816
}                               /* unpackQP */
821
817
 
822
818
/* Look for the name of the attachment and boundary */
1123
1119
    }
1124
1120
 
1125
1121
    if(debugLevel >= 5) {
1126
 
        printf("mail header analyzed\n");
 
1122
        puts("mail header analyzed");
1127
1123
        printf("subject: %s\n", w->subject);
1128
1124
        printf("from: %s\n", w->from);
1129
1125
        printf("date: %s\n", w->date);
1523
1519
    struct MHINFO *w, *v;
1524
1520
    nattach = nimages = 0;
1525
1521
    firstAttach = 0;
1526
 
    mailIsHtml = mailIsSpam = false;
 
1522
    mailIsHtml = mailIsSpam = ignoreImages = false;
1527
1523
    fm = initString(&fm_l);
1528
1524
    w = headerGlean(buf, buf + strlen(buf));
1529
1525
    mailIsHtml = (mailTextType(w) == CT_HTML);