Repository: smicallef/spiderfoot
File: modules/sfp_stackoverflow.py (Python)

Code before:

            questionId = item["question_id"]
            username = self.extractUsername(questionId, event)
            if username is not None:
                allUsernames.append(username)

            ip4s = self.extractIP4s(text)
            if ip4s is not None:
                allIP4s.append(ip4s)

            ip6s = self.extractIP6s(text)
            if ip6s is not None:
                allIP6s.append(ip6s)

        # create events for emails, username and IPs
        for email in allEmails:
            email = str(email)
            if eventData in email:
                e = SpiderFootEvent('EMAILADDR', email, self.__name__, event)
                self.notifyListeners(e)
            else:
                e = SpiderFootEvent('AFFILIATE_EMAILADDR', email, self.__name__, event)
                self.notifyListeners(e)

        for username in allUsernames:
            e = SpiderFootEvent('USERNAME', username, self.__name__, event)
            self.notifyListeners(e)

        for ip in allIP4s:
            ip = str(ip)
            e = SpiderFootEvent('IP_ADDRESS', ip, self.__name__, event)
            self.notifyListeners(e)

        for ip in allIP6s:
            ip = str(ip)
            e = SpiderFootEvent('IPV6_ADDRESS', ip, self.__name__, event)
            self.notifyListeners(e)
# End of sfp_stackoverflow class


Review comment (suggestion):
I'm still seeing non-username types for usernames. If you test against `tesla.com`, you'll see usernames like `A J E` and `stacj aa`. Probably anything with a space should be disregarded, but I'm also not sure how good the quality of usernames are here.

Code after:

            ip4s = self.extractIP4s(text)
            if ip4s is not None:
                allIP4s.append(ip4s)

            ip6s = self.extractIP6s(text)
            if ip6s is not None:
                allIP6s.append(ip6s)

        # create events for emails, username and IPs
        for email in allEmails:
            email = str(email).lower()
            if self.getTarget().matches(email):
                e = SpiderFootEvent('EMAILADDR', email, self.__name__, event)
                self.notifyListeners(e)
            else:
                e = SpiderFootEvent('AFFILIATE_EMAILADDR', email, self.__name__, event)
                self.notifyListeners(e)

        for username in allUsernames:
            if " " in username:
                # Send to sfp_names to identify if username is actually a human name
                e = SpiderFootEvent('RAW_RIR_DATA', 'Possible full name: ' + username, self.__name__, event)
                self.notifyListeners(e)

                opts = {
                    'algolimit': 70,
                    'emailtoname': False,
                    'filterjscss': False
                }

                sfp_names.setup(self, self.sf, opts)
                sfp_names.handleEvent(self, e)
            else:
                e = SpiderFootEvent('USERNAME', username, self.__name__, event)
                self.notifyListeners(e)

        for ip in allIP4s:
            ip = str(ip)
            e = SpiderFootEvent('IP_ADDRESS', ip, self.__name__, event)
            self.notifyListeners(e)

        for ip in allIP6s:
            ip = str(ip)
            e = SpiderFootEvent('IPV6_ADDRESS', ip, self.__name__, event)
            self.notifyListeners(e)
# End of sfp_stackoverflow class