示例#1
0
def send_info(s, lst, sub, text, q):
    # q is Queue()
    url = 'http://webmail.fil.bg.ac.rs/src/'
    global current_info
    global glst
    global subject
    global body

    glst = list(lst)
    subject = sub
    body = text

    # list consists of tuples with one element, e.g. ([email protected], )
    for i in glst:
        q.put_nowait(1)
        recipient = i[0]

        mail_signature = "\nS poštovanjem,\nMilan Todorović\n\nBiblioteka Katedre za germanistiku\nFilološki fakultet\n" \
                "Univerzitet u Beogradu\nStudentski trg 3\nTel: 011/2021-698\nRadno vreme: 9.00-17.00"

        files = {"startMessage": (None, "1"),
                     "session": (None, "1"),
                     "passed_id": (None, ""),
                     "send_to": (None, recipient),
                     "send_to_cc": (None, ""),
                     "send_to_bcc": (None, ""),
                     "subject": (None, subject),
                     "mailprio": (None, "3"),
                     "body": (None, body+mail_signature),
                     "send": (None, "Send"),
                     "attachfile": ("", ""),
                     "MAX_FILE_SIZE": (None, "20971520"),
                     "username": (None, "milan.todorovic"),
                     "smaction": (None, ""),
                     "mailbox": (None, "INBOX"),
                     "composesession": (None, "1"),
                     "querystring": (None, "mailbox=INBOX&startMessage=1")}

        left_side = url + 'left_main.php'
        right_side = url + 'right_main.php'
        try:
            l = s.get(left_side)
            r = s.get(right_side)
            print('Loading left frame: ', l.status_code)
            print('Loading right frame: ', r.status_code)
        except ConnectionError:
            q.put_nowait(2)
            n = [i[0] for i in glst if i[0] not in current_info]
            q.put_nowait(n)
            q.put_nowait(sub)
            q.put_nowait(text)
            q.close()

        time.sleep(1)
        compose = url + 'compose.php?mailbox=INBOX&startMessage=1'
        r = s.get(compose)
        print('Enterying "Compose": ', r.status_code)

        send = url + 'compose.php'
        time.sleep(1)
        r = s.post(send, files=files, allow_redirects=False)
        print('Mail sent: ', r.status_code)
        print('Redirecting to: ', r.headers['Location'])
        r = s.get(r.headers['Location'])
        print('Redirected to home page: ', r.status_code)
        print('Info successfully sent.')
        current_info.append(i[0])
        DataBase.unsentInformation_delete(i[0], sub)
    q.put_nowait(0)
    q.close()
    current_info = []
    glst = []
    body = None
    subject = None

    return 0