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
77 static void makemessage(void);
78 static void append(struct message
*mp
);
79 static char *globname(char *name
);
80 static size_t length_of_line(const char *line
, size_t linesize
);
81 static char *fgetline_byone(char **line
, size_t *linesize
, size_t *llen
,
82 FILE *fp
, int appendnl
, size_t n
);
83 static enum okay
get_header(struct message
*mp
);
86 * Set up the input pointers while copying the mail file into /tmp.
89 setptr(FILE *ibuf
, off_t offset
)
95 int maybe
, inhead
, thiscnt
;
97 size_t linesize
= 0, filesize
;
98 int broken_mbox
= value("broken-mbox") != NULL
;
103 memset(&this, 0, sizeof this);
104 this.m_flag
= MUSED
|MNEW
|MNEWEST
;
105 filesize
= mailsize
- offset
;
106 offset
= ftell(mb
.mb_otf
);
108 if (fgetline(&linebuf
, &linesize
, &filesize
, &count
, ibuf
, 0)
110 this.m_xsize
= this.m_size
;
111 this.m_xlines
= this.m_lines
;
112 this.m_have
= HAVE_HEADER
|HAVE_BODY
;
121 if (linebuf
[0] == '\0')
124 fwrite(linebuf
, sizeof *linebuf
, count
, mb
.mb_otf
);
125 if (ferror(mb
.mb_otf
)) {
129 if (linebuf
[count
- 1] == '\n')
130 linebuf
[count
- 1] = '\0';
131 if (maybe
&& linebuf
[0] == 'F' && is_head(linebuf
, count
)) {
132 this.m_xsize
= this.m_size
;
133 this.m_xlines
= this.m_lines
;
134 this.m_have
= HAVE_HEADER
|HAVE_BODY
;
138 this.m_flag
= MUSED
|MNEW
|MNEWEST
;
141 this.m_block
= mailx_blockof(offset
);
142 this.m_offset
= mailx_offsetof(offset
);
144 } else if (linebuf
[0] == 0) {
147 for (cp
= linebuf
, cp2
= "status";; cp
++) {
148 if ((c
= *cp2
++) == 0) {
149 while (c
= *cp
++, whitechar(c
));
152 while ((c
= *cp
++) != '\0')
154 this.m_flag
|= MREAD
;
156 this.m_flag
&= ~MNEW
;
159 if (*cp
!= c
&& *cp
!= upperconv(c
))
162 for (cp
= linebuf
, cp2
= "x-status";; cp
++) {
163 if ((c
= *cp2
++) == 0) {
164 while (c
= *cp
++, whitechar(c
));
167 while ((c
= *cp
++) != '\0')
169 this.m_flag
|= MFLAGGED
;
171 this.m_flag
|=MANSWERED
;
173 this.m_flag
|=MDRAFTED
;
176 if (*cp
!= c
&& *cp
!= upperconv(c
))
181 this.m_size
+= count
;
184 maybe
= linebuf
[0] == 0;
190 * Drop the passed line onto the passed output buffer.
191 * If a write error occurs, return -1, else the count of
192 * characters written, including the newline.
195 putline(FILE *obuf
, char *linebuf
, size_t count
)
197 fwrite(linebuf
, sizeof *linebuf
, count
, obuf
);
205 * Read up a line from the specified input into the line
206 * buffer. Return the number of characters read. Do not
207 * include the newline at the end.
209 * n is the number of characters already read.
212 readline_restart(FILE *ibuf
, char **linebuf
, size_t *linesize
, size_t n
)
218 * Interrupts will cause trouble if we are inside a stdio call. As
219 * this is only relevant if input comes from a terminal, we can simply
220 * bypass it by read() then.
222 if (fileno(ibuf
) == 0 && is_a_tty
[0]) {
223 if (*linebuf
== NULL
|| *linesize
< LINESIZE
+ n
+ 1)
224 *linebuf
= srealloc(*linebuf
,
225 *linesize
= LINESIZE
+ n
+ 1);
227 if (n
>= *linesize
- 128)
228 *linebuf
= srealloc(*linebuf
, *linesize
+= 256);
230 sz
= read(0, *linebuf
+ n
, *linesize
- n
- 1);
233 (*linebuf
)[n
] = '\0';
234 if (n
> 0 && (*linebuf
)[n
- 1] == '\n')
237 if (sz
< 0 && errno
== EINTR
)
240 if ((*linebuf
)[n
- 1] != '\n') {
241 (*linebuf
)[n
++] = '\n';
242 (*linebuf
)[n
] = '\0';
251 * Not reading from standard input or standard input not
252 * a terminal. We read one char at a time as it is the
253 * only way to get lines with embedded NUL characters in
256 if (fgetline_byone(linebuf
, linesize
, &n
, ibuf
, 1, n
) == NULL
)
259 if (n
> 0 && (*linebuf
)[n
- 1] == '\n')
260 (*linebuf
)[--n
] = '\0';
265 * Return a file buffer all ready to read up the
266 * passed message pointer.
269 setinput(struct mailbox
*mp
, struct message
*m
, enum needspec need
)
275 if (m
->m_have
& HAVE_HEADER
)
281 if (m
->m_have
& HAVE_BODY
)
293 if (fseek(mp
->mb_itf
, (long)mailx_positionof(m
->m_block
,
294 m
->m_offset
), SEEK_SET
) < 0) {
296 panic(catgets(catd
, CATSET
, 77, "temporary file seek"));
302 setdot(struct message
*mp
)
314 * Take the data out of the passed ghost file and toss it into
315 * a dynamically allocated message structure.
323 message
[msgCount
].m_size
= 0;
324 message
[msgCount
].m_lines
= 0;
328 * Append the passed message descriptor onto the message structure.
331 append(struct message
*mp
)
333 if (msgCount
+ 1 >= msgspace
)
334 message
= srealloc(message
, (msgspace
+= 64) * sizeof *message
);
336 message
[msgCount
- 1] = *mp
;
340 * Delete a file, but only if the file is a plain file.
347 if (stat(name
, &sb
) < 0)
349 if (!S_ISREG(sb
.st_mode
)) {
353 return(unlink(name
));
356 static int sigdepth
; /* depth of holdsigs() */
357 static sigset_t nset
, oset
;
359 * Hold signals SIGHUP, SIGINT, and SIGQUIT.
365 if (sigdepth
++ == 0) {
367 sigaddset(&nset
, SIGHUP
);
368 sigaddset(&nset
, SIGINT
);
369 sigaddset(&nset
, SIGQUIT
);
370 sigprocmask(SIG_BLOCK
, &nset
, &oset
);
375 * Release signals SIGHUP, SIGINT, and SIGQUIT.
382 sigprocmask(SIG_SETMASK
, &oset
, (sigset_t
*)NULL
);
386 * Determine the size of the file possessed by
394 if (fstat(fileno(iob
), &sbuf
) < 0)
400 * Evaluate the string given as a new mailbox name.
401 * Supported meta characters:
402 * % for my system mail box
403 * %user for user's system mail box
404 * # for previous file
405 * & invoker's mbox file
406 * +file file in folder directory
407 * any shell meta character
408 * Return the file name as a dynamic string.
413 char xname
[PATHSIZE
];
414 char foldbuf
[PATHSIZE
];
418 * The order of evaluation is "%" and "#" expand into constants.
419 * "&" can expand into "+". "+" can expand into shell meta characters.
420 * Shell meta characters expand into constants.
421 * This way, we make no recursive expansion.
423 if ((sh
= get_shortcut(name
)) != NULL
)
428 if (name
[1] == ':' && name
[2]) {
432 findmail(name
[1] ? name
+ 1 : myname
, name
[1] != '\0' || uflag
,
433 xname
, sizeof xname
);
434 return savestr(xname
);
438 if (prevfile
[0] == 0) {
439 printf(catgets(catd
, CATSET
, 80, "No previous file\n"));
442 return savestr(prevfile
);
444 if (name
[1] == 0 && (name
= value("MBOX")) == NULL
)
448 if (name
[0] == '@' && which_protocol(mailname
) == PROTO_IMAP
) {
449 snprintf(xname
, sizeof xname
, "%s/%s", protbase(mailname
),
451 name
= savestr(xname
);
453 if (name
[0] == '+' && getfold(foldbuf
, sizeof foldbuf
) >= 0) {
454 if (which_protocol(foldbuf
) == PROTO_IMAP
&&
455 strcmp(foldbuf
, protbase(foldbuf
)))
456 snprintf(xname
, sizeof xname
, "%s%s", foldbuf
, name
+1);
458 snprintf(xname
, sizeof xname
, "%s/%s", foldbuf
, name
+1);
459 name
= savestr(xname
);
460 if (foldbuf
[0] == '%' && foldbuf
[1] == ':')
463 /* catch the most common shell meta character */
464 if (name
[0] == '~' && (name
[1] == '/' || name
[1] == '\0')) {
465 snprintf(xname
, sizeof xname
, "%s%s", homedir
, name
+ 1);
466 name
= savestr(xname
);
468 if (!anyof(name
, "|&;<>~{}()[]*?$`'\"\\"))
470 if (which_protocol(name
) == PROTO_FILE
)
471 return globname(name
);
486 * Some systems (notably Open UNIX 8.0.0) fork a shell for
487 * wordexp() and wait for it; waiting will fail if our SIGCHLD
491 sigaddset(&nset
, SIGCHLD
);
492 sigprocmask(SIG_BLOCK
, &nset
, NULL
);
493 i
= wordexp(name
, &we
, 0);
494 sigprocmask(SIG_UNBLOCK
, &nset
, NULL
);
499 fprintf(stderr
, catgets(catd
, CATSET
, 83,
500 "\"%s\": Expansion buffer overflow.\n"), name
);
505 fprintf(stderr
, catgets(catd
, CATSET
, 242,
506 "Syntax error in \"%s\"\n"), name
);
509 switch (we
.we_wordc
) {
511 cp
= savestr(we
.we_wordv
[0]);
514 fprintf(stderr
, catgets(catd
, CATSET
, 82,
515 "\"%s\": No match.\n"), name
);
519 fprintf(stderr
, catgets(catd
, CATSET
, 84,
520 "\"%s\": Ambiguous.\n"), name
);
525 #else /* !HAVE_WORDEXP */
526 char xname
[PATHSIZE
];
527 char cmdbuf
[PATHSIZE
]; /* also used for file names */
531 extern int wait_status
;
534 if (pipe(pivec
) < 0) {
538 snprintf(cmdbuf
, sizeof cmdbuf
, "echo %s", name
);
539 if ((shell
= value("SHELL")) == NULL
)
541 pid
= start_command(shell
, 0, -1, pivec
[1], "-c", cmdbuf
, NULL
);
549 l
= read(pivec
[0], xname
, sizeof xname
);
558 if (wait_child(pid
) < 0 && WTERMSIG(wait_status
) != SIGPIPE
) {
559 fprintf(stderr
, catgets(catd
, CATSET
, 81,
560 "\"%s\": Expansion failed.\n"), name
);
564 fprintf(stderr
, catgets(catd
, CATSET
, 82,
565 "\"%s\": No match.\n"), name
);
568 if (l
== sizeof xname
) {
569 fprintf(stderr
, catgets(catd
, CATSET
, 83,
570 "\"%s\": Expansion buffer overflow.\n"), name
);
574 for (cp
= &xname
[l
-1]; *cp
== '\n' && cp
> xname
; cp
--)
577 if (strchr(xname
, ' ') && stat(xname
, &sbuf
) < 0) {
578 fprintf(stderr
, catgets(catd
, CATSET
, 84,
579 "\"%s\": Ambiguous.\n"), name
);
582 return savestr(xname
);
583 #endif /* !HAVE_WORDEXP */
587 * Determine the current folder directory name.
590 getfold(char *name
, int size
)
595 if ((folder
= value("folder")) == NULL
)
597 if (*folder
== '/' || ((p
= which_protocol(folder
)) != PROTO_FILE
&&
598 p
!= PROTO_MAILDIR
)) {
599 strncpy(name
, folder
, size
);
602 snprintf(name
, size
, "%s/%s", homedir
, folder
);
608 * Return the name of the dead.letter file.
615 if ((cp
= value("DEAD")) == NULL
|| (cp
= expand(cp
)) == NULL
)
616 cp
= expand("~/dead.letter");
617 else if (*cp
!= '/') {
621 buf
= ac_alloc(sz
= strlen(cp
) + 3);
622 snprintf(buf
, sz
, "~/%s", cp
);
623 snprintf(buf
, sz
, "~/%s", cp
);
631 * line is a buffer with the result of fgets(). Returns the first
632 * newline or the last character read.
635 length_of_line(const char *line
, size_t linesize
)
640 * Last character is always '\0' and was added by fgets.
643 for (i
= 0; i
< linesize
; i
++)
646 return i
< linesize
? i
+ 1 : linesize
;
650 * fgets replacement to handle lines of arbitrary size and with
651 * embedded \0 characters.
652 * line - line buffer. *line be NULL.
653 * linesize - allocated size of line buffer.
654 * count - maximum characters to read. May be NULL.
655 * llen - length_of_line(*line).
657 * appendnl - always terminate line with \n, append if necessary.
660 fgetline(char **line
, size_t *linesize
, size_t *count
, size_t *llen
,
661 FILE *fp
, int appendnl
)
667 * If we have no count, we cannot determine where the
668 * characters returned by fgets() end if there was no
669 * newline. We have to read one character at one.
671 return fgetline_byone(line
, linesize
, llen
, fp
, appendnl
, 0);
672 if (*line
== NULL
|| *linesize
< LINESIZE
)
673 *line
= srealloc(*line
, *linesize
= LINESIZE
);
674 sz
= *linesize
<= *count
? *linesize
: *count
+ 1;
675 if (sz
<= 1 || fgets(*line
, sz
, fp
) == NULL
)
677 * Leave llen untouched; it is used to determine whether
678 * the last line was \n-terminated in some callers.
681 i_llen
= length_of_line(*line
, sz
);
683 while ((*line
)[i_llen
- 1] != '\n') {
684 *line
= srealloc(*line
, *linesize
+= 256);
685 sz
= *linesize
- i_llen
;
686 sz
= (sz
<= *count
? sz
: *count
+ 1);
687 if (sz
<= 1 || fgets(&(*line
)[i_llen
], sz
, fp
) == NULL
) {
689 (*line
)[i_llen
++] = '\n';
690 (*line
)[i_llen
] = '\0';
694 sz
= length_of_line(&(*line
)[i_llen
], sz
);
704 * Read a line, one character at once.
707 fgetline_byone(char **line
, size_t *linesize
, size_t *llen
,
708 FILE *fp
, int appendnl
, size_t n
)
712 if (*line
== NULL
|| *linesize
< LINESIZE
+ n
+ 1)
713 *line
= srealloc(*line
, *linesize
= LINESIZE
+ n
+ 1);
715 if (n
>= *linesize
- 128)
716 *line
= srealloc(*line
, *linesize
+= 256);
740 get_header(struct message
*mp
)
742 switch (mb
.mb_type
) {
747 return pop3_header(mp
);
750 return imap_header(mp
);
759 get_body(struct message
*mp
)
761 switch (mb
.mb_type
) {
766 return pop3_body(mp
);
769 return imap_body(mp
);
778 static long xwrite(int fd
, const char *data
, size_t sz
);
781 xwrite(int fd
, const char *data
, size_t sz
)
787 if ((wo
= write(fd
, data
+ wt
, sz
- wt
)) < 0) {
799 sclose(struct sock
*sp
)
804 if (sp
->s_onclose
!= NULL
)
806 #if defined (USE_NSS)
809 i
= PR_Close(sp
->s_prfd
) == PR_SUCCESS
? 0 : -1;
812 #elif defined (USE_OPENSSL)
815 SSL_shutdown(sp
->s_ssl
);
818 SSL_CTX_free(sp
->s_ctx
);
833 swrite(struct sock
*sp
, const char *data
)
835 return swrite1(sp
, data
, strlen(data
), 0);
839 swrite1(struct sock
*sp
, const char *data
, int sz
, int use_buffer
)
843 if (use_buffer
> 0) {
847 if (sp
->s_wbuf
== NULL
) {
848 sp
->s_wbufsize
= 4096;
849 sp
->s_wbuf
= smalloc(sp
->s_wbufsize
);
852 while (sp
->s_wbufpos
+ sz
> sp
->s_wbufsize
) {
853 di
= sp
->s_wbufsize
- sp
->s_wbufpos
;
855 if (sp
->s_wbufpos
> 0) {
856 memcpy(&sp
->s_wbuf
[sp
->s_wbufpos
], data
, di
);
857 ok
= swrite1(sp
, sp
->s_wbuf
,
860 ok
= swrite1(sp
, data
,
867 if (sz
== sp
->s_wbufsize
) {
868 ok
= swrite1(sp
, data
, sp
->s_wbufsize
, -1);
872 memcpy(&sp
->s_wbuf
[sp
->s_wbufpos
], data
, sz
);
876 } else if (use_buffer
== 0 && sp
->s_wbuf
!= NULL
&&
880 if (swrite1(sp
, sp
->s_wbuf
, x
, -1) != OKAY
)
885 #if defined (USE_NSS)
887 x
= PR_Write(sp
->s_prfd
, data
, sz
);
889 #elif defined (USE_OPENSSL)
891 ssl_retry
: x
= SSL_write(sp
->s_ssl
, data
, sz
);
893 switch (SSL_get_error(sp
->s_ssl
, x
)) {
894 case SSL_ERROR_WANT_READ
:
895 case SSL_ERROR_WANT_WRITE
:
902 x
= xwrite(sp
->s_fd
, data
, sz
);
906 snprintf(o
, sizeof o
, "%s write error",
907 sp
->s_desc
? sp
->s_desc
: "socket");
908 #if defined (USE_NSS)
909 sp
->s_use_ssl
? nss_gen_err("%s", o
) : perror(o
);
910 #elif defined (USE_OPENSSL)
911 sp
->s_use_ssl
? ssl_gen_err("%s", o
) : perror(o
);
914 #endif /* !USE_SSL */
923 sgetline(char **line
, size_t *linesize
, size_t *linelen
, struct sock
*sp
)
932 if (*line
== NULL
|| lp
> &(*line
)[*linesize
- 128]) {
933 size_t diff
= lp
- *line
;
934 *line
= srealloc(*line
, *linesize
+= 256);
937 if (sp
->s_rbufptr
== NULL
||
938 sp
->s_rbufptr
>= &sp
->s_rbuf
[sp
->s_rsz
]) {
939 #if defined (USE_NSS)
941 if ((sp
->s_rsz
= PR_Read(sp
->s_prfd
,
943 sizeof sp
->s_rbuf
)) <= 0) {
946 snprintf(o
, sizeof o
, "%s",
950 nss_gen_err("%s", o
);
955 #elif defined (USE_OPENSSL)
957 ssl_retry
: if ((sp
->s_rsz
= SSL_read(sp
->s_ssl
,
959 sizeof sp
->s_rbuf
)) <= 0) {
962 switch(SSL_get_error(sp
->s_ssl
,
964 case SSL_ERROR_WANT_READ
:
965 case SSL_ERROR_WANT_WRITE
:
968 snprintf(o
, sizeof o
, "%s",
972 ssl_gen_err("%s", o
);
980 again
: if ((sp
->s_rsz
= read(sp
->s_fd
, sp
->s_rbuf
,
981 sizeof sp
->s_rbuf
)) <= 0) {
986 snprintf(o
, sizeof o
, "%s",
995 sp
->s_rbufptr
= sp
->s_rbuf
;
997 } while ((*lp
++ = *sp
->s_rbufptr
++) != '\n');
1000 *linelen
= lp
- *line
;
1005 sopen(const char *xserver
, struct sock
*sp
, int use_ssl
,
1006 const char *uhp
, const char *portstr
, int verbose
)
1008 #ifdef HAVE_IPv6_FUNCS
1009 char hbuf
[NI_MAXHOST
];
1010 struct addrinfo hints
, *res0
, *res
;
1011 #else /* !HAVE_IPv6_FUNCS */
1012 struct sockaddr_in servaddr
;
1013 struct in_addr
**pptr
;
1016 unsigned short port
= 0;
1017 #endif /* !HAVE_IPv6_FUNCS */
1020 char *server
= (char *)xserver
;
1024 if ((cp
= strchr(server
, ':')) != NULL
) {
1026 #ifndef HAVE_IPv6_FUNCS
1027 port
= strtol(portstr
, NULL
, 10);
1028 #endif /* HAVE_IPv6_FUNCS */
1029 server
= salloc(cp
- xserver
+ 1);
1030 memcpy(server
, xserver
, cp
- xserver
);
1031 server
[cp
- xserver
] = '\0';
1033 #ifdef HAVE_IPv6_FUNCS
1034 memset(&hints
, 0, sizeof hints
);
1035 hints
.ai_socktype
= SOCK_STREAM
;
1037 fprintf(stderr
, "Resolving host %s . . .", server
);
1038 if (getaddrinfo(server
, portstr
, &hints
, &res0
) != 0) {
1039 fprintf(stderr
, catgets(catd
, CATSET
, 252,
1040 "Could not resolve host: %s\n"), server
);
1043 fprintf(stderr
, " done.\n");
1045 for (res
= res0
; res
!= NULL
&& sockfd
< 0; res
= res
->ai_next
) {
1047 if (getnameinfo(res
->ai_addr
, res
->ai_addrlen
,
1048 hbuf
, sizeof hbuf
, NULL
, 0,
1049 NI_NUMERICHOST
) != 0)
1050 strcpy(hbuf
, "unknown host");
1051 fprintf(stderr
, catgets(catd
, CATSET
, 192,
1052 "Connecting to %s:%s . . ."),
1055 if ((sockfd
= socket(res
->ai_family
, res
->ai_socktype
,
1056 res
->ai_protocol
)) >= 0) {
1057 if (connect(sockfd
, res
->ai_addr
, res
->ai_addrlen
)!=0) {
1064 perror(catgets(catd
, CATSET
, 254, "could not connect"));
1069 #else /* !HAVE_IPv6_FUNCS */
1071 if (strcmp(portstr
, "smtp") == 0)
1073 else if (strcmp(portstr
, "smtps") == 0)
1075 else if (strcmp(portstr
, "imap") == 0)
1077 else if (strcmp(portstr
, "imaps") == 0)
1079 else if (strcmp(portstr
, "pop3") == 0)
1081 else if (strcmp(portstr
, "pop3s") == 0)
1083 else if ((ep
= getservbyname((char *)portstr
, "tcp")) != NULL
)
1086 fprintf(stderr
, tr(251, "Unknown service: %s\n"),
1093 fprintf(stderr
, "Resolving host %s . . .", server
);
1094 if ((hp
= gethostbyname(server
)) == NULL
) {
1095 fprintf(stderr
, catgets(catd
, CATSET
, 252,
1096 "Could not resolve host: %s\n"), server
);
1099 fprintf(stderr
, " done.\n");
1100 pptr
= (struct in_addr
**)hp
->h_addr_list
;
1101 if ((sockfd
= socket(AF_INET
, SOCK_STREAM
, 0)) == -1) {
1102 perror(catgets(catd
, CATSET
, 253, "could not create socket"));
1105 memset(&servaddr
, 0, sizeof servaddr
);
1106 servaddr
.sin_family
= AF_INET
;
1107 servaddr
.sin_port
= port
;
1108 memcpy(&servaddr
.sin_addr
, *pptr
, sizeof(struct in_addr
));
1110 fprintf(stderr
, catgets(catd
, CATSET
, 192,
1111 "Connecting to %s:%d . . ."),
1112 inet_ntoa(**pptr
), ntohs(port
));
1113 if (connect(sockfd
, (struct sockaddr
*)&servaddr
, sizeof servaddr
)
1115 perror(catgets(catd
, CATSET
, 254, "could not connect"));
1118 #endif /* !HAVE_IPv6_FUNCS */
1120 fputs(catgets(catd
, CATSET
, 193, " connected.\n"), stderr
);
1121 memset(sp
, 0, sizeof *sp
);
1123 #if defined (USE_SSL)
1127 if ((ok
= ssl_open(server
, sp
, uhp
)) != OKAY
)
1131 #endif /* USE_SSL */
1134 #endif /* HAVE_SOCKETS */