private void heuristicInreply(List<MM2Message> messages, Connection connection) {
		// This is the msg_id ==> in-reply-to
		Hashtable<String, String> msg_id_to_message_id = new Hashtable<String, String>();
		
		// This is message-id ==> msg_id
		Hashtable<String, String> message_id_to_msg_id = new Hashtable<String, String>();

		// This is child ==> parent
		Hashtable<String, String> msg_id_to_msg_id = new Hashtable<String, String>();
		Pattern messageid_pattern = Pattern.compile("<(.*?@.*?)>");
		
		try {
			for (MM2Message msg : messages) {
				
				// Step One: check whether the message has a message-id header
				// We assume that the "message-id" field is always set - at least to "" and is not null
				String h_message_id = msg.getHeaderEntry("message-id");
				if (h_message_id.length() > 2 ) {
					// We try to identify the message identifier part
					String maybeMatch = findLongestPatternMatch(h_message_id, messageid_pattern);
					if (!maybeMatch.equalsIgnoreCase("")) {
						String extracted_message_id = maybeMatch;
						String msg_id = msg.getHeaderEntry("msg_id");
						// Add the information to the reverse lookup table that we will need later
						message_id_to_msg_id.put(extracted_message_id, msg_id);
						Main.getLogger().debug(5, this, "I know that message " + msg_id + " has message-id " + extracted_message_id);
					}
				}
				
				
				// Step Two: check whether the message has an in-reply-to header
				// Again we assume that the "in-reply-to" field is at least "" and not null
				String h_in_reply_to = msg.getHeaderEntry("in-reply-to");
				if(h_in_reply_to.contains(">") && h_in_reply_to.contains("<")) {
					// We try to identify the message identifier part
					String maybeMatch = findLongestPatternMatch(h_in_reply_to, messageid_pattern);
					if (!maybeMatch.equalsIgnoreCase("")) {
						String extracted_in_reply_to_messageid = maybeMatch;
						String msg_id = msg.getHeaderEntry("msg_id");
						// Add the information into the forward lookup table
						Main.getLogger().debug(5, this, "I know that message " + msg_id + " is a reply to " + extracted_in_reply_to_messageid);
						msg_id_to_message_id.put(msg_id, extracted_in_reply_to_messageid);
					} 
				}
			}
			
			// Step Three: After we obtained the previous information, we will
			// resolve each in-reply-to id to a msg_id. so we know for each key in the
			// forward lookup table the msg_id it is a reply to:
			
			for (String child_msg_id : msg_id_to_message_id.keySet()) {
				String parent_msg_id = message_id_to_msg_id.get(msg_id_to_message_id.get(child_msg_id));
				// If we found an entry in the table
				if (parent_msg_id != null) {
					// Add this information to the parents table
					Main.getLogger().debug(5, this, "I know that message " + child_msg_id + " has the parent " + parent_msg_id);
					msg_id_to_msg_id.put(child_msg_id, parent_msg_id);
				}
			}
			
			Main.getLogger().debug(5, "message-ids resolved to msg_ids = " + message_id_to_msg_id.size());
			Main.getLogger().debug(5, "message_ids resolved from in-reply-to = " + msg_id_to_message_id.size());
			
			// Store the parents and roots into the database
			Main.getLogger().log("The heuristic could resolve " + msg_id_to_msg_id.size() + " parent relations!");
			Main.getLogger().log("Storing associations found by in-reply-to heuristic in the database...");
			storeParents(msg_id_to_msg_id, connection);
			
		} catch (Exception e) {
			Main.getLogger().error("Error storing messages for heuristic in-reply!", e);
		}
	}