# Copyright (c) 2019, JINGROW and contributors
# License: MIT. See LICENSE

import imaplib
import poplib

from jingrow.utils import cint


def get_port(pg):
	if not pg.incoming_port:
		if pg.use_imap:
			pg.incoming_port = imaplib.IMAP4_SSL_PORT if pg.use_ssl else imaplib.IMAP4_PORT

		else:
			pg.incoming_port = poplib.POP3_SSL_PORT if pg.use_ssl else poplib.POP3_PORT

	return cint(pg.incoming_port)
