1 /*@ S-nail - a mail user agent derived from Berkeley Mail.
2 *@ POP3 (RFCs 1939, 2595) client.
4 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
5 * Copyright (c) 2012 - 2016 Steffen (Daode) Nurpmeso <steffen@sdaoden.eu>.
9 * Gunnar Ritter. All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by Gunnar Ritter
22 * and his contributors.
23 * 4. Neither the name of Gunnar Ritter nor the names of his contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY GUNNAR RITTER AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL GUNNAR RITTER OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 #ifndef HAVE_AMALGAMATION
49 #define POP3_ANSWER(RV,ACTIONSTOP) \
50 do if (((RV) = pop3_answer(mp)) == STOP) {\
54 #define POP3_OUT(RV,X,Y,ACTIONSTOP) \
56 if (((RV) = pop3_finish(mp)) == STOP) {\
59 if (options & OPT_VERBVERB)\
62 if (((RV) = swrite(&mp->mb_sock, X)) == STOP) {\
67 static char *_pop3_buf
;
68 static size_t _pop3_bufsize
;
69 static sigjmp_buf _pop3_jmp
;
70 static sighandler_type _pop3_savealrm
;
71 static int _pop3_keepalive
;
72 static int volatile _pop3_lock
;
74 /* Perform entire login handshake */
75 static enum okay
_pop3_login(struct mailbox
*mp
, struct sockconn
*scp
);
77 /* APOP: get greeting credential or NULL */
79 static char * _pop3_lookup_apop_timestamp(char const *bp
);
82 /* Several authentication methods */
84 static enum okay
_pop3_auth_apop(struct mailbox
*mp
,
85 struct sockconn
const *scp
, char const *ts
);
87 static enum okay
_pop3_auth_plain(struct mailbox
*mp
,
88 struct sockconn
const *scp
);
90 static void pop3_timer_off(void);
91 static enum okay
pop3_answer(struct mailbox
*mp
);
92 static enum okay
pop3_finish(struct mailbox
*mp
);
93 static void pop3catch(int s
);
94 static void _pop3_maincatch(int s
);
95 static enum okay
pop3_noop1(struct mailbox
*mp
);
96 static void pop3alarm(int s
);
97 static enum okay
pop3_stat(struct mailbox
*mp
, off_t
*size
, int *cnt
);
98 static enum okay
pop3_list(struct mailbox
*mp
, int n
, size_t *size
);
99 static void pop3_setptr(struct mailbox
*mp
,
100 struct sockconn
const *scp
);
101 static enum okay
pop3_get(struct mailbox
*mp
, struct message
*m
,
103 static enum okay
pop3_exit(struct mailbox
*mp
);
104 static enum okay
pop3_delete(struct mailbox
*mp
, int n
);
105 static enum okay
pop3_update(struct mailbox
*mp
);
108 _pop3_login(struct mailbox
*mp
, struct sockconn
*scp
)
113 enum okey_xlook_mode oxm
;
117 oxm
= ok_blook(v15_compat
) ? OXM_ALL
: OXM_PLAIN
| OXM_U_H_P
;
119 /* Get the greeting, check whether APOP is advertised */
120 POP3_ANSWER(rv
, goto jleave
);
122 ts
= _pop3_lookup_apop_timestamp(_pop3_buf
);
125 /* If not yet secured, can we upgrade to TLS? */
127 if (!scp
->sc_url
.url_needs_tls
&&
128 xok_blook(pop3_use_starttls
, &scp
->sc_url
, oxm
)) {
129 POP3_OUT(rv
, "STLS" NETNL
, MB_COMD
, goto jleave
);
130 POP3_ANSWER(rv
, goto jleave
);
131 if ((rv
= ssl_open(&scp
->sc_url
, &scp
->sc_sock
)) != OKAY
)
135 if (xok_blook(pop3_use_starttls
, &scp
->sc_url
, oxm
)) {
136 n_err(_("No SSL support compiled in\n"));
142 /* Use the APOP single roundtrip? */
144 if (ts
!= NULL
&& !xok_blook(pop3_no_apop
, &scp
->sc_url
, oxm
)) {
145 if ((rv
= _pop3_auth_apop(mp
, scp
, ts
)) != OKAY
) {
149 if (scp
->sc_sock
.s_use_ssl
)
150 ccp
= _("over an encrypted connection");
153 ccp
= _("(unsafe clear text!)");
154 n_err(_("POP3 APOP authentication failed!\n"
155 " Server indicated support.. Set *pop3-no-apop*\n"
156 " for plain text authentication %s\n"), ccp
);
162 rv
= _pop3_auth_plain(mp
, scp
);
170 _pop3_lookup_apop_timestamp(char const *bp
)
173 * A POP3 server which implements the APOP command will include
174 * a timestamp in its banner greeting. The syntax of the timestamp
175 * corresponds to the "msg-id" in [RFC822]
177 * msg-id = "<" addr-spec ">"
178 * addr-spec = local-part "@" domain */
185 if ((cp
= strchr(bp
, '<')) == NULL
)
188 /* xxx What about malformed APOP timestamp (<@>) here? */
189 for (ep
= cp
; *ep
!= '\0'; ++ep
) {
194 else if (*ep
== '>') {
203 tl
= PTR2SIZE(++ep
- cp
);
215 _pop3_auth_apop(struct mailbox
*mp
, struct sockconn
const *scp
, char const *ts
)
217 unsigned char digest
[16];
218 char hex
[MD5TOHEX_SIZE
], *cp
;
225 md5_update(&ctx
, (uc_i
*)n_UNCONST(ts
), strlen(ts
));
226 md5_update(&ctx
, (uc_i
*)scp
->sc_cred
.cc_pass
.s
, scp
->sc_cred
.cc_pass
.l
);
227 md5_final(digest
, &ctx
);
228 md5tohex(hex
, digest
);
230 i
= scp
->sc_cred
.cc_user
.l
;
231 cp
= ac_alloc(5 + i
+ 1 + MD5TOHEX_SIZE
+ sizeof(NETNL
)-1 +1);
233 memcpy(cp
, "APOP ", 5);
234 memcpy(cp
+ 5, scp
->sc_cred
.cc_user
.s
, i
);
237 memcpy(cp
+ i
, hex
, MD5TOHEX_SIZE
);
239 memcpy(cp
+ i
, NETNL
, sizeof(NETNL
));
240 POP3_OUT(rv
, cp
, MB_COMD
, goto jleave
);
241 POP3_ANSWER(rv
, goto jleave
);
249 #endif /* HAVE_MD5 */
252 _pop3_auth_plain(struct mailbox
*mp
, struct sockconn
const *scp
)
258 /* The USER/PASS plain text version */
259 cp
= ac_alloc(n_MAX(scp
->sc_cred
.cc_user
.l
, scp
->sc_cred
.cc_pass
.l
) + 5 +
262 memcpy(cp
, "USER ", 5);
263 memcpy(cp
+ 5, scp
->sc_cred
.cc_user
.s
, scp
->sc_cred
.cc_user
.l
);
264 memcpy(cp
+ 5 + scp
->sc_cred
.cc_user
.l
, NETNL
, sizeof(NETNL
));
265 POP3_OUT(rv
, cp
, MB_COMD
, goto jleave
);
266 POP3_ANSWER(rv
, goto jleave
);
268 memcpy(cp
, "PASS ", 5);
269 memcpy(cp
+ 5, scp
->sc_cred
.cc_pass
.s
, scp
->sc_cred
.cc_pass
.l
);
270 memcpy(cp
+ 5 + scp
->sc_cred
.cc_pass
.l
, NETNL
, sizeof(NETNL
));
271 POP3_OUT(rv
, cp
, MB_COMD
, goto jleave
);
272 POP3_ANSWER(rv
, goto jleave
);
285 if (_pop3_keepalive
> 0) {
287 safe_signal(SIGALRM
, _pop3_savealrm
);
293 pop3_answer(struct mailbox
*mp
)
301 if ((sz
= sgetline(&_pop3_buf
, &_pop3_bufsize
, &blen
, &mp
->mb_sock
)) > 0) {
302 if ((mp
->mb_active
& (MB_COMD
| MB_MULT
)) == MB_MULT
)
304 if (options
& OPT_VERBVERB
)
306 switch (*_pop3_buf
) {
309 mp
->mb_active
&= ~MB_COMD
;
313 mp
->mb_active
= MB_NONE
;
315 (_pop3_buf
[blen
- 1] == NETNL
[0] ||
316 _pop3_buf
[blen
- 1] == NETNL
[1]))
317 _pop3_buf
[--blen
] = '\0';
318 n_err(_("POP3 error: %s\n"), _pop3_buf
);
321 /* If the answer starts neither with '+' nor with '-', it must be part
322 * of a multiline response. Get lines until a single dot appears */
324 while (_pop3_buf
[0] != '.' || _pop3_buf
[1] != NETNL
[0] ||
325 _pop3_buf
[2] != NETNL
[1] || _pop3_buf
[3] != '\0') {
326 sz
= sgetline(&_pop3_buf
, &_pop3_bufsize
, NULL
, &mp
->mb_sock
);
330 mp
->mb_active
&= ~MB_MULT
;
331 if (mp
->mb_active
!= MB_NONE
)
337 mp
->mb_active
= MB_NONE
;
344 pop3_finish(struct mailbox
*mp
)
347 while (mp
->mb_sock
.s_fd
> 0 && mp
->mb_active
!= MB_NONE
)
356 NYD_X
; /* Signal handler */
359 /*n_err_sighdl(_("Interrupt during POP3 operation\n"));*/
360 interrupts
= 2; /* Force "Interrupt" message shall we onintr(0) */
361 siglongjmp(_pop3_jmp
, 1);
363 n_err_sighdl(_("Received SIGPIPE during POP3 operation\n"));
369 _pop3_maincatch(int s
)
371 NYD_X
; /* Signal handler */
374 n_err_sighdl(_("\n(Interrupt -- one more to abort operation)\n"));
377 siglongjmp(_pop3_jmp
, 1);
382 pop3_noop1(struct mailbox
*mp
)
387 POP3_OUT(rv
, "NOOP" NETNL
, MB_COMD
, goto jleave
);
388 POP3_ANSWER(rv
, goto jleave
);
397 sighandler_type
volatile saveint
, savepipe
;
398 NYD_X
; /* Signal handler */
401 if (_pop3_lock
++ == 0) {
403 if ((saveint
= safe_signal(SIGINT
, SIG_IGN
)) != SIG_IGN
)
404 safe_signal(SIGINT
, &_pop3_maincatch
);
405 savepipe
= safe_signal(SIGPIPE
, SIG_IGN
);
406 if (sigsetjmp(_pop3_jmp
, 1)) {
408 safe_signal(SIGINT
, saveint
);
409 safe_signal(SIGPIPE
, savepipe
);
412 if (savepipe
!= SIG_IGN
)
413 safe_signal(SIGPIPE
, pop3catch
);
415 if (pop3_noop1(&mb
) != OKAY
) {
416 safe_signal(SIGINT
, saveint
);
417 safe_signal(SIGPIPE
, savepipe
);
420 safe_signal(SIGINT
, saveint
);
421 safe_signal(SIGPIPE
, savepipe
);
424 alarm(_pop3_keepalive
);
430 pop3_stat(struct mailbox
*mp
, off_t
*size
, int *cnt
)
436 POP3_OUT(rv
, "STAT" NETNL
, MB_COMD
, goto jleave
);
437 POP3_ANSWER(rv
, goto jleave
);
439 for (cp
= _pop3_buf
; *cp
!= '\0' && !spacechar(*cp
); ++cp
)
441 while (*cp
!= '\0' && spacechar(*cp
))
445 *cnt
= (int)strtol(cp
, NULL
, 10);
446 while (*cp
!= '\0' && !spacechar(*cp
))
448 while (*cp
!= '\0' && spacechar(*cp
))
451 *size
= (int)strtol(cp
, NULL
, 10);
458 n_err(_("Invalid POP3 STAT response: %s\n"), _pop3_buf
);
465 pop3_list(struct mailbox
*mp
, int n
, size_t *size
)
467 char o
[LINESIZE
], *cp
;
471 snprintf(o
, sizeof o
, "LIST %u" NETNL
, n
);
472 POP3_OUT(rv
, o
, MB_COMD
, goto jleave
);
473 POP3_ANSWER(rv
, goto jleave
);
475 for (cp
= _pop3_buf
; *cp
!= '\0' && !spacechar(*cp
); ++cp
)
477 while (*cp
!= '\0' && spacechar(*cp
))
479 while (*cp
!= '\0' && !spacechar(*cp
))
481 while (*cp
!= '\0' && spacechar(*cp
))
484 *size
= (size_t)strtol(cp
, NULL
, 10);
491 pop3_setptr(struct mailbox
*mp
, struct sockconn
const *scp
)
497 message
= scalloc(msgCount
+ 1, sizeof *message
);
498 message
[msgCount
].m_size
= 0;
499 message
[msgCount
].m_lines
= 0;
500 dot
= message
; /* (Just do it: avoid crash -- shall i now do ointr(0).. */
502 for (i
= 0; UICMP(z
, i
, <, msgCount
); ++i
) {
503 struct message
*m
= message
+ i
;
504 m
->m_flag
= MUSED
| MNEW
| MNOFROM
| MNEWEST
;
507 m
->m_size
= m
->m_xsize
= 0;
510 for (i
= 0; UICMP(z
, i
, <, msgCount
); ++i
)
511 if (!pop3_list(mp
, i
+ 1, &message
[i
].m_xsize
))
514 /* Force the load of all messages right now */
515 ns
= xok_blook(pop3_bulk_load
, &scp
->sc_url
, OXM_ALL
)
516 ? NEED_BODY
: NEED_HEADER
;
517 for (i
= 0; UICMP(z
, i
, <, msgCount
); ++i
)
518 if (!pop3_get(mp
, message
+ i
, ns
))
522 for (i
= 0; UICMP(z
, i
, <, msgCount
); ++i
) {
523 struct message
*m
= message
+ i
;
526 if ((cp
= hfield1("status", m
)) != NULL
)
527 while (*cp
!= '\0') {
546 pop3_get(struct mailbox
*mp
, struct message
*m
, enum needspec
volatile need
)
548 char o
[LINESIZE
], *line
, *lp
;
549 sighandler_type
volatile saveint
, savepipe
;
550 size_t linesize
, linelen
, size
;
552 int volatile emptyline
;
554 enum okay
volatile rv
;
557 line
= NULL
; /* TODO line pool */
558 saveint
= savepipe
= SIG_IGN
;
560 number
= (int)PTR2SIZE(m
- message
+ 1);
564 if (mp
->mb_sock
.s_fd
< 0) {
565 n_err(_("POP3 connection already closed\n"));
570 if (_pop3_lock
++ == 0) {
572 if ((saveint
= safe_signal(SIGINT
, SIG_IGN
)) != SIG_IGN
)
573 safe_signal(SIGINT
, &_pop3_maincatch
);
574 savepipe
= safe_signal(SIGPIPE
, SIG_IGN
);
575 if (sigsetjmp(_pop3_jmp
, 1))
577 if (savepipe
!= SIG_IGN
)
578 safe_signal(SIGPIPE
, pop3catch
);
582 fseek(mp
->mb_otf
, 0L, SEEK_END
);
583 offset
= ftell(mp
->mb_otf
);
587 snprintf(o
, sizeof o
, "TOP %u 0" NETNL
, number
);
590 snprintf(o
, sizeof o
, "RETR %u" NETNL
, number
);
595 POP3_OUT(rv
, o
, MB_COMD
| MB_MULT
, goto jleave
);
597 if (pop3_answer(mp
) == STOP
) {
598 if (need
== NEED_HEADER
) {
599 /* The TOP POP3 command is optional, so retry with entire message */
608 while (sgetline(&line
, &linesize
, &linelen
, &mp
->mb_sock
) > 0) {
609 if (line
[0] == '.' && line
[1] == NETNL
[0] && line
[2] == NETNL
[1] &&
611 mp
->mb_active
&= ~MB_MULT
;
614 if (line
[0] == '.') {
620 * Need to mask 'From ' lines. This cannot be done properly
621 * since some servers pass them as 'From ' and others as
622 * '>From '. Although one could identify the first kind of
623 * server in principle, it is not possible to identify the
624 * second as '>From ' may also come from a server of the
625 * first type as actual data. So do what is absolutely
626 * necessary only - mask 'From '.
628 * If the line is the first line of the message header, it
629 * is likely a real 'From ' line. In this case, it is just
630 * ignored since it violates all standards.
631 * TODO i have *never* seen the latter?!?!?
634 /* Since we simply copy over data without doing any transfer
635 * encoding reclassification/adjustment we *have* to perform
636 * RFC 4155 compliant From_ quoting here */
637 if (emptyline
&& is_head(lp
, linelen
, FAL0
)) {
638 putc('>', mp
->mb_otf
);
642 if (lp
[linelen
-1] == NETNL
[1] &&
643 (linelen
== 1 || lp
[linelen
-2] == NETNL
[0])) {
644 emptyline
= linelen
<= 2;
646 fwrite(lp
, 1, linelen
- 2, mp
->mb_otf
);
647 putc('\n', mp
->mb_otf
);
651 fwrite(lp
, 1, linelen
, mp
->mb_otf
);
656 /* This is very ugly; but some POP3 daemons don't end a
657 * message with NETNL NETNL, and we need \n\n for mbox format */
658 putc('\n', mp
->mb_otf
);
664 m
->m_block
= mailx_blockof(offset
);
665 m
->m_offset
= mailx_offsetof(offset
);
670 m
->m_content_info
|= CI_HAVE_HEADER
;
673 m
->m_content_info
|= CI_HAVE_HEADER
| CI_HAVE_BODY
;
674 m
->m_xlines
= m
->m_lines
;
675 m
->m_xsize
= m
->m_size
;
685 if (saveint
!= SIG_IGN
)
686 safe_signal(SIGINT
, saveint
);
687 if (savepipe
!= SIG_IGN
)
688 safe_signal(SIGPIPE
, savepipe
);
697 pop3_exit(struct mailbox
*mp
)
702 POP3_OUT(rv
, "QUIT" NETNL
, MB_COMD
, goto jleave
);
703 POP3_ANSWER(rv
, goto jleave
);
710 pop3_delete(struct mailbox
*mp
, int n
)
716 snprintf(o
, sizeof o
, "DELE %u" NETNL
, n
);
717 POP3_OUT(rv
, o
, MB_COMD
, goto jleave
);
718 POP3_ANSWER(rv
, goto jleave
);
725 pop3_update(struct mailbox
*mp
)
728 int dodel
, c
, gotcha
, held
;
731 if (!(pstate
& PS_EDIT
)) {
734 for (m
= message
; PTRCMP(m
, <, message
+ msgCount
); ++m
)
735 if (m
->m_flag
& MBOX
)
742 for (m
= message
; PTRCMP(m
, <, message
+ msgCount
); ++m
) {
743 if (pstate
& PS_EDIT
)
744 dodel
= m
->m_flag
& MDELETED
;
746 dodel
= !((m
->m_flag
& MPRESERVE
) || !(m
->m_flag
& MTOUCH
));
748 pop3_delete(mp
, PTR2SIZE(m
- message
+ 1));
757 dnq
= n_shexp_quote_cp(displayname
, FAL0
);
759 if (gotcha
&& (pstate
& PS_EDIT
)) {
760 printf(_("%s "), dnq
);
761 printf((ok_blook(bsdcompat
) || ok_blook(bsdmsgs
))
762 ? _("complete\n") : _("updated\n"));
763 } else if (held
&& !(pstate
& PS_EDIT
)) {
765 printf(_("Held 1 message in %s\n"), dnq
);
767 printf(_("Held %d messages in %s\n"), held
, dnq
);
778 sighandler_type
volatile saveint
, savepipe
;
779 enum okay
volatile rv
= STOP
;
784 if ((saveint
= safe_signal(SIGINT
, SIG_IGN
)) != SIG_IGN
)
785 safe_signal(SIGINT
, &_pop3_maincatch
);
786 savepipe
= safe_signal(SIGPIPE
, SIG_IGN
);
787 if (sigsetjmp(_pop3_jmp
, 1) == 0) {
788 if (savepipe
!= SIG_IGN
)
789 safe_signal(SIGPIPE
, pop3catch
);
791 rv
= pop3_noop1(&mb
);
793 safe_signal(SIGINT
, saveint
);
794 safe_signal(SIGPIPE
, savepipe
);
801 pop3_setfile(char const *server
, enum fedit_mode fm
)
804 sighandler_type saveint
, savepipe
;
810 if (fm
& FEDIT_NEWMAIL
)
814 if (!url_parse(&sc
.sc_url
, CPROTO_POP3
, server
))
816 if (!ok_blook(v15_compat
) &&
817 (!sc
.sc_url
.url_had_user
|| sc
.sc_url
.url_pass
.s
!= NULL
)) {
818 n_err(_("New-style URL used without *v15-compat* being set\n"));
822 if (!(ok_blook(v15_compat
) ? ccred_lookup(&sc
.sc_cred
, &sc
.sc_url
)
823 : ccred_lookup_old(&sc
.sc_cred
, CPROTO_POP3
,
824 (sc
.sc_url
.url_had_user
? sc
.sc_url
.url_eu_h_p
.s
825 : sc
.sc_url
.url_u_h_p
.s
))))
831 if (!sopen(&sc
.sc_sock
, &sc
.sc_url
))
836 if (fm
& FEDIT_SYSBOX
)
840 if (mb
.mb_sock
.s_fd
>= 0)
851 initbox(sc
.sc_url
.url_p_u_h_p
);
852 mb
.mb_type
= MB_VOID
;
854 mb
.mb_sock
= sc
.sc_sock
;
856 saveint
= safe_signal(SIGINT
, SIG_IGN
);
857 savepipe
= safe_signal(SIGPIPE
, SIG_IGN
);
858 if (sigsetjmp(_pop3_jmp
, 1)) {
860 n_err(_("POP3 connection closed\n"));
861 safe_signal(SIGINT
, saveint
);
862 safe_signal(SIGPIPE
, savepipe
);
869 if (saveint
!= SIG_IGN
)
870 safe_signal(SIGINT
, pop3catch
);
871 if (savepipe
!= SIG_IGN
)
872 safe_signal(SIGPIPE
, pop3catch
);
874 if ((cp
= xok_vlook(pop3_keepalive
, &sc
.sc_url
, OXM_ALL
)) != NULL
) {
875 if ((_pop3_keepalive
= (int)strtol(cp
, NULL
, 10)) > 0) {
876 _pop3_savealrm
= safe_signal(SIGALRM
, pop3alarm
);
877 alarm(_pop3_keepalive
);
881 mb
.mb_sock
.s_desc
= sc
.sc_url
.url_needs_tls
? "POP3S" : "POP3";
882 mb
.mb_sock
.s_onclose
= pop3_timer_off
;
883 if (_pop3_login(&mb
, &sc
) != OKAY
||
884 pop3_stat(&mb
, &mailsize
, &msgCount
) != OKAY
) {
887 safe_signal(SIGINT
, saveint
);
888 safe_signal(SIGPIPE
, savepipe
);
894 mb
.mb_type
= MB_POP3
;
895 mb
.mb_perm
= ((options
& OPT_R_FLAG
) || (fm
& FEDIT_RDONLY
)) ? 0 : MB_DELE
;
896 pop3_setptr(&mb
, &sc
);
898 /*if (!(fm & FEDIT_NEWMAIL)) */{
899 pstate
&= ~PS_SAW_COMMAND
;
900 pstate
|= PS_SETFILE_OPENED
;
903 safe_signal(SIGINT
, saveint
);
904 safe_signal(SIGPIPE
, savepipe
);
907 if ((options
& OPT_EXISTONLY
) && !(options
& OPT_HEADERLIST
)) {
908 rv
= (msgCount
== 0);
912 if (!(pstate
& PS_EDIT
) && msgCount
== 0) {
913 if (!ok_blook(emptystart
))
914 n_err(_("No mail at %s\n"), server
);
925 pop3_header(struct message
*m
)
930 /* TODO no URL here, no OXM possible; (however it is used in setfile()..) */
931 rv
= pop3_get(&mb
, m
, (ok_blook(pop3_bulk_load
) ? NEED_BODY
: NEED_HEADER
));
937 pop3_body(struct message
*m
)
942 rv
= pop3_get(&mb
, m
, NEED_BODY
);
948 pop3_quit(bool_t hold_sigs_on
)
950 sighandler_type
volatile saveint
, savepipe
;
959 if (mb
.mb_sock
.s_fd
< 0) {
960 n_err(_("POP3 connection already closed\n"));
966 saveint
= safe_signal(SIGINT
, SIG_IGN
);
967 savepipe
= safe_signal(SIGPIPE
, SIG_IGN
);
968 if (sigsetjmp(_pop3_jmp
, 1)) {
969 safe_signal(SIGINT
, saveint
);
970 safe_signal(SIGPIPE
, savepipe
);
975 if (saveint
!= SIG_IGN
)
976 safe_signal(SIGINT
, pop3catch
);
977 if (savepipe
!= SIG_IGN
)
978 safe_signal(SIGPIPE
, pop3catch
);
982 safe_signal(SIGINT
, saveint
);
983 safe_signal(SIGPIPE
, savepipe
);
993 #endif /* HAVE_POP3 */