40
40
* Hooks for various stuff
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);
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 *);
57
52
/*----------------------------------------------------------------------
487
482
rv += (t_nm_count = sp_new_mail_count(m));
488
483
sp_set_new_mail_count(m, 0L);
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))
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);
502
new_mail_mess(m, sp_mail_since_cmd(m), n, 0);
503
new_mail_was_announced++;
490
(*pith_opt_newmail_announce)(m, n, t_nm_count);
493
new_mail_was_announced++;
542
531
sp_set_new_mail_count(m, 0L);
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))
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);
558
new_mail_mess(m, sp_mail_since_cmd(m), n, 0);
559
new_mail_was_announced++;
542
(*pith_opt_newmail_announce)(m, n, t_nm_count);
545
new_mail_was_announced++;
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
608
new_mail_win_mess(MAILSTREAM *stream, long int number)
617
* spare6, or MN_STMP, should be safe to use for now, we
618
* just want to set which messages to alert about before
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);
631
mc = mail_elt(stream, n);
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.
642
for(; n <= stream->nmsgs; n++)
643
if(n > 0L && (mc = mail_elt(stream, n)) && mc->spare6){
645
new_mail_mess(stream, 1, n, 1);
650
/*----------------------------------------------------------------------
651
Format and queue a "new mail" message
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)
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.
663
new_mail_mess(MAILSTREAM *stream, long int number, long int max_num, int for_new_mail_win)
665
char subject[MAILTMPLEN+1], subjtext[MAILTMPLEN+1], from[MAILTMPLEN+1],
666
*folder = NULL, intro[MAILTMPLEN+1];
670
e = pine_mail_fetchstructure(stream, max_num, NULL);
673
if(sp_flagged(stream, SP_INBOX))
676
folder = STREAMNAME(stream);
677
if(folder[0] == '?' && folder[1] == '\0')
682
format_new_mail_msg(folder, number, e, intro, from, subject, subjtext, sizeof(subject));
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") : "",
691
#if (!defined(DOS) && !defined(OS2) && !defined(LEAVEOUTFIFO)) || defined(_WINDOWS)
697
for(tadr = e->to; tadr; tadr = tadr->next)
698
if(address_is_us(tadr, ps_global)){
703
mswin_newmailwin(is_us, from, subject, folder);
705
newmailfifo(is_us, from, subject, folder);
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)){
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);
722
snprintf(tmp_20k_buf, SIZEOF_20KBUF, "[%ld] %s", number > 1L ? number: 1L,
723
ps_global->pine_name);
726
snprintf(tmp_20k_buf, SIZEOF_20KBUF, "%s%s%s%.80s", intro,
727
from ? ((number > 1L) ? " Most recent f" : " F") : "",
731
(*pith_opt_icon_text)(tmp_20k_buf, IT_NEWMAIL);
737
585
* format_new_mail_msg - actual work of generating intro,
738
586
* from, subject and expanded subject
1092
940
sp_set_mail_since_cmd(m, 0L);
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;
1104
init_newmailfifo(char *fname)
1107
close_newmailfifo();
1109
if(!(fname && *fname))
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));
1120
q_status_message1(SM_ORDER,0,3, "NewMail FIFO: \"%s\"", fname);
1122
fifoname = cpystr(fname);
1128
close_newmailfifo(void)
1132
(void) close(fifofd);
1135
our_unlink(fifoname);
1137
fs_give((void **) &fifoname);
1148
newmailfifo(int is_us, char *from, char *subject, char *folder)
1150
char buf[MAX_SCREEN_COLS+1], buf2[MAX_SCREEN_COLS+1];
1151
char buf3[MAX_SCREEN_COLS+1], buf4[MAX_SCREEN_COLS+1];
1153
if(!(fifoname && *fifoname)){
1155
close_newmailfifo();
1161
fifofd = our_open(fifoname, O_WRONLY | O_NONBLOCK | O_BINARY, 0600);
1163
if(!fifoopenerrmsg){
1165
q_status_message2(SM_ORDER,0,3, "Nothing reading \"%s\": %s",
1166
fifoname, error_description(errno));
1168
q_status_message2(SM_ORDER,0,3, "Can't open \"%s\": %s",
1169
fifoname, error_description(errno));
1180
int fromlen, subjlen, foldlen;
1182
width = MIN(MAX(20, ps_global->nmw_width), MAX_SCREEN_COLS);
1184
foldlen = .18 * width;
1185
foldlen = MAX(5, foldlen);
1186
fromlen = .28 * width;
1187
subjlen = width - 2 - foldlen - fromlen;
1193
now = time((time_t *) 0);
1194
tmtxt = ctime(&now);
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));
1202
snprintf(buf, sizeof(buf), " %-*s%-*s%-*s\n",
1204
subjlen, "Subject:",
1205
foldlen, "Folder:");
1206
(void) write(fifofd, buf, strlen(buf));
1208
snprintf(buf, sizeof(buf), "%-*.*s\n", width, width, repeat_char(width, '-'));
1209
(void) write(fifofd, buf, strlen(buf));
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),
1221
short_str(folder ? folder : "INBOX", buf4, sizeof(buf4), foldlen, FrontDots));
1222
(void) write(fifofd, buf, strlen(buf));