Beispiel #1
0
def mailDownloader(mnt, dst, tsv):
    with open(tsv) as tsvfile:
        reader = csv.reader(tsvfile, delimiter='\t')
        array = []
        for row in reader:
            try:
                fulldomain = getaddresses([
                    row[2],
                ])
            except:
                print("[ERROR] Can't parse the following row, skipping it : " +
                      ', '.join(row))
                pass

            if fulldomain:
                email = fulldomain.pop()[1]
                contact = email.split("@")[0]
                domain = email.split("@")[-1]
                fileprefix = row[0][1:3]
                URI = "/" + domain + "/" + contact + "/" + fileprefix + "/" + row[
                    0]
                fullpath = mnt + URI
                localfile = "/home/learning/" + args.bayes + "-archive/" + row[
                    0]
                if isFileExist(localfile) == False:
                    try:
                        shutil.copy2(mnt + URI, dst)
                        if args.debug == True:
                            print("GET :", fullpath)
                    except:
                        pass
Beispiel #2
0
def emailFromAdmin(recipient, sub, content, wholelist=False):

    if not bballdb.getSendEmails():
        logging.info("Emails are disabled; not sending email To: %s Subject: %s" % (recipient, sub) )
        # logging.info(content)
        return

    logging.info("Sent email To: %s Subject: %s" % (recipient, sub) )
    logging.info(content)

    if recipient is not None:
      to = [recipient]
    else:
      to = []

    if wholelist:
      # Add the A List recipients
      to.extend(email.split()[0] for name,email in bballdb.loadAList(onlySendEmail=True)) # only use first name on a line
      # Add the B List recipients
      to.extend(email.split()[0] for name,email in bballdb.loadBList(onlySendEmail=True)) # only use first name on a line

    # Only unique entries, sorted
    to = list(sorted(set([i.lower() for i in to])))

    if not to:
        logging.warning('No recipients, not sending email')
        return

    mail.send_mail(sender=ADMIN_EMAIL,
                       to=to,
                       subject=sub,
                       body=content)
 def preprocessEmailData(self):
     '''
     this method is used as a driver that calls different methods for processing data
     :return: void
     '''
     parser = Parser() # Added for extracting only the body of the email
     tokens = self.Ngram.loadCorpus()
     email = parser.parsestr(tokens) # Added for extracting only the body of the email
     email_body_list = [email.split('Body:')[-1] for email in tokens.split('##########################################################')] # Added for extracting only the body of the email
     tokendata=[]
     for txt in email_body_list:
         tokendata.append(nltk.wordpunct_tokenize(txt))
     merged = list(itertools.chain.from_iterable(tokendata)) # flattening the tokendata which is a list of list.
     preprocessedText = self.Ngram.preprocessData(merged)
     stemmedwords = self.Ngram.stemWords(preprocessedText)
     self.Ngram.writeToFile(stemmedwords,'preprocessedEmailBody')
     posTaggedList = self.Ngram.createPOSTagging(stemmedwords)
     preprocessedListwithoutNouns = self.Ngram.removeProperNouns(posTaggedList)
     print 'removed proper nouns'
     print datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M:%S')
     bigramslist = self.Ngram.createBigrams(preprocessedListwithoutNouns)
     print 'bigrams created successfully'
     print datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M:%S')
     trigramslist = self.Ngram.createTrigrams(preprocessedListwithoutNouns)
     print 'trigrams created successfully'
     self.Ngram.writeToFile(bigramslist,'emailbigramList')
     self.Ngram.writeToFile(trigramslist,'emailtrigramList')
     print datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M:%S')
Beispiel #4
0
 def signin(cls, email, type):
     if not '@' in email:
         raise EmailError("malformed e-mail")
     hash = hashlib.md5(email).hexdigest()
     image = 'http://0.gravatar.com/avatar/%s' % hash
     name = string.capwords(email.split('@')[0].replace('.', ' '))
     # prevents double signin...
     previous_signin = db.GqlQuery(
         "SELECT * FROM Signin WHERE email = '%s' AND active = true" %
         email).get()
     if previous_signin:
         try:
             cls.deactivate_staffer(email)
         except:
             logging.info("Failed deactivating old Signin object.")
     s = Signin(email=email, type=type, image_url=image, name=name)
     DailyCount.increment_and_get()
     s.put()
     if "mark.hutsell" in email or "some.other.evilguy" in email:
         mail.send_mail(sender="Signin Machine <*****@*****.**>",
                        to="Emergency Paging System <*****@*****.**>",
                        subject="Sign-in: " + email,
                        body="Sign in")
         urlfetch.fetch(
             "http://www.dustball.com/call/call.php?str=Sign+in+" + email)
     return s
Beispiel #5
0
def matchEmailstoAddresses(email):
    matched = False
    matches = []

    # finds match of the brand in the email, can have several
    for brand_entry in brands_dict.keys():
        clean = email.replace(".com","")
        if brand_entry[1] in clean:
            matches.append(brand_entry)
            matched = True;

    # cleans up the email address
    email = email.split('<')
    email = email[len(email)-1].strip('>')

    # if there are matches match to the longest brand name
    if matched:
        longest = matches[0]
        for match in matches:
            if (len(match[1]) > len(longest[1])):
                longest = match

        brands_dict[longest] = email
        return longest[0]

    # else add to list of unmatched brands
    else:
        unmatched.append(email)
        return unmatchedIndex ##UNMATCHED in the db is 1
    def _get_host(self, email):
        '''
        Extracts imap host and port number based on the email address. If the
        domain of the email is not recognized, it will try 'imap.domain.com'
        which is fairly standard.

        Parameters
        ==========
        email: str, the email address. E.g. '*****@*****.**'

        Notes
        =====
        Please note that Gmail by default does not allow users to access
        their email in this way. You can change this setting here:
        https://support.google.com/mail/accounts/answer/78754
        '''
        #extract domain, e.g. 'yahoo.com'
        domain = email.split('@')[1]
        #Dict of known host/port tuples
        imap = {
            'yahoo.com': ('imap.mail.yahoo.com', 993),
            'gmail.com': ('imap.gmail.com', 993)
        }
        if imap.get(domain):
            return imap.get(domain)
        else:
            msg = 'Domain "%s" not recognized. Trying "imap.%s"'
            raise Warning(msg % (domain, domain))
            return ('imap.%s' % domain, 993)
Beispiel #7
0
def validate_email(email: str) -> bool:
    """
    Checks correctness of a username
    Throws exception if the syntax does not fit,
     the domain is blacklistet or is already in use
    :email name: Users email (Case sensitive)
    :return: true if no error occured
    """

    # check for correct email syntax
    if not EMAIL_REGEX.match(email):
        raise ApiException([Error(ErrorCode.INVALID_EMAIL, email)])

    # check for blacklisted email domains (we don't like disposable email)
    with db.connection:
        cursor = db.connection.cursor()
        cursor.execute("SELECT lower(domain) FROM email_domain_blacklist")
        rows = cursor.fetchall()
        # Get list of  blacklisted domains (so we can suffix-match incoming emails
        # in sublinear time)
        blacklisted_email_domains = marisa_trie.Trie(map(lambda x: x[0], rows))

        domain = email.split("@")[1].lower()
        if domain in blacklisted_email_domains:
            raise ApiException([Error(ErrorCode.BLACKLISTED_EMAIL, email)])

        # ensue that email adress is unique
        cursor.execute("SELECT id FROM `login` WHERE LOWER(`email`) = %s",
                       (email.lower(),))

        if cursor.fetchone() is not None:
            raise ApiException([Error(ErrorCode.EMAIL_REGISTERED, email)])

    return True
Beispiel #8
0
def sendNotification(df):

    import smtplib, ssl

    companyEmail = pd.unique(df['Email'])
    from email.mime.multipart import MIMEMultipart
    from email.mime.text import MIMEText
    port = 465  # For SSL
    smtp_server = "smtp.gmail.com"
    sender_email = "*****@*****.**"  # Enter your address

    password = '******'

    context = ssl.create_default_context()
    for email in companyEmail:

        print('Sending Email to ', email)
        grouped = df.groupby('Email').get_group(email)
        str_msg = "recieved {}  files ".format(grouped['Title'].count())

        print(grouped)
        email2 = email.split('@')
        message = """\
        Subject: VH-Files recieved from """ + email2[0] + """

        We have recieved your files: \n""" + str(
            grouped['Title'].to_string()).split('   ')[1] + '      ' + str(
                grouped['File Size'].to_string()).split(
                    '   ')[1] + '      ' + str(datetime.now())

        with smtplib.SMTP_SSL(smtp_server, port, context=context) as server:
            server.login(sender_email, password)

            server.sendmail(sender_email, email, message)
Beispiel #9
0
 def __get_tokens(self, rcptto):
     c = self.get_cursor()
     format_strings = ','.join(['%s'] * len(rcptto))
     recipients = tuple([re.sub(r'^(drop|bucket)-comment-', r'', email.split('@')[0]) for email in rcptto])
     c.execute("""select `type`, `data`
               from `auth_tokens`
               where token in (%s)""" % format_strings, recipients)
     return [(token_type, json.loads(data)) for token_type, data in c.fetchall()]
Beispiel #10
0
def from_email_parse(msg):
    email = str(make_header(decode_header(msg['From'])))
    name = ''
    fields = email.split("<")
    if len(fields) > 1:
        name = fields[0]
        email = fields[1].replace(">", "")
    return name, email
Beispiel #11
0
 def _parse_email_address(self, email):
     """
     Returns 'email' as:
     ... (address_name, address_domain)
     E.g. _parse_email_address('*****@*****.**')
     ... will return: ('account', 'dom.com')
     Essentially just splits the string at '@'
     """
     return email.split('@')
Beispiel #12
0
def get_pop3host(email):

    try:
        pop3_host = 'pop3.%s' % (email.split('@')[-1])

        return pop3_host

    except:

        return ''
Beispiel #13
0
 def __get_rivers(self, rcptto):
     c = self.get_cursor()
     format_strings = ','.join(['%s'] * len(rcptto))
     c.execute(
         """select `id`
               from `rivers`
               where river_active = 1
               and email_id in (%s)""" % format_strings,
         tuple([email.split('@')[0] for email in rcptto]))
     return [river_id for river_id, in c.fetchall()]
Beispiel #14
0
def get_smtphost(email):

    try:

        smtp_host='smtp.'+email.split('@')[-1]

        return smtp_host

    except:

        return ''
Beispiel #15
0
    def create_user(self,
                    email: str,
                    username: str = None,
                    password: str = None,
                    is_staff: bool = False,
                    is_superuser: bool = False) -> UserHandle:
        """Add the specified user to the database, with email confirmed.

        Keyword arguments:
        username -- string (default user portion of email)
        password -- string (default email)
        is_staff -- bool (default False)
        is_superuser -- bool (default False)
        """
        if not username:
            username = email.split('@')[0]
        if not password:
            password = email

        hmac = hashlib.pbkdf2_hmac('sha256', password.encode('utf-8'), b'salt',
                                   1)
        hmac_base64 = binascii.b2a_base64(hmac, newline=False)

        password_hash = '$'.join(
            ['pbkdf2_sha256', '1', 'salt',
             hmac_base64.decode('ascii')])

        self._sql("""
                WITH u AS (
                    INSERT INTO auth_user (
                        first_name, last_name, is_active, date_joined,
                        email, username, password, is_staff, is_superuser
                    )
                    VALUES (
                        'First', 'Last', TRUE, NOW(),
                        %(email)s, %(username)s, %(password_hash)s,
                        %(is_staff)s, %(is_superuser)s
                    )
                    RETURNING id, email
                )
                INSERT INTO account_emailaddress (
                    verified, "primary", user_id, email
                )
                SELECT TRUE, TRUE, u.id, u.email
                FROM u
            """,
                  email=email,
                  username=username,
                  password_hash=password_hash,
                  is_staff=is_staff,
                  is_superuser=is_superuser)

        return UserHandle(username, password, email)
Beispiel #16
0
 def _get_email(self, email):
   '''Given an email address, check the email_remapping table to see if the email
   should be sent to a different address. This function also handles overriding
   the email domain if ignore_vcs_email_domain is set or the domain was missing'''
   if email in self.email_remapping:
     return self.email_remapping[email]
   prefix, domain = email.split("@", 2)
   if prefix in self.email_remapping:
     return self.email_remapping[prefix]
   if "." not in domain or config.ignore_vcs_email_domain:
     return "%s@%s" % (prefix, config.email_domain_name)
   return email
Beispiel #17
0
def save_developer(email):
	# add if we dont exist
	if not Developer.objects.filter(email=email).first():
		names = email.split('.')
		first_name = ""
		last_name = ""
		if len(names) > 1:
			first_name = names[0]
			last_name = names[1].split('@')[0]

		dev = Developer(email=email, first_name=first_name, last_name=last_name)
		dev.save()
Beispiel #18
0
		def _validate(email):
			"""validate an email field"""
			if email:
				if "," in email:
					email = email.split(",")[-1]
				if not validate_email_add(email):
					# try extracting the email part and set as sender
					new_email = extract_email_id(email)
					if not (new_email and validate_email_add(new_email)):
						webnotes.msgprint("%s is not a valid email id" % email,
							raise_exception = 1)
					email = new_email
			return email
Beispiel #19
0
 def __get_tokens(self, rcptto):
     c = self.get_cursor()
     format_strings = ','.join(['%s'] * len(rcptto))
     recipients = tuple([
         re.sub(r'^(drop|bucket)-comment-', r'',
                email.split('@')[0]) for email in rcptto
     ])
     c.execute(
         """select `type`, `data`
               from `auth_tokens`
               where token in (%s)""" % format_strings, recipients)
     return [(token_type, json.loads(data))
             for token_type, data in c.fetchall()]
Beispiel #20
0
 def _validate(email):
     """validate an email field"""
     if email:
         if "," in email:
             email = email.split(",")[-1]
         if not validate_email_add(email):
             # try extracting the email part and set as sender
             new_email = extract_email_id(email)
             if not (new_email and validate_email_add(new_email)):
                 webnotes.msgprint("%s is not a valid email id" % email,
                                   raise_exception=1)
             email = new_email
     return email
Beispiel #21
0
def check_email_catchall(email):

    try:

        from_address = EMAIL_HOST_USER

        # Get domain for DNS lookup
        domain = email.split('@')[-1]

        # experimental part
        # we make a deliberately non-existent email with the required domain
        first_part, second_part = email.split('@')
        fake_email = first_part + 'ashdfabebdfjksjakuahfka' + '@' + second_part

        # MX record lookup
        records = dns.resolver.resolve(domain, 'MX')
        mx_record = records[0].exchange
        mx_record = str(mx_record)

        # SMTP lib setup (use debug level for full output)
        server = smtplib.SMTP()
        server.set_debuglevel(0)

        # SMTP Conversation
        server.connect(mx_record)
        server.helo(server.local_hostname
                    )  # server.local_hostname(Get local server hostname)
        server.mail(from_address)
        code, message = server.rcpt(str(fake_email))
        server.quit()

        # Assume SMTP response 250 is success
        if code == 250:
            return True
        else:
            return False

    except Exception:
        return False
Beispiel #22
0
def get_pop3_host(email):
    """获取邮箱对应的服务商的 POP3 服务器地址"""
    maps = {
        'qq.com': 'pop.qq.com',
        'gmail.com': 'pop.gmail.com',
        '126.com': 'pop.126.com',
        '163.com': 'pop.163.com',
        'sohu.com': 'pop3.sohu.com',
        'sina.com': 'pop3.sina.com',
        '139.com': 'pop.139.com',
        'foxmail.com': 'pop.foxmail.com'
    }
    tail = email.split('@')[1]
    return maps[tail] if tail in maps else None
Beispiel #23
0
def save_developer(email):
    # add if we dont exist
    if not Developer.objects.filter(email=email).first():
        names = email.split('.')
        first_name = ""
        last_name = ""
        if len(names) > 1:
            first_name = names[0]
            last_name = names[1].split('@')[0]

        dev = Developer(email=email,
                        first_name=first_name,
                        last_name=last_name)
        dev.save()
def email_cleaning(text):
    # Data cleaning

    email = text.lower()
    # clean and tokenize document string
    email_content = email.split()
    word_list = []
    for i in email_content:
        x = 0
        if (('http' not in i) and ('@' not in i) and ('<.*?>' not in i)
                and i.isalnum() and (not i in stop_words)):
            word_list += [i]

    return word_list
Beispiel #25
0
    def tagEmail(self, email, tags='All', fullName=None):

        newTagList = tags.split(',')
        if fullName == None:
            fullName = email.split('@')[0]
            # trying to guess the full name.
            fullName = fullName.replace('.', ' ')
            fullName = fullName.replace('_', ' ')
        if self.emailDict.has_key(email):
            fullName, tagList = self.emailDict[email]
            newTagList.extend(tagList)
            newTagList = list(set(newTagList))

        self.emailDict[email] = (fullName, newTagList)
    def eom(self):
        ''' End of Message '''
        self.fp.seek(0)
        msg = email.message_from_file(self.fp)

        msg_id = msg.get('In-Reply-To', None)
        if msg_id is None:
            self.log('No In-Reply-To, keep going')
            return Milter.CONTINUE

        # Ensure we don't get extra lines in the message-id
        msg_id = msg_id.split('\n')[0].strip()

        self.log('msg-ig %s' % msg_id)
        self.log('To %s' % msg['to'])
        self.log('Cc %s' % msg.get('cc'))
        self.log('From %s' % msg['From'])

        # Ensure the user replied to his/her own notification, not that
        # they are trying to forge their ID into someone else's
        salt = pagure.APP.config.get('SALT_EMAIL')
        m = hashlib.sha512('%s%s%s' % (msg_id, salt, clean_item(msg['From'])))
        email = msg['to']
        if 'reply+' in msg.get('cc'):
            email = msg['cc']
        if not 'reply+' in email:
            self.log('No valid recipient email found in To/Cc: %s' % email)
        tohash = email.split('@')[0].split('+')[-1]
        if m.hexdigest() != tohash:
            self.log('hash: %s' % m.hexdigest())
            self.log('tohash:   %s' % tohash)
            self.log('Hash does not correspond to the destination')
            return Milter.CONTINUE

        if msg['From'] and msg['From'] == pagure.APP.config.get('FROM_EMAIL'):
            self.log("Let's not process the email we send")
            return Milter.CONTINUE

        msg_id = clean_item(msg_id)

        if msg_id and '-ticket-' in msg_id:
            self.log('Processing issue')
            return self.handle_ticket_email(msg, msg_id)
        elif msg_id and '-pull-request-' in msg_id:
            self.log('Processing pull-request')
            return self.handle_request_email(msg, msg_id)
        else:
            self.log('Not a pagure ticket or pull-request email, let it go')
            return Milter.CONTINUE
Beispiel #27
0
    def _get_email(self, email):
        '''Given an email address, check the email_remapping table to see if the email
        should be sent to a different address. This function also handles overriding
        the email domain if ignore_vcs_email_domain is set or the domain was missing'''
        if not email or "@" not in email:
            return None

        if email in self.email_remapping.remap:
            return self.email_remapping.remap[email]
        prefix, domain = email.split("@", 2)
        if prefix in self.email_remapping.remap:
            return self.email_remapping.remap[prefix]
        if "." not in domain or config.ignore_vcs_email_domain:
            return "%s@%s" % (prefix, config.email_domain_name)
        return email
Beispiel #28
0
	def valid (self, email: str, company_id: Optional[int] = None) -> None:
		"""Validate an ``email'' address for ``company_id''"""
		self.setup (company_id = company_id)
		if not email:
			raise error ('empty email')
		email = email.strip ()
		if not email:
			raise error ('empty email (just whitespaces)')
		parts = email.split ('@')
		if len (parts) != 2:
			raise error ('expect exactly one "@" sign')
		(user, domain) = parts
		self.valid_user (user)
		self.valid_domain (domain)
		self.check_blacklist (email, company_id)
Beispiel #29
0
def normalize_email(email):
    if not email:
        return None

    result = ""

    for token in email.split():
        if token == "dot":
            result += "."
        elif token == "at":
            result += "@"
        else:
            result += token

    return result
def preprocess(emails):
    """
    Performs preprocessing operations such as:
        1. Removing signature lines (only English emails are supported)
        2. Removing new line characters.
    """
    n_emails = len(emails)
    for i in range(n_emails):
        email = emails[i]
        email, _ = extract_signature(email)
        lines = email.split('\n')
        for j in reversed(range(len(lines))):
            lines[j] = lines[j].strip()
            if lines[j] == '':
                lines.pop(j)
        emails[i] = ' '.join(lines)
Beispiel #31
0
 def signin(cls, email, type):
   if not '@' in email:
     raise EmailError("malformed e-mail")
   hash = hashlib.md5(email).hexdigest()
   image = 'http://0.gravatar.com/avatar/%s' % hash
   name = string.capwords(email.split('@')[0].replace('.', ' '))
   # prevents double signin...
   previous_signin = db.GqlQuery("SELECT * FROM Signin WHERE email = '%s' AND active = true" % email).get()
   if previous_signin:
     try:
       cls.deactivate_staffer(email)
     except:
       logging.info("Failed deactivating old Signin object.")
   s = Signin(email=email, type=type, image_url=image, name=name)
   s.put()
   return s
Beispiel #32
0
  def _initializePath(self, email):
    basePath = os.path.join( os.environ['HOME'], 'rapp_platform_files', 'emails' )

    if not os.path.exists( basePath ):
      RappUtilities.rapp_print("Language temporary directory does not exist. " + \
          'Path: ' + basePath)
      os.makedirs( basePath )

    username = email.split('@')[0]
    ## The temporary directory containing the configurations
    finalPath = tempfile.mkdtemp( prefix=username + '_', dir = basePath)

    RappUtilities.rapp_print('Email receiver path: ' + finalPath, 'DEBUG')

    # Delete temp file at termination
    # TODO: Check whether files are preserved long enough for the agent to collect
    atexit.register(shutil.rmtree, finalPath)
    return finalPath
Beispiel #33
0
    def _initializePath(self, email):
        basePath = os.path.join(os.environ['HOME'], 'rapp_platform_files',
                                'emails')

        if not os.path.exists(basePath):
            RappUtilities.rapp_print("Language temporary directory does not exist. " + \
                'Path: ' + basePath)
            os.makedirs(basePath)

        username = email.split('@')[0]
        ## The temporary directory containing the configurations
        finalPath = tempfile.mkdtemp(prefix=username + '_', dir=basePath)

        RappUtilities.rapp_print('Email receiver path: ' + finalPath, 'DEBUG')

        # Delete temp file at termination
        # TODO: Check whether files are preserved long enough for the agent to collect
        atexit.register(shutil.rmtree, finalPath)
        return finalPath
Beispiel #34
0
def detect_server(email, password, ssl=True):
    "Attempt to figure out the server protocol, hostname and username."
    def generate_hosts(domain):
        "Use heuristics to guess the valid hostname."
        for hostname in HOSTNAMES:
            yield '%s.%s' % (hostname, domain)
        yield domain

    def generate_users(email):
        "Use heuristics to guess the valid username."
        yield email
        username = email.split('@')[0]
        yield username
        # TODO: try splitting on common stuff like '.' or '-'.

    # TODO: this should be done in parallel. I am using a short timeout to
    # minimize the overall time, but if the last combo is the winning one, it
    # will have take a LONG time to find out.
    username, domain = email.split('@')
    protocol, hostname = None, None
    # By default, try non-SSL first.
    protocols = [('imap', 'pop3'), ('imaps', 'pop3s')]
    if ssl:
        # Reverse order, try SSL first.
        protocols.reverse()
    # Try hosts until we find one that works.
    for imap, pop3 in protocols:
        for tryhost in generate_hosts(domain):
            imapclient, pop3client = PROTOCOLS[imap], PROTOCOLS[pop3]
            try:
                
                client = imapclient(tryhost)
            except (imaplib.IMAP4.error, socket.error), e:
                try:
                    client = pop3client(tryhost)
                except (poplib.error_proto, socket.error), e:
                    continue
                else:
                    protocol, hostname = pop3, tryhost
                    break
            else:
                protocol, hostname = imap, tryhost
                break
Beispiel #35
0
def get_students_from_gmail( ):

	# This portion downloads from the spreadsheet
	try: import gspread
	except ImportError:
		print "Install gpsread library (on github @ https://github.com/burnash/gspread)"
		print "Note - library is super easy to install!"
		return

	user = get_credentials()
	
	# Login with your Google account
	gc = gspread.login(user[0],user[1])

	# Spreadsheets can be opened by their title in Google Docs
	spreadsheet = gc.open(spreadsheet_name)

	# Select worksheet by index
	worksheet = spreadsheet.get_worksheet(0)

	# Update cell with your form value
	#worksheet.update_cell(1, 2, 'woot!')

	ncells = 'A2:A' + str(num_students+1)
	cell_list = worksheet.range(ncells)
	names = []
	for cell in cell_list:
		names.append(cell.value)
	
	ncells = 'B2:B' + str(num_students+1)	
	cell_list = worksheet.range(ncells)
	emails = []
	for cell in cell_list:
		emails.append(cell.value)
	
	tokenized_emails = []
	for email in emails:
		tokenized_emails.append(email.split(' '))	
	
	students = zip(names, tokenized_emails)

	return students
Beispiel #36
0
 def signin(cls, email, type):
   if not '@' in email:
     raise EmailError("malformed e-mail")
   hash = hashlib.md5(email).hexdigest()
   image = 'http://0.gravatar.com/avatar/%s' % hash
   name = string.capwords(email.split('@')[0].replace('.', ' '))
   # prevents double signin...
   previous_signin = db.GqlQuery("SELECT * FROM Signin WHERE email = '%s' AND active = true" % email).get()
   if previous_signin:
     try:
       cls.deactivate_staffer(email)
     except:
       logging.info("Failed deactivating old Signin object.")
   s = Signin(email=email, type=type, image_url=image, name=name)
   DailyCount.increment_and_get()    
   s.put()
   if "xxxxx.xxxxx" in email or "yyyy.yyyy" in email:
       mail.send_mail(sender="Signin Machine <*****@*****.**>", to="Emergency Paging System <*****@*****.**>",
          subject="Sign-in: " + email, body="Sign in")
       urlfetch.fetch("http://www.dustball.com/call/call.php?str=Sign+in+"+email)
   return s
    def calculateWordWeights(email,wordWeights,emailVector):
        importantWordsFromEmail = {}
        sum = 0

        #count the number of words that are not stopwords and how often they occur
        for word in email.split():
            #TODO: Use regex to remove all punctuation here
            if word not in stopwords:
                importantWordsFromEmail[word] = importantWordsFromEmail.get(word,0)+1
                sum+=1

        #update the global count of each words
        for word in importantWordsFromEmail.keys():
            wordWeights[word] = wordWeights.get(word,0)+importantWordsFromEmail[word]

        #update the total number of words
        wordWeights["totalNumbers"] = wordWeights.get("totalNumbers",0) + sum

        #create a vector representing the email
        emailVector = vector(importantWordsFromEmail,wordWeights)
        return emailVector
Beispiel #38
0
    def calculateWordWeights(email,wordWeights,emailVector):
        importantWordsFromEmail = {}
        sum = 0

        #count the number of words that are not stopwords and how often they occur
        for word in email.split():
            #TODO: Use regex to remove all punctuation here
            if word not in stopwords:
                importantWordsFromEmail[word] = importantWordsFromEmail.get(word,0)+1
                sum+=1

        #update the global count of each words
        for word in importantWordsFromEmail.keys():
            wordWeights[word] = wordWeights.get(word,0)+importantWordsFromEmail[word]

        #update the total number of words
        wordWeights["totalNumbers"] = wordWeights.get("totalNumbers",0) + sum

        #create a vector representing the email
        emailVector = vector(importantWordsFromEmail,wordWeights)
        return emailVector
Beispiel #39
0
    def fill_database(self, recipients_count, scheduled_start=None, scheduled_end=None, scheduled_duration=None,
                      real_start=None, satellite_group=None):
        mq = factories.MailingFactory(satellite_group=satellite_group)
        for i in range(recipients_count):
            email = '*****@*****.**' % i
            MailingRecipient.create(mailing=mq, email=email, domain_name=email.split('@', 1)[1],
                                    contact=repr({'email': email, 'firstname': 'Cedric%d' % i}),
                                    next_try=datetime.utcnow())

        mq.status = MAILING_STATUS.READY
        if scheduled_start:
            mq.scheduled_start = scheduled_start
        if scheduled_end:
            mq.scheduled_end = scheduled_end
        if scheduled_duration:
            mq.scheduled_duration = scheduled_duration
        if real_start:
            mq.status = MAILING_STATUS.RUNNING
            mq.start_time = real_start
        mq.update_stats()
        mq.save()
Beispiel #40
0
	def __init__(self, email, password, username=None, domain=None, use_ssl=True):
		# validate email
		if basic_email_re.match(email):
			emailparts = email.split("@")
		else:
			raise ImapDbException(["EMAIL-VALIDATION"])
		# get the username from the email address
		if not username:
			username = emailparts[0]
		# get the domain name from the email address
		if not domain:
			domain = emailparts[1]
		# TODO: on failure automatically try various ways of connecting (Non-SSL, common server subdomains, etc.)
		# try to connect to the IMAP server
		# TODO: timeout? if you incorrectly connect to some servers with no SSL they hang
		IMAPClient.__init__(self, domain, use_uid=True, ssl=use_ssl)
		# try to log in with the username and password provided
		try:
			self.login(username, password)
		# IMAPClient.Error
		except Exception, e:
			raise ImapDbException(["AUTH", e.message])
Beispiel #41
0
    def create_user(self,
                    email: str,
                    username: str = None,
                    password: str = None) -> UserHandle:
        """Add the specified user to the database.

        When done with the User, `account_admin.destroy_user(user)`

        Keyword arguments:
        username -- string (default user portion of email)
        password -- string (default email)
        """
        if username is None: username = email.split('@')[0]
        if password is None: password = email
        var = self._execute_setvar('\n'.join([
            f'VAR = User.objects.create_user(',
            f'    username={repr(username)},',
            f'    password={repr(password)},',
            f'    email={repr(email)}',
            f')',
        ]))
        return UserHandle(var, username, password, email)
    def check_email_valid(self, email):
        """Check if email is valid. Check @ and .
        :email str
        return True/False
        """
        def get_validate_email(email):
            if not re.match(
                    r"^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*$",
                    email):
                return False
            return True

        if not email:
            return False

        emails = email.split(',')
        if len(emails) > 0:
            for email in emails:
                if not get_validate_email(email.strip()):
                    return False
                    break
        return True
Beispiel #43
0
    def get_email_author(self, msg):
        "Returns author's name and email if any"
        try:
            header_from = msg['From']
            splits = header_from.split('<', 1)
            name, email = splits if len(splits) == 2 else ('', header_from)
            email = email.split('>', 1)[0]
            if name:
                name, encoding = decode_header(name.strip(' "\''))[0]
                name = self.decode(name, encoding)
                name = name.strip(' \'"')
        except:
            email = name = None

        if not email:
            try:
                email = msg['Return-path']
                email.strip(' \'"<>')
            except Exception:
                email = None

        return name, email
Beispiel #44
0
    def get_email_author(self, msg):
        "Returns author's name and email if any"
        try:
            header_from = msg['From']
            splits = header_from.split('<', 1)
            name, email = splits if len(splits) == 2 else ('', header_from)
            email = email.split('>', 1)[0]
            if name:
                name, encoding = decode_header(name.strip(' "\''))[0]
                name = self.decode(name, encoding)
                name = name.strip(' \'"')
        except:
            email = name = None

        if not email:
            try:
                email = msg['Return-path']
                email.strip(' \'"<>')
            except Exception:
                email = None

        return name, email
Beispiel #45
0
 def post(self):
   email = self.request.get('email')
   if not '@' in email:
     email = '*****@*****.**' % email
   if email:
     hash=hashlib.md5(email).hexdigest()
     
     # Defaults
     image = 'http://0.gravatar.com/avatar/%s' % hash
     name = email.split('@')[0].replace('.', ' ')
     say = '%s, %s' % (random.choice(GREETINGS), name.split(' ')[0])
     text = "Welcome back to Hacker Dojo, %s!" % name.split(' ')[0]
     
     # If on staff
     if 'Staff' in self.request.get('type'):
       response = urlfetch.fetch('http://dojo.pbworks.com/api_v2/op/GetUserInfo/_type/jsontext/email/%s/token/%s' % (urllib.quote(email), get_token())).content
       if not 'appenginebot' in response:
         response = parse_json(response)
         image = response['image']
         name = response['name']
         say = "Staff member, %s" % name
         text = "Welcome back, %s. Remember to check out when you leave!" % name.split(' ')[0]  
     else:
       # TODO: contact signup app
       # if member
       #   say = "member" + name
       # else...
       
       # If new visitor
       s = Signin.all().filter('email =', email).get()
       if not s:
         say = "Welcome to Hacker Dojo!"
         text = "Congrats on your first visit, %s!" % name
     
     s = Signin(email=email, type=self.request.get('type'), image_url=image, name=name)
     s.put()
     broadcast(text=text, say=say)
   self.redirect('/')
Beispiel #46
0
def tokenize_to(to):
    """ Parse the To field and extract elements that should be anonymized """
    emails = set()
    tokens = set()

    # Get both aliases and email addresses
    fields = TKENSEP.split(to.lower())
    for token in fields:
        token = clean_token(token)
        if "@" in token:
            emails.add(token)
        elif len(token) != 0:
            tokens.add(token)

    # For every email address, extract element of interest (name, surname, domain…)
    for email in emails:
        fulluser, todom = email.split("@", 1)
        for user_part in USERSEP.split(fulluser, 4):
            if len(user_part) > 2:
                tokens.add(user_part)
        tokens.add(todom)

    return tokens
def check_email(): #查看邮件也可以用IMAP服务来实现,这里用POP3 =。=
    import poplib
    import email
    from email.parser import Parser
    from email.header import decode_header
    from email.utils import parseaddr
    def guess_charset(msg):
        # 先从msg对象获取编码:
        charset = msg.get_charset()
        # 如果获取不到,再从Content-Type字段获取:
        if charset is None:
            content_type = msg.get('Content-Type', '').lower()
            pos = content_type.find('charset=')
            if pos >= 0:
                charset = content_type[pos + 8:].strip()
        return charset

    #邮件的Subject或者Email中包含的名字都是经过编码后的str,要正常显示,就必须decode
    def decode_str(s):
        value, charset = decode_header(s)[0]
        if charset:
            value = value.decode(charset)
        return value

    #这个Message对象本身可能是一个MIMEMultipart对象,即包含嵌套的其他MIMEBase对象,嵌套可能还不止一层。
    #所以我们要递归地打印出Message对象的层次结构:
    # indent用于缩进显示:
    def print_info(msg, indent=0):
        if indent == 0:
            # 邮件的From, To, Subject存在于根对象上:
            for header in ['From', 'To', 'Subject']:
                value = msg.get(header, '')
                if value:
                    # 需要解码Subject字符串:
                    if header=='Subject':
                        value = decode_str(value)
                    # 需要解码Email地址:
                    else:
                        hdr, addr = parseaddr(value)
                        name = decode_str(hdr)
                        value = u'%s <%s>' % (name, addr)
                if header == 'From':
                    print(u'%s发件人:%s' % ('  ' * indent, value))
                elif header == 'To':
                    print(u'%s收件人:%s' % ('  ' * indent, value))
                elif header == 'Subject':
                    print(u'%s主题:%s' % ('  ' * indent, value))

        # 如果邮件对象是一个MIMEMultipart,
        # get_payload()返回list,包含所有的子对象:
        if (msg.is_multipart()):
            parts = msg.get_payload()
            for n, part in enumerate(parts):
                print('%spart %s' % ('  ' * indent, n))
                print('%s--------------------' % ('  ' * indent))
                # 递归打印每一个子对象:
                print_info(part, indent + 1)
        # 邮件对象不是一个MIMEMultipart,
        # 就根据content_type判断:
        else:
            content_type = msg.get_content_type()
            if content_type=='text/plain' or content_type=='text/html':
                # 纯文本或HTML内容:
                content = msg.get_payload(decode=True)
                # 要检测文本编码:
                charset = guess_charset(msg)
                if charset:
                    content = content.decode(charset)
                print(u'%s正文: %s' % ('  ' * indent, content + '...'))
            # 不是文本,作为附件处理:
            else:
                print(u'%s附件: %s' % ('  ' * indent, content_type))

    # 输入邮件地址,密码和POP3服务器地址:
    print u'请输入邮箱地址:',
    email = raw_input().strip()
    print u'请输入密码:',
    password = pwd_input()

    mail_check = (email.split('@'))[-1].split('.')[0]
    pop_check = 'pop.%s.com' % mail_check
    print u'已检测到您使用的是%s邮箱,已为您自动填写POP服务器地址:[%s]\n是否需要修改?[y/n]' % (mail_check,pop_check),
    ifchange = raw_input()
    if ifchange == 'y' or ifchange == 'Y':
        print u'好的,请修改POP服务器地址'
        print u'请输入POP服务器地址:',
        pop_server = raw_input().strip()
    else:
        pop_server = pop_check

    print u'是否使用SSL加密传输方式?[y/n]',
    ifuserssl = raw_input()
    if ifuserssl == 'y' or ifuserssl == 'Y':
        print u'好的,正在使用SSL加密服务...'
    else:
        print u'好的,不使用SSL加密服务...'

    k = 0
    while True:
        try:
            # 连接到POP3服务器:
            if ifuserssl == 'y' or ifchange == 'Y':
                server = poplib.POP3_SSL(pop_server)
            else:
                server = poplib.POP3(pop_server)
            # 可以打开或关闭调试信息:
            #server.set_debuglevel(1)
            # 可选:打印POP3服务器的欢迎文字:
            #print(server.getwelcome())

            # 身份认证:
            print u'正在进行身份认证...'
            server.user(email)
            server.pass_(password)

            print u'正在获取邮箱信息...'
            # stat()返回邮件数量和占用空间:
            print(u'邮件数量: %s  占用空间: %s' % server.stat())

            # list()返回所有邮件的编号:
            resp, mails, octets = server.list()

            # 可以查看返回的列表类似['1 82923', '2 2184', ...]
            #print(mails)

            print u'正在获取最新一封邮件...'
            # 获取最新一封邮件, 注意索引号从1开始:
            resp, lines, octets = server.retr(len(mails))
            #index = len(mails)
            #resp,lines,octets = server.retr(index)

            # lines存储了邮件的原始文本的每一行,
            # 可以获得整个邮件的原始文本:
            #msg_content = '\r\n'.join(lines)#
            # 解析邮件:
            #msg = Parser().parsestr(msg_content)#
            msg = Parser().parsestr('\r\n'.join(lines))

            #用POP3获取邮件其实很简单,要获取所有邮件,只需要循环使用retr()把每一封邮件内容拿到即可。
            #真正麻烦的是把邮件的原始内容解析为可以阅读的邮件对象。

            # 打印邮件内容:
            print_info(msg)

            # 慎重:可以根据邮件索引号直接从服务器删除邮件:
            # server.dele(len(mails))

            # 关闭连接:
            server.quit()
            print u'读取成功...'
            print u'正在返回菜单...'
            break
        except:
            print u'获取失败...'
            k+=1
            if k != 4:
                print u'正在重试(第%s次)...' % str(k)
            else:
                print u'重试次数已达到3次,正在返回菜单...'
                break
Beispiel #48
0
 def generate_users(email):
     "Use heuristics to guess the valid username."
     yield email
     username = email.split('@')[0]
     yield username
Beispiel #49
0
 def getMailIDs(self, mails):
     self.mailIDs = []
     for email in mails:
         email = email.split()
         self.mailIDs.append(int(email[0]))        
     return self.mailIDs