Index: conf.c
===================================================================
--- conf.c	(revision 3314ced0efff64ce4f92caf24b9272f5249c3a17)
+++ conf.c	(revision 12f041de930a20a3df91f9f90c4fd518162ea82c)
@@ -295,4 +295,6 @@
 				} else if (url->proto == PROTO_SOCKS5) {
 					proxytype = PROXY_SOCKS5;
+				} else if (url->proto == PROTO_SOCKS4A) {
+					proxytype = PROXY_SOCKS4A;
 				}
 
Index: lib/proxy.c
===================================================================
--- lib/proxy.c	(revision 3314ced0efff64ce4f92caf24b9272f5249c3a17)
+++ lib/proxy.c	(revision 12f041de930a20a3df91f9f90c4fd518162ea82c)
@@ -294,4 +294,5 @@
 	socklen_t len;
 	int error = ETIMEDOUT;
+	gboolean is_socks4a = (proxytype == PROXY_SOCKS4A);
 
 	if (phb->inpa > 0) {
@@ -304,6 +305,5 @@
 	sock_make_blocking(source);
 
-	/* XXX does socks4 not support host name lookups by the proxy? */
-	if (!(hp = gethostbyname(phb->host))) {
+	if (!is_socks4a && !(hp = gethostbyname(phb->host))) {
 		return phb_close(phb);
 	}
@@ -313,11 +313,26 @@
 	packet[2] = phb->port >> 8;
 	packet[3] = phb->port & 0xff;
-	packet[4] = (unsigned char) (hp->h_addr_list[0])[0];
-	packet[5] = (unsigned char) (hp->h_addr_list[0])[1];
-	packet[6] = (unsigned char) (hp->h_addr_list[0])[2];
-	packet[7] = (unsigned char) (hp->h_addr_list[0])[3];
+	if (is_socks4a) {
+		packet[4] = 0;
+		packet[5] = 0;
+		packet[6] = 0;
+		packet[7] = 1;
+	} else {
+		packet[4] = (unsigned char) (hp->h_addr_list[0])[0];
+		packet[5] = (unsigned char) (hp->h_addr_list[0])[1];
+		packet[6] = (unsigned char) (hp->h_addr_list[0])[2];
+		packet[7] = (unsigned char) (hp->h_addr_list[0])[3];
+	}
 	packet[8] = 0;
 	if (write(source, packet, 9) != 9) {
 		return phb_close(phb);
+	}
+
+	if (is_socks4a) {
+		size_t host_len = strlen(phb->host) + 1; /* include the \0 */
+
+		if (write(source, phb->host, host_len) != host_len) {
+			return phb_close(phb);
+		}
 	}
 
@@ -506,5 +521,5 @@
 	} else if (proxytype == PROXY_HTTP) {
 		return proxy_connect_http(host, port, phb);
-	} else if (proxytype == PROXY_SOCKS4) {
+	} else if (proxytype == PROXY_SOCKS4 || proxytype == PROXY_SOCKS4A) {
 		return proxy_connect_socks4(host, port, phb);
 	} else if (proxytype == PROXY_SOCKS5) {
Index: lib/proxy.h
===================================================================
--- lib/proxy.h	(revision 3314ced0efff64ce4f92caf24b9272f5249c3a17)
+++ lib/proxy.h	(revision 12f041de930a20a3df91f9f90c4fd518162ea82c)
@@ -40,4 +40,5 @@
 #define PROXY_SOCKS4 2
 #define PROXY_SOCKS5 3
+#define PROXY_SOCKS4A 4
 
 extern char proxyhost[128];
Index: lib/url.c
===================================================================
--- lib/url.c	(revision 3314ced0efff64ce4f92caf24b9272f5249c3a17)
+++ lib/url.c	(revision 12f041de930a20a3df91f9f90c4fd518162ea82c)
@@ -48,4 +48,6 @@
 		} else if (g_strncasecmp(set_url, "socks5", i - set_url) == 0) {
 			url->proto = PROTO_SOCKS5;
+		} else if (g_strncasecmp(set_url, "socks4a", i - set_url) == 0) {
+			url->proto = PROTO_SOCKS4A;
 		} else {
 			return 0;
Index: lib/url.h
===================================================================
--- lib/url.h	(revision 3314ced0efff64ce4f92caf24b9272f5249c3a17)
+++ lib/url.h	(revision 12f041de930a20a3df91f9f90c4fd518162ea82c)
@@ -30,4 +30,5 @@
 #define PROTO_SOCKS4    3
 #define PROTO_SOCKS5    4
+#define PROTO_SOCKS4A   5
 #define PROTO_DEFAULT   PROTO_HTTP
 
Index: protocols/purple/purple.c
===================================================================
--- protocols/purple/purple.c	(revision 3314ced0efff64ce4f92caf24b9272f5249c3a17)
+++ protocols/purple/purple.c	(revision 12f041de930a20a3df91f9f90c4fd518162ea82c)
@@ -122,4 +122,10 @@
 		purple_blist_load();
 		purple_prefs_load();
+
+		if (proxytype == PROXY_SOCKS4A) {
+			/* do this here after loading prefs. yes, i know, it sucks */
+			purple_prefs_set_bool("/purple/proxy/socks4_remotedns", TRUE);
+		}
+
 		dir_fixed = TRUE;
 	}
@@ -1404,4 +1410,5 @@
 		PurpleProxyInfo *pi = purple_global_proxy_get_info();
 		switch (proxytype) {
+		case PROXY_SOCKS4A:
 		case PROXY_SOCKS4:
 			purple_proxy_info_set_type(pi, PURPLE_PROXY_SOCKS4);
