Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
mailutils
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
0aed0d58
...
0aed0d5832e76d20f2ea560293955214cb182553
authored
2009-08-29 22:45:27 +0300
by
Sergey Poznyakoff
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Minor fixes
* libproto/mailer/smtp.c: fix indentation
1 parent
496bdf72
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
24 deletions
libproto/mailer/smtp.c
libproto/mailer/smtp.c
View file @
0aed0d5
...
...
@@ -95,6 +95,7 @@ static struct _mu_record _smtp_record = {
NULL
,
/* _get_mailer method. */
NULL
/* _get_folder method. */
};
/* We export : url parsing and the initialisation of
the mailbox, via the register entry/record. */
mu_record_t
mu_smtp_record
=
&
_smtp_record
;
...
...
@@ -163,19 +164,20 @@ typedef struct _smtp *smtp_t;
#define AUTH_GSSAPI 0x00000010
#define AUTH_EXTERNAL 0x00000020
struct
auth_mech_record
{
struct
auth_mech_record
{
unsigned
long
id
;
char
*
name
;
};
static
struct
auth_mech_record
auth_mech_list
[]
=
{
{
AUTH_LOGIN
,
"login"
},
{
AUTH_PLAIN
,
"plain"
},
{
AUTH_CRAM_MD5
,
"cram-md5"
},
{
AUTH_DIGEST_MD5
,
"digest-md5"
},
{
AUTH_GSSAPI
,
"gssapi"
},
{
AUTH_EXTERNAL
,
"external"
},
{
0
,
NULL
},
{
AUTH_LOGIN
,
"login"
},
{
AUTH_PLAIN
,
"plain"
},
{
AUTH_CRAM_MD5
,
"cram-md5"
},
{
AUTH_DIGEST_MD5
,
"digest-md5"
},
{
AUTH_GSSAPI
,
"gssapi"
},
{
AUTH_EXTERNAL
,
"external"
},
{
0
,
NULL
},
};
static
void
smtp_destroy
(
mu_mailer_t
);
...
...
@@ -238,7 +240,8 @@ CLEAR_STATE (smtp_t smtp)
as that which is ongoing. Check this. */
static
int
smtp_check_send_resumption
(
smtp_t
smtp
,
mu_message_t
msg
,
mu_address_t
from
,
mu_address_t
to
)
mu_message_t
msg
,
mu_address_t
from
,
mu_address_t
to
)
{
if
(
smtp
->
state
==
SMTP_NO_STATE
)
return
0
;
...
...
@@ -324,6 +327,7 @@ _mailer_smtp_init (mu_mailer_t mailer)
/* Set our properties. */
{
mu_property_t
property
=
NULL
;
mu_mailer_get_property
(
mailer
,
&
property
);
mu_property_set_value
(
property
,
"TYPE"
,
"SMTP"
,
1
);
}
...
...
@@ -429,8 +433,7 @@ smtp_open (mu_mailer_t mailer, int flags)
case
SMTP_OPEN
:
MU_DEBUG2
(
mailer
->
debug
,
MU_DEBUG_PROT
,
"smtp_open (host: %s port: %ld)
\n
"
,
smtp
->
mailhost
,
port
);
"smtp_open (host: %s port: %ld)
\n
"
,
smtp
->
mailhost
,
port
);
status
=
mu_stream_open
(
mailer
->
stream
);
CHECK_EAGAIN
(
smtp
,
status
);
smtp
->
state
=
SMTP_GREETINGS
;
...
...
@@ -446,7 +449,7 @@ smtp_open (mu_mailer_t mailer, int flags)
return
EACCES
;
}
ehlo:
ehlo:
status
=
smtp_writeline
(
smtp
,
"EHLO %s
\r\n
"
,
smtp
->
localhost
);
CHECK_ERROR
(
smtp
,
status
);
...
...
@@ -475,7 +478,8 @@ ehlo:
if
(
smtp
->
capa
&
CAPA_STARTTLS
)
smtp
->
state
=
SMTP_STARTTLS
;
else
if
(
smtp
->
capa
&
CAPA_AUTH
&&
mailer
->
url
->
user
)
{
else
if
(
smtp
->
capa
&
CAPA_AUTH
&&
mailer
->
url
->
user
)
{
smtp
->
state
=
SMTP_AUTH
;
}
else
...
...
@@ -484,14 +488,16 @@ ehlo:
case
SMTP_STARTTLS
:
case
SMTP_STARTTLS_ACK
:
if
(
smtp
->
capa
&
CAPA_STARTTLS
)
{
if
(
smtp
->
capa
&
CAPA_STARTTLS
)
{
smtp_starttls
(
smtp
);
goto
ehlo
;
}
case
SMTP_AUTH
:
case
SMTP_AUTH_ACK
:
if
(
smtp
->
capa
&
CAPA_AUTH
)
{
if
(
smtp
->
capa
&
CAPA_AUTH
)
{
smtp_auth
(
smtp
);
break
;
}
...
...
@@ -532,6 +538,7 @@ smtp_close (mu_mailer_t mailer)
{
smtp_t
smtp
=
mailer
->
data
;
int
status
;
switch
(
smtp
->
state
)
{
case
SMTP_NO_STATE
:
...
...
@@ -565,6 +572,7 @@ smtp_reader (void *iodata)
{
int
status
=
0
;
smtp_t
iop
=
iodata
;
status
=
smtp_read_ack
(
iop
);
CHECK_EAGAIN
(
iop
,
status
);
return
status
;
...
...
@@ -575,6 +583,7 @@ smtp_writer (void *iodata, char *buf)
{
smtp_t
iop
=
iodata
;
int
status
;
if
(
mu_c_strncasecmp
(
buf
,
"EHLO"
,
4
)
==
0
)
status
=
smtp_writeline
(
iop
,
"%s %s
\r\n
"
,
buf
,
iop
->
localhost
);
else
...
...
@@ -586,9 +595,10 @@ smtp_writer (void *iodata, char *buf)
}
static
void
smtp_stream_ctl
(
void
*
iodata
,
mu_stream_t
*
pold
,
mu_stream_t
new
)
smtp_stream_ctl
(
void
*
iodata
,
mu_stream_t
*
pold
,
mu_stream_t
new
)
{
smtp_t
iop
=
iodata
;
if
(
pold
)
*
pold
=
iop
->
mailer
->
stream
;
if
(
new
)
...
...
@@ -642,7 +652,7 @@ cram_md5 (char *secret, char *challenge, unsigned char *digest)
if
(
secret_len
>
64
)
{
mu_md5_init_ctx
(
&
context
);
mu_md5_process_bytes
((
unsigned
char
*
)
secret
,
secret_len
,
&
context
);
mu_md5_process_bytes
((
unsigned
char
*
)
secret
,
secret_len
,
&
context
);
mu_md5_finish_ctx
(
&
context
,
ipad
);
mu_md5_finish_ctx
(
&
context
,
opad
);
}
...
...
@@ -660,7 +670,7 @@ cram_md5 (char *secret, char *challenge, unsigned char *digest)
mu_md5_init_ctx
(
&
context
);
mu_md5_process_bytes
(
ipad
,
sizeof
(
ipad
),
&
context
);
mu_md5_process_bytes
((
unsigned
char
*
)
challenge
,
challenge_len
,
&
context
);
mu_md5_process_bytes
((
unsigned
char
*
)
challenge
,
challenge_len
,
&
context
);
mu_md5_finish_ctx
(
&
context
,
digest
);
mu_md5_init_ctx
(
&
context
);
...
...
@@ -725,6 +735,7 @@ smtp_auth (smtp_t smtp)
unsigned
char
*
b64buf
=
NULL
;
unsigned
char
digest
[
16
];
static
char
ascii_digest
[
33
];
memset
(
digest
,
0
,
16
);
status
=
mu_url_sget_user
(
mailer
->
url
,
&
user
);
...
...
@@ -757,7 +768,7 @@ smtp_auth (smtp_t smtp)
mu_rtrim_cset
(
p
,
"
\r\n
"
);
mu_base64_decode
(
p
,
strlen
(
p
),
&
chl
,
&
chlen
);
cram_md5
((
char
*
)
mu_secret_password
(
secret
),
chl
,
digest
);
cram_md5
((
char
*
)
mu_secret_password
(
secret
),
chl
,
digest
);
mu_secret_password_unref
(
secret
);
free
(
chl
);
...
...
@@ -825,7 +836,8 @@ smtp_auth (smtp_t smtp)
}
static
int
message_set_header_value
(
mu_message_t
msg
,
const
char
*
field
,
const
char
*
value
)
message_set_header_value
(
mu_message_t
msg
,
const
char
*
field
,
const
char
*
value
)
{
int
status
=
0
;
mu_header_t
hdr
=
NULL
;
...
...
@@ -895,8 +907,8 @@ The correct algorithm is
*/
static
int
smtp_send_message
(
mu_mailer_t
mailer
,
mu_message_t
argmsg
,
mu_address_t
argfrom
,
mu_address_t
argto
)
smtp_send_message
(
mu_mailer_t
mailer
,
mu_message_t
argmsg
,
mu_address_t
arg
from
,
mu_address_t
arg
to
)
{
smtp_t
smtp
=
NULL
;
int
status
;
...
...
@@ -1168,7 +1180,7 @@ smtp_send_message (mu_mailer_t mailer, mu_message_t argmsg, mu_address_t argfrom
}
int
smtp_address_add
(
mu_address_t
*
paddr
,
const
char
*
value
)
smtp_address_add
(
mu_address_t
*
paddr
,
const
char
*
value
)
{
mu_address_t
addr
=
NULL
;
int
status
;
...
...
@@ -1300,6 +1312,7 @@ smtp_writeline (smtp_t smtp, const char *format, ...)
{
char
*
buffer
=
NULL
;
size_t
buflen
=
smtp
->
buflen
*
2
;
buffer
=
realloc
(
smtp
->
buffer
,
buflen
);
if
(
smtp
->
buffer
==
NULL
)
return
ENOMEM
;
...
...
@@ -1333,6 +1346,7 @@ smtp_write (smtp_t smtp)
{
int
status
=
0
;
size_t
len
;
if
(
smtp
->
ptr
>
smtp
->
buffer
)
{
len
=
smtp
->
ptr
-
smtp
->
buffer
;
...
...
@@ -1386,7 +1400,8 @@ smtp_parse_ehlo_ack (smtp_t smtp)
status
=
smtp_readline
(
smtp
);
if
((
smtp
->
ptr
-
smtp
->
buffer
)
>
4
&&
smtp
->
buffer
[
3
]
==
'-'
)
multi
=
1
;
if
(
status
==
0
)
{
if
(
status
==
0
)
{
smtp
->
ptr
=
smtp
->
buffer
;
if
(
!
mu_c_strncasecmp
(
smtp
->
buffer
,
"250-STARTTLS"
,
12
))
...
...
@@ -1398,6 +1413,7 @@ smtp_parse_ehlo_ack (smtp_t smtp)
{
char
*
p
;
size_t
n
=
strtoul
(
smtp
->
buffer
+
9
,
&
p
,
10
);
if
(
*
p
!=
'\n'
)
MU_DEBUG1
(
smtp
->
mailer
->
debug
,
MU_DEBUG_ERROR
,
"suspicious size declaration: %s"
,
...
...
@@ -1409,12 +1425,14 @@ smtp_parse_ehlo_ack (smtp_t smtp)
else
if
(
!
mu_c_strncasecmp
(
smtp
->
buffer
,
"250-AUTH"
,
8
))
{
char
*
name
,
*
s
;
smtp
->
capa
|=
CAPA_AUTH
;
for
(
name
=
strtok_r
(
smtp
->
buffer
+
8
,
" "
,
&
s
);
name
;
name
=
strtok_r
(
NULL
,
" "
,
&
s
))
{
struct
auth_mech_record
*
mechs
=
auth_mech_list
;
for
(;
mechs
->
name
;
mechs
++
)
{
mu_rtrim_cset
(
name
,
"
\r\n
"
);
...
...
Please
register
or
sign in
to post a comment