Python imaplib._MAXLINE Examples
The following are 8
code examples of imaplib._MAXLINE().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
imaplib
, or try the search function
.
Example #1
Source File: auto_unsubscriber.py From automate-the-boring-stuff-projects with MIT License | 6 votes |
def unsub_scan(user_name, user_pass): """Returns a list of the unsubscribe links in a Gmail inbox.""" unsub_links = [] imaplib._MAXLINE = 10000000 imap_obj = imapclient.IMAPClient('imap.gmail.com', ssl=True) imap_obj.login(user_name, user_pass) imap_obj.select_folder('INBOX', readonly=True) unique_ids = imap_obj.search(['ALL']) for identifier in unique_ids: raw_message = imap_obj.fetch([identifier], ['BODY[]', 'FLAGS']) message = pyzmail.PyzMessage.factory(raw_message[identifier][b'BODY[]']) html = message.html_part.get_payload().decode(message.html_part.charset) soup = bs4.BeautifulSoup(html, 'lxml') link_elems = soup.select('a') for selected in link_elems: if 'unsubscribe' in str(selected): unsub_links.append(selected.get('href')) imap_obj.logout() return unsub_links
Example #2
Source File: test_imaplib.py From oss-ftp with MIT License | 5 votes |
def test_linetoolong(self): class TooLongHandler(SimpleIMAPHandler): def handle(self): # Send a very long response line self.wfile.write('* OK ' + imaplib._MAXLINE*'x' + '\r\n') with self.reaped_server(TooLongHandler) as server: self.assertRaises(imaplib.IMAP4.error, self.imap_class, *server.server_address)
Example #3
Source File: test_imaplib.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_linetoolong(self): class TooLongHandler(SimpleIMAPHandler): def handle(self): # Send a very long response line self.wfile.write(b'* OK ' + imaplib._MAXLINE * b'x' + b'\r\n') with self.reaped_server(TooLongHandler) as server: self.assertRaises(imaplib.IMAP4.error, self.imap_class, *server.server_address)
Example #4
Source File: test_imaplib.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_linetoolong(self): class TooLongHandler(SimpleIMAPHandler): def handle(self): # Send a very long response line self.wfile.write(b'* OK ' + imaplib._MAXLINE*b'x' + b'\r\n') with self.reaped_server(TooLongHandler) as server: self.assertRaises(imaplib.IMAP4.error, self.imap_class, *server.server_address)
Example #5
Source File: unsubscriber.py From automate-the-boring-stuff-projects with MIT License | 5 votes |
def unsubscribe(imap_address, email_address, password): """Checks unsubscribe links within emails and opens link Args: imap_address (str): email providers imap address email_address (str): email address password (str): password for email Returns: None """ imaplib._MAXLINE = 10000000 imapObj = imapclient.IMAPClient(imap_address, ssl=True) # See https://support.google.com/accounts/answer/6010255 if (Login Error) imapObj.login(email_address, password) imapObj.select_folder('INBOX', readonly=True) UIDs = imapObj.search(['ALL']) for u in UIDs: rawMessages = imapObj.fetch([u], ['BODY[]', 'FLAGS']) message = pyzmail.PyzMessage.factory(rawMessages[u][b'BODY[]']) if message.html_part: html = message.html_part.get_payload().decode(message.html_part.charset) soup = bs4.BeautifulSoup(html, 'html.parser') linkElems = soup.select('a') for link in linkElems: if 'unsubscribe' in link.text.lower(): url = link.get('href') print('opening {}: '.format(url)) webbrowser.open(url) imapObj.logout()
Example #6
Source File: download_torrent.py From automate-the-boring-stuff-projects with MIT License | 5 votes |
def check_for_torrents(imap_address, email_address, password, verified_creds): """Checks email for torrent links from verified accounts Args: imap_address (str): email providers imap address email_address (str): email address password (str): password for email verified_creds (dict): dict containing verfied email and password """ imaplib._MAXLINE = 10000000 imapObj = imapclient.IMAPClient(imap_address, ssl=True) # See https://support.google.com/accounts/answer/6010255 if (Login Error) imapObj.login(email_address, password) imapObj.select_folder('INBOX', readonly=True) UIDs = imapObj.search(['FROM ' + verified_creds['email']]) links = [] if UIDs: for u in UIDs: rawMessages = imapObj.fetch([u], ['BODY[]', 'FLAGS']) message = pyzmail.PyzMessage.factory(rawMessages[u][b'BODY[]']) text = message.text_part.get_payload().decode(message.text_part.charset) if verified_creds['password'] in text: html = message.html_part.get_payload().decode(message.html_part.charset) links.append(html) imapObj.delete_messages(UIDs) imapObj.expunge() imapObj.logout() return links
Example #7
Source File: test_imaplib.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_linetoolong(self): class TooLongHandler(SimpleIMAPHandler): def handle(self): # Send a very long response line self.wfile.write('* OK ' + imaplib._MAXLINE*'x' + '\r\n') with self.reaped_server(TooLongHandler) as server: self.assertRaises(imaplib.IMAP4.error, self.imap_class, *server.server_address)
Example #8
Source File: test_imaplib.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_linetoolong(self): class TooLongHandler(SimpleIMAPHandler): def handle(self): # Send a very long response line self.wfile.write(b'* OK ' + imaplib._MAXLINE * b'x' + b'\r\n') with self.reaped_server(TooLongHandler) as server: self.assertRaises(imaplib.IMAP4.error, self.imap_class, *server.server_address)