~ubuntu-branches/debian/stretch/alpine/stretch

« back to all changes in this revision

Viewing changes to pith/newmail.c

  • Committer: Bazaar Package Importer
  • Author(s): Asheesh Laroia
  • Date: 2010-10-03 15:31:55 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20101003153155-2exypc96j1e8tw0p
Tags: 2.02-1
* New upstream release, based on re-alpine project
* Updated debian/copyright to reflect this fact
* re-alpine removed the non-free from the tarball, so now
  we do not repack the upstream tarball. (Yay!)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#if !defined(lint) && !defined(DOS)
2
 
static char rcsid[] = "$Id: newmail.c 1113 2008-07-14 18:01:54Z hubert@u.washington.edu $";
 
2
static char rcsid[] = "$Id: newmail.c 1266 2009-07-14 18:39:12Z hubert@u.washington.edu $";
3
3
#endif
4
4
 
5
5
/*
39
39
/*
40
40
 * Hooks for various stuff
41
41
 */
 
42
void    (*pith_opt_newmail_announce)(MAILSTREAM *, long, long);
42
43
void    (*pith_opt_newmail_check_cue)(int);
43
44
void    (*pith_opt_checkpoint_cue)(int);
44
45
void    (*pith_opt_icon_text)(char *, int);
45
46
 
46
47
 
47
 
/*
48
 
 * Internal prototypes
49
 
 */
50
 
void new_mail_win_mess(MAILSTREAM *, long);
51
 
void new_mail_mess(MAILSTREAM *, long, long, int);
52
48
void fixup_flags(MAILSTREAM *, MSGNO_S *);
53
49
int  check_point(MAILSTREAM *, CheckPointTime, int);
54
 
void newmailfifo(int, char *, char *, char *);
55
50
 
56
51
 
57
52
/*----------------------------------------------------------------------
487
482
            rv += (t_nm_count = sp_new_mail_count(m));
488
483
            sp_set_new_mail_count(m, 0L);
489
484
 
490
 
            if(flags & NM_STATUS_MSG){
 
485
            if((flags & NM_STATUS_MSG) && pith_opt_newmail_announce){
491
486
                for(n = m->nmsgs; n > 1L; n--)
492
487
                  if(!get_lflag(m, NULL, n, MN_EXLD))
493
488
                    break;
494
 
#ifdef _WINDOWS
495
 
                if(mswin_newmailwinon())
496
 
                  new_mail_win_mess(m, t_nm_count);
497
 
#elif !defined(DOS) && !defined(OS2) && !defined(LEAVEOUTFIFO)
498
 
                if(ps_global->VAR_FIFOPATH)
499
 
                  new_mail_win_mess(m, t_nm_count);
500
 
#endif
501
 
                if(n){
502
 
                    new_mail_mess(m, sp_mail_since_cmd(m), n, 0);
503
 
                    new_mail_was_announced++;
504
 
                }
 
489
 
 
490
                (*pith_opt_newmail_announce)(m, n, t_nm_count);
 
491
 
 
492
                if(n)
 
493
                  new_mail_was_announced++;
505
494
            }
506
495
        }
507
496
 
542
531
                sp_set_new_mail_count(m, 0L);
543
532
 
544
533
                /* messages only for user's streams */
545
 
                if(flags & NM_STATUS_MSG && sp_flagged(m, SP_LOCKED)
 
534
                if(flags & NM_STATUS_MSG
 
535
                   && pith_opt_newmail_announce
 
536
                   && sp_flagged(m, SP_LOCKED)
546
537
                   && sp_flagged(m, SP_USERFLDR)){
547
538
                    for(n = m->nmsgs; n > 1L; n--)
548
539
                      if(!get_lflag(m, NULL, n, MN_EXLD))
549
540
                        break;
550
 
#ifdef _WINDOWS
551
 
                    if(mswin_newmailwinon())
552
 
                      new_mail_win_mess(m, t_nm_count);
553
 
#elif !defined(DOS) && !defined(OS2) && !defined(LEAVEOUTFIFO)
554
 
                    if(ps_global->VAR_FIFOPATH)
555
 
                      new_mail_win_mess(m, t_nm_count);
556
 
#endif
557
 
                    if(n){
558
 
                        new_mail_mess(m, sp_mail_since_cmd(m), n, 0);
559
 
                        new_mail_was_announced++;
560
 
                    }
 
541
 
 
542
                    (*pith_opt_newmail_announce)(m, n, t_nm_count);
 
543
 
 
544
                    if(n)
 
545
                      new_mail_was_announced++;
561
546
                }
562
547
            }
563
548
 
597
582
 
598
583
 
599
584
/*
600
 
 * alert for each new message individually.  new_mail_mess lumps 
601
 
 * messages together, we call new_mail_mess with 1 message at a time.
602
 
 * This is currently for PC-Pine new mail window, but could probably
603
 
 * be used more generally.
604
 
 *      stream - new mail stream
605
 
 *      number - number of new messages to alert for
606
 
 */
607
 
void
608
 
new_mail_win_mess(MAILSTREAM *stream, long int number)
609
 
{
610
 
    int n, i;
611
 
    MESSAGECACHE *mc;
612
 
 
613
 
    if(!stream)
614
 
      return;
615
 
 
616
 
    /* 
617
 
     * spare6, or MN_STMP, should be safe to use for now, we
618
 
     * just want to set which messages to alert about before
619
 
     * going to c-client.
620
 
     */
621
 
    for(n = stream->nmsgs, i = 0; n > 1L && i < number; n--){
622
 
        if(!get_lflag(stream, NULL, n, MN_EXLD)){
623
 
            mc = mail_elt(stream, n);
624
 
            if(mc)
625
 
              mc->spare6 = 1;
626
 
 
627
 
            if(++i == number)
628
 
              break;
629
 
        }
630
 
        else{
631
 
            mc = mail_elt(stream, n);
632
 
            if(mc)
633
 
              mc->spare6 = 0;
634
 
        }
635
 
    }
636
 
    /* 
637
 
     * Here n is the first new message we want to notify about.
638
 
     * spare6 will tell us which ones to use.  We set spare6
639
 
     * in case of new mail or expunge that could happen when
640
 
     * we mail_fetchstructure in new_mail_mess.
641
 
     */
642
 
    for(; n <= stream->nmsgs; n++)
643
 
      if(n > 0L && (mc = mail_elt(stream, n)) && mc->spare6){
644
 
          mc->spare6 = 0;
645
 
          new_mail_mess(stream, 1, n, 1);
646
 
      }
647
 
}
648
 
 
649
 
 
650
 
/*----------------------------------------------------------------------
651
 
     Format and queue a "new mail" message
652
 
 
653
 
  Args: stream     -- mailstream on which a mail has arrived
654
 
        number     -- number of new messages since last command
655
 
        max_num    -- The number of messages now on stream
656
 
        for_new_mail_win -- for separate new mail window (curr. PC-Pine)
657
 
 
658
 
 Not too much worry here about the length of the message because the
659
 
status_message code will fit what it can on the screen and truncation on
660
 
the right is about what we want which is what will happen.
661
 
  ----*/
662
 
void
663
 
new_mail_mess(MAILSTREAM *stream, long int number, long int max_num, int for_new_mail_win)
664
 
{
665
 
    char      subject[MAILTMPLEN+1], subjtext[MAILTMPLEN+1], from[MAILTMPLEN+1],
666
 
             *folder = NULL, intro[MAILTMPLEN+1];
667
 
    ENVELOPE *e = NULL;
668
 
 
669
 
    if(stream)
670
 
      e = pine_mail_fetchstructure(stream, max_num, NULL);
671
 
 
672
 
    if(stream){
673
 
        if(sp_flagged(stream, SP_INBOX))
674
 
          folder = NULL;
675
 
        else{
676
 
            folder = STREAMNAME(stream);
677
 
            if(folder[0] == '?' && folder[1] == '\0')
678
 
              folder = NULL;
679
 
        }
680
 
    }
681
 
 
682
 
    format_new_mail_msg(folder, number, e, intro, from, subject, subjtext, sizeof(subject));
683
 
 
684
 
    if(!for_new_mail_win)
685
 
      q_status_message5(SM_ASYNC | SM_DING, 0, 60,
686
 
                      "%s%s%s%.80s%.80s", intro,
687
 
                      from ? ((number > 1L) ? " Most recent f" : " F") : "",
688
 
                      from ? "rom " : "",
689
 
                      from ? from : "",
690
 
                      subjtext);
691
 
#if (!defined(DOS) && !defined(OS2) && !defined(LEAVEOUTFIFO)) || defined(_WINDOWS)
692
 
    else {
693
 
        int is_us = 0;
694
 
        ADDRESS *tadr;
695
 
 
696
 
        if(e)
697
 
          for(tadr = e->to; tadr; tadr = tadr->next)
698
 
            if(address_is_us(tadr, ps_global)){
699
 
                is_us = 1;
700
 
                break;
701
 
            }
702
 
#ifdef _WINDOWS
703
 
        mswin_newmailwin(is_us, from, subject, folder);
704
 
#else
705
 
        newmailfifo(is_us, from, subject, folder);
706
 
#endif
707
 
    }
708
 
#endif
709
 
 
710
 
    if(pith_opt_icon_text){
711
 
        if(F_ON(F_ENABLE_XTERM_NEWMAIL, ps_global)
712
 
           && F_ON(F_ENABLE_NEWMAIL_SHORT_TEXT, ps_global)){
713
 
            long inbox_nm;
714
 
            if(!sp_flagged(stream, SP_INBOX) 
715
 
               && (inbox_nm = sp_mail_since_cmd(sp_inbox_stream()))){
716
 
                snprintf(tmp_20k_buf, SIZEOF_20KBUF, "[%ld, %ld] %s",
717
 
                         inbox_nm > 1L ? inbox_nm : 1L,
718
 
                         number > 1L ? number: 1L,
719
 
                         ps_global->pine_name);
720
 
            }
721
 
            else
722
 
              snprintf(tmp_20k_buf, SIZEOF_20KBUF, "[%ld] %s", number > 1L ? number: 1L,
723
 
                       ps_global->pine_name);
724
 
        }
725
 
        else
726
 
          snprintf(tmp_20k_buf, SIZEOF_20KBUF, "%s%s%s%.80s", intro,
727
 
                   from ? ((number > 1L) ? " Most recent f" : " F") : "",
728
 
                   from ? "rom " : "",
729
 
                   from ? from : "");
730
 
 
731
 
        (*pith_opt_icon_text)(tmp_20k_buf, IT_NEWMAIL);
732
 
    }
733
 
}
734
 
 
735
 
 
736
 
/*
737
585
 * format_new_mail_msg - actual work of generating intro,
738
586
 *                       from, subject and expanded subject
739
587
 */
1092
940
          sp_set_mail_since_cmd(m, 0L);
1093
941
    }
1094
942
}
1095
 
 
1096
 
 
1097
 
#if !defined(DOS) && !defined(OS2) && !defined(LEAVEOUTFIFO)
1098
 
static char *fifoname = NULL;
1099
 
static int   fifoopenerrmsg = 0;
1100
 
static int   fifofd = -1;
1101
 
static int   fifoheader = 0;
1102
 
 
1103
 
void
1104
 
init_newmailfifo(char *fname)
1105
 
{
1106
 
    if(fifoname)
1107
 
      close_newmailfifo();
1108
 
 
1109
 
    if(!(fname && *fname))
1110
 
      return;
1111
 
 
1112
 
    if(!fifoname){
1113
 
        if(mkfifo(fname, 0600) == -1){
1114
 
            q_status_message2(SM_ORDER,3,3,
1115
 
                              "Can't create NewMail FIFO \"%s\": %s",
1116
 
                              fname, error_description(errno));
1117
 
            return;
1118
 
        }
1119
 
        else
1120
 
          q_status_message1(SM_ORDER,0,3, "NewMail FIFO: \"%s\"", fname);
1121
 
 
1122
 
        fifoname = cpystr(fname);
1123
 
    }
1124
 
}
1125
 
 
1126
 
 
1127
 
void
1128
 
close_newmailfifo(void)
1129
 
{
1130
 
    if(fifoname){
1131
 
        if(fifofd >= 0)
1132
 
          (void) close(fifofd);
1133
 
 
1134
 
        if(*fifoname)
1135
 
          our_unlink(fifoname);
1136
 
 
1137
 
        fs_give((void **) &fifoname);
1138
 
    }
1139
 
 
1140
 
    fifoheader = 0;
1141
 
    fifoname = NULL;
1142
 
    fifofd = -1;
1143
 
    fifoopenerrmsg = 0;
1144
 
}
1145
 
 
1146
 
 
1147
 
void
1148
 
newmailfifo(int is_us, char *from, char *subject, char *folder)
1149
 
{
1150
 
    char buf[MAX_SCREEN_COLS+1], buf2[MAX_SCREEN_COLS+1];
1151
 
    char buf3[MAX_SCREEN_COLS+1], buf4[MAX_SCREEN_COLS+1];
1152
 
 
1153
 
    if(!(fifoname && *fifoname)){
1154
 
        if(fifoname)
1155
 
          close_newmailfifo();
1156
 
 
1157
 
        return;
1158
 
    }
1159
 
 
1160
 
    if(fifofd < 0){
1161
 
        fifofd = our_open(fifoname, O_WRONLY | O_NONBLOCK | O_BINARY, 0600);
1162
 
        if(fifofd < 0){
1163
 
            if(!fifoopenerrmsg){
1164
 
                if(errno == ENXIO)
1165
 
                  q_status_message2(SM_ORDER,0,3, "Nothing reading \"%s\": %s",
1166
 
                                    fifoname, error_description(errno));
1167
 
                else
1168
 
                  q_status_message2(SM_ORDER,0,3, "Can't open \"%s\": %s",
1169
 
                                    fifoname, error_description(errno));
1170
 
 
1171
 
                fifoopenerrmsg++;
1172
 
            }
1173
 
 
1174
 
            return;
1175
 
        }
1176
 
    }
1177
 
 
1178
 
    if(fifofd >= 0){
1179
 
        int width;
1180
 
        int fromlen, subjlen, foldlen;
1181
 
 
1182
 
        width = MIN(MAX(20, ps_global->nmw_width), MAX_SCREEN_COLS);
1183
 
 
1184
 
        foldlen = .18 * width;
1185
 
        foldlen = MAX(5, foldlen);
1186
 
        fromlen = .28 * width;
1187
 
        subjlen = width - 2 - foldlen - fromlen;
1188
 
 
1189
 
        if(!fifoheader){
1190
 
            time_t now;
1191
 
            char *tmtxt;
1192
 
 
1193
 
            now = time((time_t *) 0);
1194
 
            tmtxt = ctime(&now);
1195
 
            if(!tmtxt)
1196
 
              tmtxt = "";
1197
 
 
1198
 
            snprintf(buf, sizeof(buf), "New Mail window started at %.*s\n",
1199
 
                    MIN(100, strlen(tmtxt)-1), tmtxt);
1200
 
            (void) write(fifofd, buf, strlen(buf));
1201
 
 
1202
 
            snprintf(buf, sizeof(buf), "  %-*s%-*s%-*s\n",
1203
 
                    fromlen, "From:",
1204
 
                    subjlen, "Subject:",
1205
 
                    foldlen, "Folder:");
1206
 
            (void) write(fifofd, buf, strlen(buf));
1207
 
 
1208
 
            snprintf(buf, sizeof(buf), "%-*.*s\n", width, width, repeat_char(width, '-'));
1209
 
            (void) write(fifofd, buf, strlen(buf));
1210
 
 
1211
 
            fifoheader++;
1212
 
        }
1213
 
 
1214
 
        snprintf(buf, sizeof(buf), "%s %-*.*s %-*.*s %-*.*s\n", is_us ? "+" : " ",
1215
 
                fromlen - 1, fromlen - 1,
1216
 
                short_str(from ? from : "", buf2, sizeof(buf2), fromlen-1, EndDots),
1217
 
                subjlen - 1, subjlen - 1,
1218
 
                short_str(subject ? subject : "(no subject)",
1219
 
                          buf3, sizeof(buf3), subjlen-1, EndDots),
1220
 
                foldlen, foldlen,
1221
 
                short_str(folder ? folder : "INBOX", buf4, sizeof(buf4), foldlen, FrontDots));
1222
 
        (void) write(fifofd, buf, strlen(buf));
1223
 
    }
1224
 
}
1225
 
#endif