Exemple #1
0
    def getGooglePlay(self):
        typ, data = self.m.search(None, '(FROM "*****@*****.**")')
        for num in data[0].split():
            typ, data = self.m.fetch(num, '(RFC822)')
            #print 'Message %s\n%s\n' % (num, data[0][1])
            msg = HeaderParser().parsestr(data[0][1])
            
            print msg['From']
            print msg['To']
            print msg['Subject']
            print msg.get_payload()
  	
  	def close(self):
  		self.m.close()
		self.m.logout()
Exemple #2
0
    def getGooglePlay(self):
        typ, data = self.m.search(None, '(FROM "*****@*****.**")')
        messages = []
        for num in data[0].split():
            typ, data = self.m.fetch(num, '(RFC822)')
            msg = HeaderParser().parsestr(data[0][1])
            payload = msg.get_payload()
            payload = self.parsePayload(payload)
            
            messages.append({"from":msg['From'], "to":msg['To'], "subject":msg['Subject'], "payload":payload})
            soup = BeautifulSoup(payload)
            #print(soup.prettify())
            #for link in soup.find_all('a'):
            #    print(link.get('href'))
            #for link in soup.find_all('img'):
            #    webbrowser.open(link.get('src'))
            for meta in soup.find_all('meta'):
                if meta.get('itemprop') == 'orderNumber':
                    print meta.get('content')
                elif meta.get('itemprop') == 'price':
                    print meta.get('content')
                elif meta.get('itemprop') == 'image':
                    f = open(msg['Subject'],'wb')
                    f.write(urllib.urlopen(meta.get('content')).read())
                    f.close()

        return messages    
Exemple #3
0
    def getAmazon(self):
        typ, data = self.m.search(None, '(FROM "*****@*****.**")')
        messages = []
        for num in data[0].split():
            typ, data = self.m.fetch(num, '(RFC822)')
            #print 'Message %s\n%s\n' % (num, data[0][1])
            msg = HeaderParser().parsestr(data[0][1])
            payload = msg.get_payload()
            payload = self.parsePayload(payload)
            messages.append({"from":msg['From'], "to":msg['To'], "subject":msg['Subject'], "payload":payload})

            
        return messages    
Exemple #4
0
    def getSquare(self):
        typ, data = self.m.search(None, '(FROM "*****@*****.**")')
        messages = []
        for num in data[0].split():
            typ, data = self.m.fetch(num, '(RFC822)')
            #print 'Message %s\n%s\n' % (num, data[0][1])
            msg = HeaderParser().parsestr(data[0][1])
            payload = msg.get_payload()
            payload = self.parsePayload(payload)
            messages.append({"from":msg['From'], "to":msg['To'], "subject":msg['Subject'], "payload":payload})

            # print msg['From']
            # print msg['To']
            # print msg['Subject']
            # print msg.get_payload()
        return messages    
    def _rfc822_string_to_dict(
        cls, rfc822_string: str
    ) -> Dict[str, Union[List[str], str]]:
        """Extracts metadata information from a metadata-version 2.1 object.

        https://www.python.org/dev/peps/pep-0566/#json-compatible-metadata

        - The original key-value format should be read with email.parser.HeaderParser;
        - All transformed keys should be reduced to lower case. Hyphens should
          be replaced with underscores, but otherwise should retain all other
          characters;
        - The transformed value for any field marked with "(Multiple-use")
          should be a single list containing all the original values for the
          given key;
        - The Keywords field should be converted to a list by splitting the
          original value on whitespace characters;
        - The message body, if present, should be set to the value of the
          description key.
        - The result should be stored as a string-keyed dictionary.
        """
        metadata: Dict[str, Union[List[str], str]] = {}
        parsed = HeaderParser().parsestr(rfc822_string)
        metadata_fields = VERSIONED_METADATA_FIELDS[parsed.get("Metadata-Version")]

        for key, value in parsed.items():
            if key in metadata_fields["MULTI"]:
                metadata.setdefault(key, []).append(value)
            elif key in metadata_fields["TREAT_AS_MULTI"]:
                metadata[key] = [val.strip() for val in value.split(",")]
            elif key == "Description":
                metadata[key] = inspect.cleandoc(value)
            else:
                metadata[key] = value

        # Handle the message payload
        payload = parsed.get_payload()
        if payload:
            if "Description" in metadata:
                print("Both Description and payload given - ignoring Description")
            metadata["Description"] = payload

        return _canonicalize(metadata)
Exemple #6
0
import temp as oauth2

# Set up your Consumer and Token as per usual. Just like any other
# three-legged OAuth request.

email = '*****@*****.**'
client_id="977739430087-iul45rh0o6qjp6bq3sdhhrjuth5f61rv.apps.googleusercontent.com"
client_secret="7TI2GD3ANT537Yyi_yF0fwM-"
token = oauth.Token(client_id, client_secret)
consumer = oauth.Consumer('anonymous', 'anonymous')
url = "https://mail.google.com/mail/b/" + email +"/imap/"

 
M = imaplib.IMAP4_SSL('imap.gmail.com')
M.authenticate(url, consumer, token)
#M.authenticate('XOAUTH2', lambda x: oauth2string)
#M.login('*****@*****.**', 'Yankswin272009')
M.select()
typ, data = M.search(None, '(FROM "*****@*****.**")')
for num in data[0].split():
    typ, data = M.fetch(num, '(RFC822)')
    #print 'Message %s\n%s\n' % (num, data[0][1])
    msg = HeaderParser().parsestr(data[0][1])
    
    print msg['From']
    print msg['To']
    print msg['Subject']
    print msg.get_payload()
    
M.close()
M.logout()