Example #1
0
    def command(self, search=None):
        session, idx, start = self._do_search(search=search)

        nodes = []
        links = []
        res = {}

        for messageid in session.results:
            message = Email(self._idx(), messageid)
            try:
                msgfrom = ExtractEmails(message.get("from"))[0].lower()
            except IndexError, e:
                print "No e-mail address in '%s'" % message.get("from")
                continue

            msgto = [x.lower() for x in ExtractEmails(message.get("to"))]
            msgcc = [x.lower() for x in ExtractEmails(message.get("cc"))]
            msgbcc = [x.lower() for x in ExtractEmails(message.get("bcc"))]

            if msgfrom not in [m["email"] for m in nodes]:
                nodes.append({"email": msgfrom})

            for msgset in [msgto, msgcc, msgbcc]:
                for address in msgset:
                    if address not in [m["email"] for m in nodes]:
                        nodes.append({"email": address})

                curnodes = [x["email"] for x in nodes]
                fromid = curnodes.index(msgfrom)
                searchspace = [m for m in links if m["source"] == fromid]
                for recipient in msgset:
                    index = curnodes.index(recipient)
                    link = [m for m in searchspace if m["target"] == index]
                    if len(link) == 0:
                        links.append({
                            "source": fromid,
                            "target": index,
                            "value": 1
                        })
                    elif len(link) == 1:
                        link[0]["value"] += 1
                    else:
                        raise ValueError(
                            "Too many links! - This should never happen.")

            if len(nodes) >= 200:
                # Let's put a hard upper limit on how many nodes we can have, for performance reasons.
                # There might be a better way to do this though...
                res["limit_hit"] = True
                break
Example #2
0
  def command(self, search=None):
    session, idx, start = self._do_search(search=search)

    nodes = []
    links = []
    res = {}

    for messageid in session.results:
      message = Email(self._idx(), messageid)
      try:
        msgfrom = ExtractEmails(message.get("from"))[0].lower()
      except IndexError, e:
        print "No e-mail address in '%s'" % message.get("from")
        continue

      msgto = [x.lower() for x in ExtractEmails(message.get("to"))]
      msgcc = [x.lower() for x in ExtractEmails(message.get("cc"))]
      msgbcc = [x.lower() for x in ExtractEmails(message.get("bcc"))]

      if msgfrom not in [m["email"] for m in nodes]:
        nodes.append({"email": msgfrom})

      for msgset in [msgto, msgcc, msgbcc]:
        for address in msgset:
          if address not in [m["email"] for m in nodes]:
            nodes.append({"email": address})

        curnodes = [x["email"] for x in nodes]
        fromid = curnodes.index(msgfrom)
        searchspace = [m for m in links if m["source"] == fromid]
        for recipient in msgset:
          index = curnodes.index(recipient)
          link = [m for m in searchspace if m["target"] == index]
          if len(link) == 0:
            links.append({"source": fromid, "target": index, "value": 1})
          elif len(link) == 1:
            link[0]["value"] += 1
          else:
            raise ValueError("Too many links! - This should never happen.")

      if len(nodes) >= 200:
        # Let's put a hard upper limit on how many nodes we can have, for performance reasons.
        # There might be a better way to do this though...
        res["limit_hit"] = True
        break