1 /**************************************************************** 2 * Licensed to the Apache Software Foundation (ASF) under one * 3 * or more contributor license agreements. See the NOTICE file * 4 * distributed with this work for additional information * 5 * regarding copyright ownership. The ASF licenses this file * 6 * to you under the Apache License, Version 2.0 (the * 7 * "License"); you may not use this file except in compliance * 8 * with the License. You may obtain a copy of the License at * 9 * * 10 * http://www.apache.org/licenses/LICENSE-2.0 * 11 * * 12 * Unless required by applicable law or agreed to in writing, * 13 * software distributed under the License is distributed on an * 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * 15 * KIND, either express or implied. See the License for the * 16 * specific language governing permissions and limitations * 17 * under the License. * 18 ****************************************************************/ 19 20 21 package org.apache.james.jspf.core; 22 23 import org.apache.james.jspf.core.exceptions.SPFErrorConstants; 24 25 26 /** 27 * 28 * Class that offer static methods to convert SPF Results and contains all 29 * possible results as static Strings. 30 * 31 */ 32 33 public class SPF1Utils { 34 35 public static final String DEFAULT_EXPLANATION = "http://www.openspf.org/why.html?sender=%{S}&ip=%{I}"; 36 public static final String BEST_GUESS_RECORD = "v=spf1 a/24 mx/24 ptr ?all"; 37 public static final String ATTRIBUTE_SPF1_RECORD = "SPF.SPF1Record"; 38 39 /** 40 * Convert raw SPF results to SPF names 41 * 42 * @param result The result which should converted 43 * @return coverted result 44 */ 45 public static String resultToName(String result) { 46 47 if (result.equals(SPF1Constants.PASS)) { 48 return SPFErrorConstants.PASS_CONV; 49 } else if (result.equals(SPF1Constants.FAIL)) { 50 return SPFErrorConstants.FAIL_CONV; 51 } else if (result.equals(SPF1Constants.NEUTRAL)) { 52 return SPFErrorConstants.NEUTRAL_CONV; 53 } else if (result.equals(SPF1Constants.SOFTFAIL)) { 54 return SPFErrorConstants.SOFTFAIL_CONV; 55 } else { 56 return SPFErrorConstants.NEUTRAL_CONV; 57 } 58 59 } 60 61 /** 62 * Check for valid FQDN 63 * 64 * @param host The hostname to check 65 * @return false or true 66 */ 67 public static boolean checkFQDN(String host) { 68 String regex = "(([a-zA-Z0-9\\-])+\\.)+([a-zA-Z]+)$"; 69 if (host.matches(regex)) { 70 return true; 71 } else { 72 return false; 73 } 74 } 75 }