예제 #1
0
    def receive(self, message):
        logging.info("Message from: " + message.sender + " to: " + message.to)
        original = message.original

        fromEmail = message.sender
        to = message.to
        blocked = trusted = accountExists = blockMode = False

        m = re.search("(?<=\<)(.*?)(?=\>)", to)  # serching for gmail formatted emails. ex: 'user <*****@*****.**>'
        if m:  # gmail format
            to = m.group()

        emailName, emailDomain = to.split("@")

        fm = re.search(
            "(?<=\<)(.*?)(?=\>)", fromEmail
        )  # serching for gmail formatted emails. ex: 'user <*****@*****.**>'
        if fm:  # gmail format
            fromEmail = fm.group()

        existingUsers = UserDetails.gql("WHERE emailName = :1 LIMIT 1", emailName)
        for existingUser in existingUsers:
            accountExists = True
            blockMode = existingUser.trustedMode

        logging.info("Forwarder start")
        if original.has_key("X-Forwarded-To"):
            logging.info("Forwarder hit")
            forwardEmail = original.get("X-Forwarded-To")
            to = forwardEmail
            emailName, emailDomain = forwardEmail.split("@")
            logging.info("Forwarder: " + str(forwardEmail) + " :: to " + emailName)
            existingUsers2 = UserDetails.gql("WHERE emailName = :1 LIMIT 1", str(emailName))
            for existingUser2 in existingUsers2:
                accountExists = True
                blockMode = existingUser2.trustedMode
                accountName = existingUser2.accountName
                logging.info("Account Exists via Forward: " + str(emailName))
                fromEmail = emailName

        if accountExists:
            mailMessage = MailMessage()
            mailMessage.toAddress = to
            mailMessage.fromAddress = message.sender
            mailMessage.subject = message.subject
            mailMessage.body = self._getBody(message)
            mailMessage.dateSent = message.date
            mailMessage.dateReceived = datetime.datetime.now()
            mailMessage.put()
        else:
            logging.info("Account does not exist " + message.to + " with an email name of " + emailName)
예제 #2
0
 def get(self, feed_url, messageid):    
     
      
     existingUsers = UserDetails.gql("WHERE feedUrl = :1 LIMIT 1",feed_url) 
     for existingUser in existingUsers:
         email_name = existingUser.emailName
         account_exists = True
     USER_EMAIL = email_name + config.SETTINGS['emaildomain']       
     
     mId = int(messageid)
     accountExists = False   
     emailName = ""
     empty = True
             
     email = MailMessage.get_by_id(mId)   
     if email:
         empty = False
     
     feed_url = self.request.path.split('/')[2]
        
     prev_url = ""
     
     next_url = ""
            
         
     this_data = { 'email':email, 'to':USER_EMAIL, 'user':email_name, 'account_exists':account_exists, 'empty': empty, 'feed_url':feed_url[2], 'feed_url':feed_url, 'prev_url':prev_url}      
     
     app = App()
     view_data = app.data(this_data)
     
     path = os.path.join(main.ROOT_DIR, 'views/view/web-single.html')
     self.response.out.write(template.render(path, view_data))   
예제 #3
0
 def get(self, feed_url):                    
    
     account_exists = empty = False   
     emailName = ""
    
     
     existingUsers = UserDetails.gql("WHERE feedUrl = :1 LIMIT 1",feed_url) 
     for existingUser in existingUsers:
         email_name = existingUser.emailName
         account_exists = True
         
     if account_exists:
         feed_path = feed_url      
         feed_url = config.SETTINGS['url'] +"/"+ feed_url
          
         user_email = email_name + config.SETTINGS['emaildomain']           
         app = App()            
         
         emails = MailMessage.all().filter("toAddress = ", user_email).order("-dateReceived")      
         emailCount = emails.count() 
         if emailCount == 0:
             empty = True 
         this_data = { 'emails':emails, 'to':user_email,  'authControl':users.create_login_url("/"), 'empty': empty, 'feed_url':feed_url, 'feed_path':feed_path, 'account_exists':account_exists}      
                   
         
        
         view_data = app.data(this_data)
                 
         path = os.path.join(main.ROOT_DIR, 'views/view/web.html')
         self.response.out.write(template.render(path, view_data))
     else: 
         self.redirect("/#")      
예제 #4
0
 def feed_exists(feed_name):
     exists = False    
     existing_feeds = UserDetails.gql("WHERE emailName = :1 LIMIT 1",feed_name) 
     for existing_feed in existing_feeds:                     
         exists = True       
            
     return exists
예제 #5
0
 def data(self, view_data):
     
     view_data['logged_in'] = False        
     view_data['base_title'] = config.SETTINGS['platform']
     view_data['hostname'] = config.SETTINGS['hostname']
     view_data['emaildomain'] = config.SETTINGS['emaildomain']
     if view_data.get('errors'):
         error_codes = view_data['errors']
     else:
         error_codes = [] 
     user = users.get_current_user()
     if user:  
         view_data['logged_in'] = True
         view_data['auth_link'] = users.create_logout_url("/")
         
         current_users = UserDetails.gql("WHERE accountName = :1 LIMIT 1",user) 
         if current_users:
             view_data['account_name'] = current_users[0].emailName                        
     else:
         view_data['auth_link'] = users.create_login_url("/")    
     
     
     if view_data.get('user_get'):               
         view_data['account_exists'] = self.feed_exists(view_data['user_get'])
         view_data['rss_link'] = '<link rel="alternate" type="application/rss+xml" title="'+ view_data.get('user_get')  +' feed at email2feed" href="/rss/' + view_data.get('user_get')  + '">'
         view_data['atom_link'] = '<link rel="alternate"  type="application/atom+xml"  title="'+ view_data.get('user_get')  +' feed at email2feed" href="/' + view_data.get('user_get')  + '">'
     
     view_data['errors'] =  self.app_errors(error_codes)
     
     return view_data   
예제 #6
0
 def post(self):               
     app = App() 
     confirm_username = self.request.get('email_name')
     validator = AccountValidator()
     validation = validator.validate(self.request.get('email_name'))
     if validation['valid']:
         account_available = True
         confirm_url = "/confirm/" + validation['email_name']
         auth_control = users.create_login_url(confirm_url)  
         
         feed_urls = Check.generate_box(validation['email_name'])       
         feed_url = feed_urls['feed']
         feed_view = feed_urls['view']
         feed_gen = feed_urls['gen']
                 
         validator = AccountValidator() 
         validation = validator.validate(confirm_username)       
         if validation['valid']:  
             userDetails = UserDetails()                
             userDetails.emailName = validation['email_name']
             userDetails.feedUrl = feed_gen     
             userDetails.put()
             
             self.redirect("/view/" + feed_gen)
         else:
             self.redirect("/#invalid" + validation['errors'] + " " + confirm_username)            
                 
                 
                 
                       
         this_data = {
                      'email_name':validation['email_name'], 
                      'hostname':config.SETTINGS['hostname'], 
                      'account_available':account_available,
                      'auth_control':auth_control, 
                      'feed_url':feed_url,
                      'feed_view':feed_view                       
                      }            
         view_data = app.data(this_data)     
         
         path = os.path.join(main.ROOT_DIR, 'views/register.html')           
         self.response.out.write(template.render(path,view_data))
     else:
         path = os.path.join(main.ROOT_DIR, 'views/index.html')
         this_data = {'errors':validation['errors']}        
         view_data = app.data(this_data)            
         self.response.out.write(template.render(path, view_data))             
예제 #7
0
 def account_exists(self, account_name): 
     exists = False    
     existing_users = UserDetails.gql("WHERE accountName = :1 LIMIT 1",account_name)
     for existing_user in existing_users:             
         exists = True
         account_name =  existing_users[0].emailName
         
     account = {}
     account['exists'] = exists
     account['account_name'] = account_name
     return account
예제 #8
0
 def validate(self,email_name):       
     
     errors = []
     
     user_exists = unavailable = email_exists = account_available = False;
     email_name = email_name.strip().replace('-', '').replace(' ', '') 
     email_name_length = len(email_name)
     valid = False
     full_email_name = email_name + config.SETTINGS['emaildomain']
     unavailable_names = config.SETTINGS['unavailable_names']   
     
 
     
     #Is this email taken?
     existingEmails = UserDetails.gql("WHERE emailName = :1 LIMIT 1",email_name)
     for existingEmail in existingEmails:        
         email_exists = True;          
     
     for unavailablename in unavailable_names:
         if unavailablename == email_name:
             unavailable = True
                     
     if AccountValidator.validateEmail(full_email_name) == 0:
         errors.append(1)
         #self.redirect("/#invalidemail")
     if user_exists:
         errors.append(2)
         #self.redirect("/#accountexists") 
     if email_exists:
         errors.append(3)
         #self.redirect("/#emailexists")
     if unavailable:
         errors.append(4)
         #self.redirect("/#unavailable")            
     if email_name_length <= config.SETTINGS['minusername']:
         errors.append(5)
         #self.redirect("/#short")        
     if email_name_length >= config.SETTINGS['maxusername']:
         errors.append(6)
         #self.redirect("/#long")       
         
     if not errors:
         valid = True
         
     validation = {}
     validation['valid'] = valid
     validation['email_name'] = email_name
     validation['errors'] = errors
     return validation
예제 #9
0
 def get(self, feed_url): 
     account_exists = False
     existingUsers = UserDetails.gql("WHERE feedUrl = :1 LIMIT 1",feed_url) 
     for existingUser in existingUsers:
         email_name = existingUser.emailName
         account_exists = True
     
     if account_exists:
         FEED_TITLE = email_name + " - email2feed"
         FEED_URL = "http://"+config.SETTINGS['hostname']+"/"+feed_url     
         FEED_URL_VIEW = "http://"+config.SETTINGS['hostname']+"/view/"+feed_url     
         USER_EMAIL = email_name + config.SETTINGS['emaildomain']  # ex. [email protected]  
         USER_LINK = config.SETTINGS['url'] + "/view/" + feed_url
         latestMessageVal = "";
         
         messages = MailMessage.all().filter("toAddress = ", USER_EMAIL).order("-dateReceived")
         results = messages.fetch(config.SETTINGS['maxfetch'])  
         
         latestEmailQry = MailMessage.all().filter("toAddress = ", USER_EMAIL).order("-dateReceived")
         latestMessageFtch = latestEmailQry.fetch(1)
         for latestMessage in latestMessageFtch:    
             latestMessageVal = latestMessage.dateReceived   
                 
         footer = "<div style='clear:both;text-align: right; width:100%'><span style='color:#4E83B9'>email<span style='color:#1A4979; font-weight: bold;'>2</span><span style='color:#4E83B9'>feed</span> | <a target='_blank' style='color:#4E83B9;text-decoration: none;' href='" + FEED_URL_VIEW + "'>settings</a></div>"        
                 
         this_data = {
                      "results"      :   results
                     ,"feedTitle"    :   FEED_TITLE
                     ,"feedUrl"      :   FEED_URL
                     ,"feedFooter"   :   footer
                     ,"updated"      :   latestMessageVal
                     ,"name"         :   email_name
                     ,"email"        :   USER_EMAIL
                     ,"userlink"     :   USER_LINK  
                     }     
         app = App()
         view_data = app.data(this_data)      
        
         
         self.response.headers['Content-Type'] = 'application/atom+xml'
         self.response.out.write(template.render("views/view/atom.xml", view_data))
     else:
         self.redirect("/#")
예제 #10
0
 def get(self, feed_url):     
     account_exists = False
     existingUsers = UserDetails.gql("WHERE feedUrl = :1 LIMIT 1",feed_url) 
     for existingUser in existingUsers:
         email_name = existingUser.emailName
         account_exists = True
         
     if account_exists:
         FEED_TITLE = email_name + " - email2feed"
         FEED_URL = "http://"+config.SETTINGS['hostname']+"/rss/"+feed_url      
         USER_EMAIL = email_name + config.SETTINGS['emaildomain']  # ex. [email protected]
         USER_LINK = config.SETTINGS['url'] + "/view/" + feed_url   
         
         messages = MailMessage.all().filter("toAddress = ", USER_EMAIL).order("-dateReceived") #Get all emails for the current user     
         results = messages.fetch(config.SETTINGS['maxfetch'])  
         rss_items = []
         
         #Feed Message Data
         for msg in results:
             genlink = USER_LINK + "/" + str(msg.key().id())
             item = PyRSS2Gen.RSSItem(title=msg.subject,description=msg.body,pubDate=msg.dateReceived,guid = PyRSS2Gen.Guid(genlink),link=genlink) #subject, body, date received, test guid
             rss_items.append(item) 
 
         #Feed Title Data
         rss = PyRSS2Gen.RSS2(title=FEED_TITLE,
                              link=FEED_URL,
                              description=USER_EMAIL,
                              lastBuildDate=datetime.datetime.now(),
                              items=rss_items
                             )
         
         rss_xml = rss.to_xml()
         self.response.headers['Content-Type'] = 'application/rss+xml'
         self.response.out.write(rss_xml)
     else:
         self.redirect("/#")