2 * S-nail - a mail user agent derived from Berkeley Mail.
4 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
5 * Copyright (c) 2012 Steffen "Daode" Nurpmeso.
8 * Copyright (c) 1980, 1993
9 * The Regents of the University of California. 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 the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its 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 THE REGENTS 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 THE REGENTS 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
46 #endif /* HAVE_WORDEXP */
52 #elif defined (USE_OPENSSL)
53 #include <openssl/ssl.h>
54 #include <openssl/err.h>
55 #include <openssl/x509v3.h>
56 #include <openssl/x509.h>
57 #include <openssl/rand.h>
60 #include <sys/socket.h>
62 #include <netinet/in.h>
63 #ifdef HAVE_ARPA_INET_H
64 #include <arpa/inet.h>
65 #endif /* HAVE_ARPA_INET_H */
66 #endif /* HAVE_SOCKETS */
72 * Mail -- a mail program
78 * Evaluate the string given as a new mailbox name.
79 * Supported meta characters:
80 * % for my system mail box
81 * %user for user's system mail box
83 * & invoker's mbox file
84 * +file file in folder directory
85 * any shell meta character
86 * Return the file name as a dynamic string.
88 static char * _expand(char const *name
, int only_local
);
89 /* Perform shell meta character expansion */
90 static char * _globname(char const *name
);
92 static void makemessage(void);
93 static void append(struct message
*mp
);
94 static size_t length_of_line(const char *line
, size_t linesize
);
95 static char *fgetline_byone(char **line
, size_t *linesize
, size_t *llen
,
96 FILE *fp
, int appendnl
, size_t n
);
97 static enum okay
get_header(struct message
*mp
);
100 _expand(char const *name
, int only_local
)
102 char cbuf
[PATHSIZE
], *res
;
108 * The order of evaluation is "%" and "#" expand into constants.
109 * "&" can expand into "+". "+" can expand into shell meta characters.
110 * Shell meta characters expand into constants.
111 * This way, we make no recursive expansion.
114 if ((sh
= get_shortcut(res
)) != NULL
)
120 if (res
[1] == ':' && res
[2]) {
124 findmail((res
[1] ? res
+ 1 : myname
),
125 (res
[1] != '\0' || uflag
), cbuf
, sizeof cbuf
);
131 if (prevfile
[0] == 0) {
132 fprintf(stderr
, tr(80, "No previous file\n"));
138 if (res
[1] == 0 && (res
= value("MBOX")) == NULL
)
143 if (res
[0] == '@' && which_protocol(mailname
) == PROTO_IMAP
) {
144 res
= str_concat_csvl(&s
,
145 protbase(mailname
), "/", res
+ 1, NULL
)->s
;
149 if (res
[0] == '+' && getfold(cbuf
, sizeof cbuf
) >= 0) {
150 res
= str_concat_csvl(&s
,
151 cbuf
, ((which_protocol(cbuf
) == PROTO_IMAP
&&
152 strcmp(cbuf
, protbase(cbuf
))) /* XXX */
156 if (cbuf
[0] == '%' && cbuf
[1] == ':')
160 /* Catch the most common shell meta character */
161 if (res
[0] == '~' && (res
[1] == '/' || res
[1] == '\0')) {
162 res
= str_concat_csvl(&s
, homedir
, res
+ 1, NULL
)->s
;
166 if (anyof(res
, "|&;<>~{}()[]*?$`'\"\\") &&
167 which_protocol(res
) == PROTO_FILE
) {
168 res
= _globname(res
);
174 switch (which_protocol(res
)) {
176 case PROTO_MAILDIR
: /* XXX Really? ok MAILDIR for local? */
179 fprintf(stderr
, tr(280,
180 "\"%s\": only a local file or directory may "
193 _globname(char const *name
)
202 * Some systems (notably Open UNIX 8.0.0) fork a shell for
203 * wordexp() and wait for it; waiting will fail if our SIGCHLD
207 sigaddset(&nset
, SIGCHLD
);
208 sigprocmask(SIG_BLOCK
, &nset
, NULL
);
209 i
= wordexp(name
, &we
, 0);
210 sigprocmask(SIG_UNBLOCK
, &nset
, NULL
);
216 fprintf(stderr
, tr(83, "\"%s\": Expansion buffer overflow.\n"),
222 fprintf(stderr
, tr(242, "Syntax error in \"%s\"\n"), name
);
226 switch (we
.we_wordc
) {
228 cp
= savestr(we
.we_wordv
[0]);
231 fprintf(stderr
, tr(82, "\"%s\": No match.\n"), name
);
235 fprintf(stderr
, tr(84, "\"%s\": Ambiguous.\n"), name
);
242 #else /* !HAVE_WORDEXP */
243 char xname
[PATHSIZE
];
244 char cmdbuf
[PATHSIZE
]; /* also used for file names */
248 extern int wait_status
;
251 if (pipe(pivec
) < 0) {
255 snprintf(cmdbuf
, sizeof cmdbuf
, "echo %s", name
);
256 if ((shell
= value("SHELL")) == NULL
)
258 pid
= start_command(shell
, 0, -1, pivec
[1], "-c", cmdbuf
, NULL
);
266 l
= read(pivec
[0], xname
, sizeof xname
);
275 if (wait_child(pid
) < 0 && WTERMSIG(wait_status
) != SIGPIPE
) {
276 fprintf(stderr
, tr(81, "\"%s\": Expansion failed.\n"), name
);
280 fprintf(stderr
, tr(82, "\"%s\": No match.\n"), name
);
283 if (l
== sizeof xname
) {
284 fprintf(stderr
, tr(83, "\"%s\": Expansion buffer overflow.\n"),
289 for (cp
= &xname
[l
-1]; *cp
== '\n' && cp
> xname
; cp
--)
292 if (strchr(xname
, ' ') && stat(xname
, &sbuf
) < 0) {
293 fprintf(stderr
, tr(84, "\"%s\": Ambiguous.\n"), name
);
296 return savestr(xname
);
297 #endif /* !HAVE_WORDEXP */
301 * Set up the input pointers while copying the mail file into /tmp.
304 setptr(FILE *ibuf
, off_t offset
)
310 int maybe
, inhead
, thiscnt
;
311 char *linebuf
= NULL
;
312 size_t linesize
= 0, filesize
;
317 memset(&this, 0, sizeof this);
318 this.m_flag
= MUSED
|MNEW
|MNEWEST
;
319 filesize
= mailsize
- offset
;
320 offset
= ftell(mb
.mb_otf
);
322 if (fgetline(&linebuf
, &linesize
, &filesize
, &count
, ibuf
, 0)
324 this.m_xsize
= this.m_size
;
325 this.m_xlines
= this.m_lines
;
326 this.m_have
= HAVE_HEADER
|HAVE_BODY
;
335 if (linebuf
[0] == '\0')
338 fwrite(linebuf
, sizeof *linebuf
, count
, mb
.mb_otf
);
339 if (ferror(mb
.mb_otf
)) {
343 if (linebuf
[count
- 1] == '\n')
344 linebuf
[count
- 1] = '\0';
345 if (maybe
&& linebuf
[0] == 'F' && is_head(linebuf
, count
)) {
346 this.m_xsize
= this.m_size
;
347 this.m_xlines
= this.m_lines
;
348 this.m_have
= HAVE_HEADER
|HAVE_BODY
;
352 this.m_flag
= MUSED
|MNEW
|MNEWEST
;
355 this.m_block
= mailx_blockof(offset
);
356 this.m_offset
= mailx_offsetof(offset
);
358 } else if (linebuf
[0] == 0) {
361 for (cp
= linebuf
, cp2
= "status";; cp
++) {
362 if ((c
= *cp2
++) == 0) {
363 while (c
= *cp
++, whitechar(c
));
366 while ((c
= *cp
++) != '\0')
368 this.m_flag
|= MREAD
;
370 this.m_flag
&= ~MNEW
;
373 if (*cp
!= c
&& *cp
!= upperconv(c
))
376 for (cp
= linebuf
, cp2
= "x-status";; cp
++) {
377 if ((c
= *cp2
++) == 0) {
378 while (c
= *cp
++, whitechar(c
));
381 while ((c
= *cp
++) != '\0')
383 this.m_flag
|= MFLAGGED
;
385 this.m_flag
|=MANSWERED
;
387 this.m_flag
|=MDRAFTED
;
390 if (*cp
!= c
&& *cp
!= upperconv(c
))
395 this.m_size
+= count
;
397 maybe
= linebuf
[0] == 0;
403 * Drop the passed line onto the passed output buffer.
404 * If a write error occurs, return -1, else the count of
405 * characters written, including the newline.
408 putline(FILE *obuf
, char *linebuf
, size_t count
)
410 fwrite(linebuf
, sizeof *linebuf
, count
, obuf
);
418 * Read up a line from the specified input into the line
419 * buffer. Return the number of characters read. Do not
420 * include the newline at the end.
422 * n is the number of characters already read.
425 readline_restart(FILE *ibuf
, char **linebuf
, size_t *linesize
, size_t n
)
431 * Interrupts will cause trouble if we are inside a stdio call. As
432 * this is only relevant if input comes from a terminal, we can simply
433 * bypass it by read() then.
435 if (fileno(ibuf
) == 0 && is_a_tty
[0]) {
436 if (*linebuf
== NULL
|| *linesize
< LINESIZE
+ n
+ 1)
437 *linebuf
= srealloc(*linebuf
,
438 *linesize
= LINESIZE
+ n
+ 1);
440 if (n
>= *linesize
- 128)
441 *linebuf
= srealloc(*linebuf
, *linesize
+= 256);
443 sz
= read(0, *linebuf
+ n
, *linesize
- n
- 1);
446 (*linebuf
)[n
] = '\0';
447 if (n
> 0 && (*linebuf
)[n
- 1] == '\n')
450 if (sz
< 0 && errno
== EINTR
)
453 if ((*linebuf
)[n
- 1] != '\n') {
454 (*linebuf
)[n
++] = '\n';
455 (*linebuf
)[n
] = '\0';
464 * Not reading from standard input or standard input not
465 * a terminal. We read one char at a time as it is the
466 * only way to get lines with embedded NUL characters in
469 if (fgetline_byone(linebuf
, linesize
, &n
, ibuf
, 1, n
) == NULL
)
472 if (n
> 0 && (*linebuf
)[n
- 1] == '\n')
473 (*linebuf
)[--n
] = '\0';
478 * Return a file buffer all ready to read up the
479 * passed message pointer.
482 setinput(struct mailbox
*mp
, struct message
*m
, enum needspec need
)
488 if (m
->m_have
& HAVE_HEADER
)
494 if (m
->m_have
& HAVE_BODY
)
506 if (fseek(mp
->mb_itf
, (long)mailx_positionof(m
->m_block
,
507 m
->m_offset
), SEEK_SET
) < 0) {
509 panic(catgets(catd
, CATSET
, 77, "temporary file seek"));
515 setdot(struct message
*mp
)
527 * Take the data out of the passed ghost file and toss it into
528 * a dynamically allocated message structure.
536 message
[msgCount
].m_size
= 0;
537 message
[msgCount
].m_lines
= 0;
541 * Append the passed message descriptor onto the message structure.
544 append(struct message
*mp
)
546 if (msgCount
+ 1 >= msgspace
)
547 message
= srealloc(message
, (msgspace
+= 64) * sizeof *message
);
549 message
[msgCount
- 1] = *mp
;
553 * Delete a file, but only if the file is a plain file.
560 if (stat(name
, &sb
) < 0)
562 if (!S_ISREG(sb
.st_mode
)) {
566 return(unlink(name
));
569 static int sigdepth
; /* depth of holdsigs() */
570 static sigset_t nset
, oset
;
572 * Hold signals SIGHUP, SIGINT, and SIGQUIT.
578 if (sigdepth
++ == 0) {
580 sigaddset(&nset
, SIGHUP
);
581 sigaddset(&nset
, SIGINT
);
582 sigaddset(&nset
, SIGQUIT
);
583 sigprocmask(SIG_BLOCK
, &nset
, &oset
);
588 * Release signals SIGHUP, SIGINT, and SIGQUIT.
594 sigprocmask(SIG_SETMASK
, &oset
, (sigset_t
*)NULL
);
598 * Determine the size of the file possessed by
606 if (fstat(fileno(iob
), &sbuf
) < 0)
612 * Just like expand(), but expanded file must be FILE or DIR
615 file_expand(char const *name
)
617 return (_expand(name
, 1));
621 * Evaluate the string given as a new mailbox name.
622 * Supported meta characters:
623 * % for my system mail box
624 * %user for user's system mail box
625 * # for previous file
626 * & invoker's mbox file
627 * +file file in folder directory
628 * any shell meta character
629 * Return the file name as a dynamic string.
632 expand(char const *name
)
634 return (_expand(name
, 0));
638 * Determine the current folder directory name.
641 getfold(char *name
, int size
)
646 if ((folder
= value("folder")) == NULL
)
648 if (*folder
== '/' || ((p
= which_protocol(folder
)) != PROTO_FILE
&&
649 p
!= PROTO_MAILDIR
)) {
650 strncpy(name
, folder
, size
);
653 snprintf(name
, size
, "%s/%s", homedir
, folder
);
659 * Return the name of the dead.letter file.
666 if ((cp
= value("DEAD")) == NULL
|| (cp
= file_expand(cp
)) == NULL
)
667 cp
= file_expand("~/dead.letter");
668 else if (*cp
!= '/') {
669 size_t sz
= strlen(cp
) + 3;
670 char *buf
= ac_alloc(sz
);
672 snprintf(buf
, sz
, "~/%s", cp
);
673 cp
= file_expand(buf
);
682 * line is a buffer with the result of fgets(). Returns the first
683 * newline or the last character read.
686 length_of_line(const char *line
, size_t linesize
)
691 * Last character is always '\0' and was added by fgets.
694 for (i
= 0; i
< linesize
; i
++)
697 return i
< linesize
? i
+ 1 : linesize
;
701 * fgets replacement to handle lines of arbitrary size and with
702 * embedded \0 characters.
703 * line - line buffer. *line be NULL.
704 * linesize - allocated size of line buffer.
705 * count - maximum characters to read. May be NULL.
706 * llen - length_of_line(*line).
708 * appendnl - always terminate line with \n, append if necessary.
711 fgetline(char **line
, size_t *linesize
, size_t *count
, size_t *llen
,
712 FILE *fp
, int appendnl
)
718 * If we have no count, we cannot determine where the
719 * characters returned by fgets() end if there was no
720 * newline. We have to read one character at one.
722 return fgetline_byone(line
, linesize
, llen
, fp
, appendnl
, 0);
723 if (*line
== NULL
|| *linesize
< LINESIZE
)
724 *line
= srealloc(*line
, *linesize
= LINESIZE
);
725 sz
= *linesize
<= *count
? *linesize
: *count
+ 1;
726 if (sz
<= 1 || fgets(*line
, sz
, fp
) == NULL
)
728 * Leave llen untouched; it is used to determine whether
729 * the last line was \n-terminated in some callers.
732 i_llen
= length_of_line(*line
, sz
);
734 while ((*line
)[i_llen
- 1] != '\n') {
735 *line
= srealloc(*line
, *linesize
+= 256);
736 sz
= *linesize
- i_llen
;
737 sz
= (sz
<= *count
? sz
: *count
+ 1);
738 if (sz
<= 1 || fgets(&(*line
)[i_llen
], sz
, fp
) == NULL
) {
740 (*line
)[i_llen
++] = '\n';
741 (*line
)[i_llen
] = '\0';
745 sz
= length_of_line(&(*line
)[i_llen
], sz
);
755 * Read a line, one character at once.
758 fgetline_byone(char **line
, size_t *linesize
, size_t *llen
,
759 FILE *fp
, int appendnl
, size_t n
)
763 if (*line
== NULL
|| *linesize
< LINESIZE
+ n
+ 1)
764 *line
= srealloc(*line
, *linesize
= LINESIZE
+ n
+ 1);
766 if (n
>= *linesize
- 128)
767 *line
= srealloc(*line
, *linesize
+= 256);
791 get_header(struct message
*mp
)
793 switch (mb
.mb_type
) {
798 return pop3_header(mp
);
801 return imap_header(mp
);
810 get_body(struct message
*mp
)
812 switch (mb
.mb_type
) {
817 return pop3_body(mp
);
820 return imap_body(mp
);
829 static long xwrite(int fd
, const char *data
, size_t sz
);
832 xwrite(int fd
, const char *data
, size_t sz
)
838 if ((wo
= write(fd
, data
+ wt
, sz
- wt
)) < 0) {
850 sclose(struct sock
*sp
)
855 if (sp
->s_onclose
!= NULL
)
857 #if defined (USE_NSS)
860 i
= PR_Close(sp
->s_prfd
) == PR_SUCCESS
? 0 : -1;
863 #elif defined (USE_OPENSSL)
866 SSL_shutdown(sp
->s_ssl
);
869 SSL_CTX_free(sp
->s_ctx
);
884 swrite(struct sock
*sp
, const char *data
)
886 return swrite1(sp
, data
, strlen(data
), 0);
890 swrite1(struct sock
*sp
, const char *data
, int sz
, int use_buffer
)
894 if (use_buffer
> 0) {
898 if (sp
->s_wbuf
== NULL
) {
899 sp
->s_wbufsize
= 4096;
900 sp
->s_wbuf
= smalloc(sp
->s_wbufsize
);
903 while (sp
->s_wbufpos
+ sz
> sp
->s_wbufsize
) {
904 di
= sp
->s_wbufsize
- sp
->s_wbufpos
;
906 if (sp
->s_wbufpos
> 0) {
907 memcpy(&sp
->s_wbuf
[sp
->s_wbufpos
], data
, di
);
908 ok
= swrite1(sp
, sp
->s_wbuf
,
911 ok
= swrite1(sp
, data
,
918 if (sz
== sp
->s_wbufsize
) {
919 ok
= swrite1(sp
, data
, sp
->s_wbufsize
, -1);
923 memcpy(&sp
->s_wbuf
[sp
->s_wbufpos
], data
, sz
);
927 } else if (use_buffer
== 0 && sp
->s_wbuf
!= NULL
&&
931 if (swrite1(sp
, sp
->s_wbuf
, x
, -1) != OKAY
)
936 #if defined (USE_NSS)
938 x
= PR_Write(sp
->s_prfd
, data
, sz
);
940 #elif defined (USE_OPENSSL)
942 ssl_retry
: x
= SSL_write(sp
->s_ssl
, data
, sz
);
944 switch (SSL_get_error(sp
->s_ssl
, x
)) {
945 case SSL_ERROR_WANT_READ
:
946 case SSL_ERROR_WANT_WRITE
:
953 x
= xwrite(sp
->s_fd
, data
, sz
);
957 snprintf(o
, sizeof o
, "%s write error",
958 sp
->s_desc
? sp
->s_desc
: "socket");
959 #if defined (USE_NSS)
960 sp
->s_use_ssl
? nss_gen_err("%s", o
) : perror(o
);
961 #elif defined (USE_OPENSSL)
962 sp
->s_use_ssl
? ssl_gen_err("%s", o
) : perror(o
);
965 #endif /* !USE_SSL */
974 sgetline(char **line
, size_t *linesize
, size_t *linelen
, struct sock
*sp
)
983 if (*line
== NULL
|| lp
> &(*line
)[*linesize
- 128]) {
984 size_t diff
= lp
- *line
;
985 *line
= srealloc(*line
, *linesize
+= 256);
988 if (sp
->s_rbufptr
== NULL
||
989 sp
->s_rbufptr
>= &sp
->s_rbuf
[sp
->s_rsz
]) {
990 #if defined (USE_NSS)
992 if ((sp
->s_rsz
= PR_Read(sp
->s_prfd
,
994 sizeof sp
->s_rbuf
)) <= 0) {
997 snprintf(o
, sizeof o
, "%s",
1001 nss_gen_err("%s", o
);
1006 #elif defined (USE_OPENSSL)
1007 if (sp
->s_use_ssl
) {
1008 ssl_retry
: if ((sp
->s_rsz
= SSL_read(sp
->s_ssl
,
1010 sizeof sp
->s_rbuf
)) <= 0) {
1011 if (sp
->s_rsz
< 0) {
1013 switch(SSL_get_error(sp
->s_ssl
,
1015 case SSL_ERROR_WANT_READ
:
1016 case SSL_ERROR_WANT_WRITE
:
1019 snprintf(o
, sizeof o
, "%s",
1023 ssl_gen_err("%s", o
);
1029 #endif /* USE_SSL */
1031 again
: if ((sp
->s_rsz
= read(sp
->s_fd
, sp
->s_rbuf
,
1032 sizeof sp
->s_rbuf
)) <= 0) {
1033 if (sp
->s_rsz
< 0) {
1037 snprintf(o
, sizeof o
, "%s",
1046 sp
->s_rbufptr
= sp
->s_rbuf
;
1048 } while ((*lp
++ = *sp
->s_rbufptr
++) != '\n');
1051 *linelen
= lp
- *line
;
1056 sopen(const char *xserver
, struct sock
*sp
, int use_ssl
,
1057 const char *uhp
, const char *portstr
, int verbose
)
1060 char hbuf
[NI_MAXHOST
];
1061 struct addrinfo hints
, *res0
, *res
;
1063 struct sockaddr_in servaddr
;
1064 struct in_addr
**pptr
;
1067 unsigned short port
= 0;
1071 char *server
= (char *)xserver
;
1075 if ((cp
= strchr(server
, ':')) != NULL
) {
1078 port
= strtol(portstr
, NULL
, 10);
1080 server
= salloc(cp
- xserver
+ 1);
1081 memcpy(server
, xserver
, cp
- xserver
);
1082 server
[cp
- xserver
] = '\0';
1085 memset(&hints
, 0, sizeof hints
);
1086 hints
.ai_socktype
= SOCK_STREAM
;
1088 fprintf(stderr
, "Resolving host %s . . .", server
);
1089 if (getaddrinfo(server
, portstr
, &hints
, &res0
) != 0) {
1090 fprintf(stderr
, catgets(catd
, CATSET
, 252,
1091 "Could not resolve host: %s\n"), server
);
1094 fprintf(stderr
, " done.\n");
1096 for (res
= res0
; res
!= NULL
&& sockfd
< 0; res
= res
->ai_next
) {
1098 if (getnameinfo(res
->ai_addr
, res
->ai_addrlen
,
1099 hbuf
, sizeof hbuf
, NULL
, 0,
1100 NI_NUMERICHOST
) != 0)
1101 strcpy(hbuf
, "unknown host");
1102 fprintf(stderr
, catgets(catd
, CATSET
, 192,
1103 "Connecting to %s:%s . . ."),
1106 if ((sockfd
= socket(res
->ai_family
, res
->ai_socktype
,
1107 res
->ai_protocol
)) >= 0) {
1108 if (connect(sockfd
, res
->ai_addr
, res
->ai_addrlen
)!=0) {
1115 perror(catgets(catd
, CATSET
, 254, "could not connect"));
1120 #else /* USE_IPV6 */
1122 if (strcmp(portstr
, "smtp") == 0)
1124 else if (strcmp(portstr
, "smtps") == 0)
1126 else if (strcmp(portstr
, "imap") == 0)
1128 else if (strcmp(portstr
, "imaps") == 0)
1130 else if (strcmp(portstr
, "pop3") == 0)
1132 else if (strcmp(portstr
, "pop3s") == 0)
1134 else if ((ep
= getservbyname((char *)portstr
, "tcp")) != NULL
)
1137 fprintf(stderr
, tr(251, "Unknown service: %s\n"),
1144 fprintf(stderr
, "Resolving host %s . . .", server
);
1145 if ((hp
= gethostbyname(server
)) == NULL
) {
1146 fprintf(stderr
, catgets(catd
, CATSET
, 252,
1147 "Could not resolve host: %s\n"), server
);
1150 fprintf(stderr
, " done.\n");
1151 pptr
= (struct in_addr
**)hp
->h_addr_list
;
1152 if ((sockfd
= socket(AF_INET
, SOCK_STREAM
, 0)) == -1) {
1153 perror(catgets(catd
, CATSET
, 253, "could not create socket"));
1156 memset(&servaddr
, 0, sizeof servaddr
);
1157 servaddr
.sin_family
= AF_INET
;
1158 servaddr
.sin_port
= port
;
1159 memcpy(&servaddr
.sin_addr
, *pptr
, sizeof(struct in_addr
));
1161 fprintf(stderr
, catgets(catd
, CATSET
, 192,
1162 "Connecting to %s:%d . . ."),
1163 inet_ntoa(**pptr
), ntohs(port
));
1164 if (connect(sockfd
, (struct sockaddr
*)&servaddr
, sizeof servaddr
)
1166 perror(catgets(catd
, CATSET
, 254, "could not connect"));
1169 #endif /* USE_IPV6 */
1171 fputs(catgets(catd
, CATSET
, 193, " connected.\n"), stderr
);
1172 memset(sp
, 0, sizeof *sp
);
1178 if ((ok
= ssl_open(server
, sp
, uhp
)) != OKAY
)
1185 #endif /* HAVE_SOCKETS */