/usr/share/perl5/Net/IMAP.pm is in libnet-imap-perl 0.02-9.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 | #
# Copyright (c) 1997-1999 Kevin Johnson <kjj@pobox.com>.
#
# All rights reserved. This program is free software; you can
# redistribute it and/or modify it under the same terms as Perl
# itself.
#
# $Id: IMAP.pm,v 1.2 1999/10/03 14:56:21 kjj Exp $
require 5.005;
package Net::IMAP;
use strict;
=head1 NAME
Net::IMAP - A client interface to IMAP (Internet Message Access Protocol).
B<WARNING: This code is in alpha release. Expect the interface to
change release to release.>
=cut
use Net::xAP;
use Carp;
use MIME::Base64;
use Digest::HMAC_MD5 qw(hmac_md5 hmac_md5_hex);
use vars qw($VERSION @ISA $AUTOLOAD);
$VERSION = "0.02";
@ISA = qw(Net::xAP);
use constant ATOM => Net::xAP::ATOM;
use constant ASTRING => Net::xAP::ASTRING;
use constant PARENS => Net::xAP::PARENS;
use constant SASLRESP => Net::xAP::SASLRESP;
=head1 SYNOPSIS
C<use Net::IMAP;>
=head1 DESCRIPTION
C<Net::IMAP> provides a perl interface to the client portion of IMAP
(Internet Message Access Protocol).
B<add more meat - describe overall design (commands, responses,
callbacks, convenience routines>
=head1 METHODS
=cut
use constant IMAP_STATE_NOT_AUTH => 1;
use constant IMAP_STATE_AUTH => 2;
use constant IMAP_STATE_SELECT => 4;
use constant IMAP_STATE_ANY => 7;
my %untagged_callbacks = (
'ok' => [\&_default_aux_callback],
'bye' => [\&_default_aux_callback],
'bad' => [\&_default_aux_callback],
'no' => [\&_default_aux_callback],
'capability' => [undef],
'list' => [undef],
'lsub' => [undef],
'status' => [undef],
'search' => [undef],
'flags' => [undef],
'exists' => [undef],
'recent' => [undef],
'expunge' => [undef],
'fetch' => [undef],
'namespace' => [undef],
'acl' => [undef],
'listrights' => [undef],
'myrights' => [undef],
'quota' => [undef],
'quotaroot' => [undef],
);
my %cmd_callbacks = (
'noop' => [undef, IMAP_STATE_ANY],
'capability' => [undef, IMAP_STATE_ANY],
'logout' => [undef, IMAP_STATE_ANY],
'authenticate' => ['_login_cmd_callback',
IMAP_STATE_NOT_AUTH],
'login' => ['_login_cmd_callback', IMAP_STATE_NOT_AUTH],
'select' => ['_select_cmd_callback',
IMAP_STATE_AUTH|IMAP_STATE_SELECT],
'examine' => ['_select_cmd_callback',
IMAP_STATE_AUTH|IMAP_STATE_SELECT],
'create' => [undef, IMAP_STATE_AUTH|IMAP_STATE_SELECT],
'delete' => [undef, IMAP_STATE_AUTH|IMAP_STATE_SELECT],
'rename' => [undef, IMAP_STATE_AUTH|IMAP_STATE_SELECT],
'subscribe' => [undef, IMAP_STATE_AUTH|IMAP_STATE_SELECT],
'list' => [undef, IMAP_STATE_AUTH|IMAP_STATE_SELECT],
'lsub' => [undef, IMAP_STATE_AUTH|IMAP_STATE_SELECT],
'status' => [undef, IMAP_STATE_AUTH|IMAP_STATE_SELECT],
'append' => [undef, IMAP_STATE_AUTH|IMAP_STATE_SELECT],
'check' => [undef, IMAP_STATE_SELECT],
'close' => ['_close_cmd_callback', IMAP_STATE_SELECT],
'expunge' => [undef, IMAP_STATE_SELECT],
'search' => [undef, IMAP_STATE_SELECT],
'fetch' => [undef, IMAP_STATE_SELECT],
'store' => [undef, IMAP_STATE_SELECT],
'copy' => [undef, IMAP_STATE_SELECT],
'uid copy' => [undef, IMAP_STATE_SELECT],
'uid fetch' => [undef, IMAP_STATE_SELECT],
'uid search' => [undef, IMAP_STATE_SELECT],
'uid store' => [undef, IMAP_STATE_SELECT],
# Extension commands:
'namespace' => [undef, IMAP_STATE_AUTH|IMAP_STATE_SELECT],
'setacl' => [undef, IMAP_STATE_AUTH|IMAP_STATE_SELECT],
'getacl' => [undef, IMAP_STATE_AUTH|IMAP_STATE_SELECT],
'deleteacl' => [undef, IMAP_STATE_AUTH|IMAP_STATE_SELECT],
'listrights' => [undef,
IMAP_STATE_AUTH|IMAP_STATE_SELECT],
'myrights' => [undef, IMAP_STATE_AUTH|IMAP_STATE_SELECT],
'getquota' => [undef, IMAP_STATE_AUTH|IMAP_STATE_SELECT],
'setquota' => [undef, IMAP_STATE_AUTH|IMAP_STATE_SELECT],
'getquotaroot' => [undef,
IMAP_STATE_AUTH|IMAP_STATE_SELECT],
'uid expunge' => [undef, IMAP_STATE_SELECT],
);
my %_system_flags = (
'\seen' => 1,
'\answered' => 1,
'\flagged' => 1,
'\deleted' => 1,
'\draft' => 1,
'\recent' => 1,
);
=head2 new $host, %options
Creates a new C<Net::IMAP> object, connects to C<$host> on port 143,
performs some preliminary setup of the session, and returns a
reference to the object.
Once connected, it processes the connection banner sent by the server.
If the considers the session to be preauthenticated, C<new> notes the
fact, allowing commands to be issued without logging in.
The method also issues a C<capability> command, and notes the result.
If the server does support IMAP4rev1, the method closes the connection
and returns C<undef>.
The client will use non-synchronizing literals if the server supports
the C<LITERAL+> extension (RFC2088) and the C<NonSyncLits> options is
set to C<1>.
The following C<Net::xAP> options are relevant to C<Net::IMAP>:
=over 4
=item C<Synchronous =E<gt> 1>
=item C<NonSyncLits =E<gt> 0>
=item C<Debug =E<gt> 0>
=item C<InternetDraft =E<gt> 0>
=back
C<Net::IMAP> also understands the following options, specific to the module:
=over 4
=item C<EOL =E<gt> 'lf'>
Controls what style of end-of-line processing to presented to the
end-programmer. The default, C<'lf'>, assumes that the programemr
wants to fling messages terminated with bare LFs when invoking append,
and when fetching messages. In this case, the module will map to/from
CRLF accordingly.
If C<EOL> is set to C<'crlf'>, the assumption is that the programmer
wants messages, or portions of messages, to be terminated with CRLF.
It also assumes the programmer is providing messages terminated with
the string when invoking the C<append> method, and will not provide an
EOL mapping.
=back
=cut
sub new {
my $class = shift;
my $type = ref($class) || $class;
my $host = shift if @_ % 2;
my %options = @_;
my $self = Net::xAP->new($host, 'imap2(143)', Timeout => 10, %options)
or return undef;
bless $self, $class;
$self->{Options}{EOL} ||= 'lf';
$self->{Options}{EOL} = lc($self->{Options}{EOL}); # force lower-case
$self->{PreAuth} = 0;
$self->{Banner} = undef;
$self->{Capabilities} = ();
$self->_init_mailbox;
$self->{Disconnect} = 0;
$self->{State} = IMAP_STATE_NOT_AUTH;
$self->{ResponseCallback} = $self->imap_response_callback;
STDERR->autoflush(1);
$self->_get_banner or return undef;
# the little back-flip here with the Synchronous option ensures that
# the capability command is issued in Synchronous mode
my $mode = $self->{Options}{Synchronous}; # save current sync mode
$self->{Options}{Synchronous}++; # force sync mode on
my $resp = $self->capability;
$self->{Options}{Synchronous} = $mode; # restore previous sync mode
if ($resp->status ne 'ok') {
carp "capability command failed on initial connection";
$self->close_connection or carp "error closing connection: $!";
$! = 5; # *sigh* error reporting needs to be improved
return undef;
}
unless ($self->has_capability("IMAP4rev1")){
carp "server does not support IMAP4rev1";
$self->close_connection or carp "error closing connection: $!";
return undef;
}
return $self;
}
sub _init_mailbox {
my $self = shift;
$self->{Mailbox} = '';
$self->{MailboxStatus} = ();
$self->{MailboxStatus}{'recent'} = 0;
$self->{MailboxStatus}{'unseen'} = 0;
$self->{MailboxStatus}{'exists'} = 0;
$self->{MailboxStatus}{'uidvalidity'} = 0;
$self->{MailboxStatus}{'uidnext'} = 0;
$self->{MailboxStatus}{'flags'} = ();
}
sub debug_text { $_[2] =~ /^(\d+ LOGIN [^\s]+)/i ? "$1 ..." : $_[2] }
sub _get_banner {
my $self = shift;
my $str = $self->getline;
my $list = $self->parse_fields($str);
return undef unless defined($list);
if (($list->[0] eq '*') && ($list->[1] =~ /^preauth$/i)) {
$self->{PreAuth}++;
$self->{State} = IMAP_STATE_AUTH;
} elsif (($list->[0] ne '*') || ($list->[1] !~ /^ok$/i)) {
return undef;
}
$self->{Banner} = $list;
return 1;
}
sub DESTROY {
my $self = shift;
}
sub AUTOLOAD {
my $self = shift;
my $cmd = $AUTOLOAD;
$cmd =~ s/^.*:://;
carp("unknown command: $cmd");
return undef;
}
###############################################################################
=head1 IMAP COMMAND METHODS
There are numerous commands in the IMAP protocol. Each of these are
mapped to a corresponding method in the C<Net::IMAP> module.
Some commands can only be issued in certain protocol states. Some
commands alter the state of the session. These facts are indicated in
the documentation for the individual command methods.
The following list enumerates the protocol states:
=over 4
=item Non-authenticated
The client has not authenticated with the server. Most commands are
unavailable in this state.
=item Authenticated
The client has authenticated with the server.
=item Selected
The client has opened a mailbox on the server.
=back
=head2 noop
Sends a C<noop> command to the server. It is valid in any protocol state.
This method is useful for placating the auto-logout god, or for
triggering pending unsolicited responses from the server.
=cut
sub noop { $_[0]->imap_command('noop') }
=head2 capability
The C<capability> method retrieves the capabilities the IMAP server
supports. This method is valid in any protocol state.
The server sends a C<capability> response back to the client.
If the response does not indicate support for the C<LITERAL+>
extension, the C<NonSyncLits> option is forced off.
=cut
sub capability { $_[0]->imap_command('capability') }
=head2 logout
Logs off of the server. This method is valid in any protocol state.
=cut
sub logout {
$_[0]->{Disconnect}++;
$_[0]->imap_command('logout');
}
=head2 login $user, $password
Logs into the server using a simple plaintext password. This method
is only valid when the protocol is in the non-authenticated state.
If the server supports RFC2221 (IMAP4 Login Referrals), the completion
response could include a referral. See RFC2221 for further
information about login referrals.
If successful, the session state is changed to I<authenticated>.
=cut
sub login { $_[0]->imap_command('login', ASTRING, $_[1], ASTRING, $_[2]) }
=head2 authenticate $authtype, @authinfo
Logs into the server using the authentication mechanism specified in
C<$authtype>. This method is only valid when the protocol is in the
non-authenticated state.
The IMAP C<authenticate> command is the same as that documented in
RFC2222 (Simple Authentication and Security Layer (SASL)), despite the
fact that IMAP predates SASL.
If successful, the session state is changed to I<authenticated>.
The following authentication mechanisms are currently supported:
=over 4
=item C<'login'>
This is a variation on the simple login technique, except that the
information is transmitted in Base64. This does not provide any
additional security, but does allow clients to use C<authenticate>.
=item C<'cram-md5'>
This implements the authentication mechanism defined in RFC2195
(IMAP/POP AUTHorize Extension for Simple Challenge/Response). It uses
keyed MD5 to avoid sending the password over the wire.
=item C<'anonymous'>
This implements the authentication mechanism defined in RFC2245
(Anonymous SASL Mechanism). Anonymous IMAP access is intended to
provide access to public mailboxes or newsgroups.
=back
The method returns C<undef> is C<$authtype> specifies an unsupported
mechanism or if the server does not advertise support for the
mechanism. The C<has_authtype> method can be used to see whether the
server supports a particular authentication mechanism.
In general, if the server supports a mechanism supported by
C<Net::IMAP>, the C<authenticate> command should be used instead of
the C<login> method.
=cut
my %auth_funcs = (
'LOGIN' => \&authenticate_login,
'CRAM-MD5' => \&authenticate_cram,
'ANONYMOUS' => \&authenticate_anonymous,
);
my @auth_strings;
sub authenticate {
my $authtype = uc($_[1]);
return undef unless defined($auth_funcs{$authtype});
return undef unless defined($_[0]->has_authtype($authtype));
my $func = $auth_funcs{$authtype};
@auth_strings = @_[2..$#_];
$_[0]->imap_command('authenticate',
ATOM, $authtype,
SASLRESP, $func);
}
sub authenticate_login {
my $i = shift;
return undef unless defined($auth_strings[$i]);
return encode_base64($auth_strings[$i], '');
}
sub authenticate_cram {
my $i = shift;
my $challenge = shift;
if ($i == 0) {
$challenge = decode_base64($challenge);
$challenge = hmac_md5_hex($challenge, $auth_strings[1]);
$auth_strings[1] = undef;
return(encode_base64("$auth_strings[0] $challenge", ''));
}
return undef;
}
sub authenticate_anonymous {
my $i = shift;
return(encode_base64(join(' ', @auth_strings), '')) if ($i == 0);
return undef;
}
=head2 select $mailbox
Opens the specified mailbox with the intention of performing reading
and writing. This method is valid only when the session is in the
authenticated or selected states.
If successful, the server sends several responses: C<flags>,
C<exists>, C<resent>, as well as C<ok> responses containing a
C<unseen>, C<permanentflags>, C<uidnext>, and C<uidvalidity> codes.
If also changes the session state to I<selected>.
If server returns a C<no> response containing a C<newname> response
code, this means C<$mailbox> does not exist but the server thinks this
is because the folder was renamed. In this case, try specifying the
new folder name provided with the C<newname> response code.
=cut
sub select {
$_[0]->{Mailbox} = $_[1];
my $ret = $_[0]->imap_command('select', ASTRING, _encode_mailbox($_[1]));
$_[0]->{Mailbox} = '' unless defined($ret);
return $ret;
}
=head2 examine $mailbox
Opens the specified mailbox in read-only mode. This method is valid
only when the session is in the authenticated or selected states.
=cut
sub examine { $_[0]->imap_command('examine', ASTRING, _encode_mailbox($_[1])) }
=head2 create $mailbox [, $partition]
Creates the specified mailbox. This method is valid only when the
session is in the authenticated or selected states.
The optional C<$partition> argument is only valid with the Cyrus IMAP
daemon. Refer to the section 'Specifying Partitions with "create"'
the C<doc/overview> file for that package for further information.
This feature can only be used by administrators creating new
mailboxes. Other servers will probably reject the command if this
argument is used. The results are undefined if another server accepts
a second argument.
=cut
sub create {
my @args = (ASTRING, _encode_mailbox($_[1]));
push @args, ATOM, $_[2] if (defined($_[2]));
$_[0]->imap_command('create', @args);
}
=head2 delete $mailbox
Deletes the specified mailbox. Returns C<undef> if C<$mailbox> is the
currently open mailbox. This method is valid only when the session is
in the authenticated or selected states.
=cut
sub delete {
return undef if ($_[0]->{Mailbox} eq $_[1]);
$_[0]->imap_command('delete', ASTRING, _encode_mailbox($_[1]));
}
=head2 rename $oldmailboxname, $newmailboxname [, $partition]
Renames the mailbox specified in C<$oldmailbox> to the name specified
in C<$newmailbox>. This method is valid only when the session is in
the authenticated or selected states.
The optional C<$partition> argument is only valid with the Cyrus IMAP
daemon. Refer to the section 'Specifying Partitions with "rename"'
the C<doc/overview> file for that package for further information.
This feature can only be used by administrators. Other servers will
probably reject the command if this argument is used. The results are
undefined if another server accepts a third argument.
=cut
sub rename {
my @args = (ASTRING, _encode_mailbox($_[1]), ASTRING, _encode_mailbox($_[2]));
push @args, ATOM, $_[3] if defined($_[3]);
$_[0]->imap_command('rename', @args);
}
=head2 subscribe $mailbox
Subscribe to the specified C<$mailbox>. Subscribing in IMAP is
subscribing in Usenet News, except that the server maintains the
subscription list. This method is valid only when the session is in
the authenticated or selected states.
=cut
sub subscribe { $_[0]->imap_command('subscribe',
ASTRING, _encode_mailbox($_[1])) }
=head2 unsubscribe $mailbox
Unsubscribe from the specified C<$mailbox>. This method is valid only
when the session is in the authenticated or selected states.
=cut
sub unsubscribe { $_[0]->imap_command('unsubscribe',
ASTRING, _encode_mailbox($_[1])) }
=head2 list $referencename, $mailbox_pattern
Send an IMAP C<list> command to the server. This method is valid only
when the session is in the authenticated or selected states.
Although IMAP folders do not need to be implemented as directories,
think of an IMAP reference name as a parameter given to a C<cd> or
C<chdir> command, prior to checking for folders matching
C<$mailbox_pattern>.
The C<$mailbox_pattern> parameter allows a couple wildcard characters
to list subsets of the mailboxes on the server.
=over 4
=item C<*>
Matches zero or more characters at the specified location.
=item C<%>
Like C<*>, matches zero or more characters at the specified location,
but does not match hierarchy delimiter characters.
If the last character in C<$mailbox_pattern> is a C<%>, matching
levels of hierarchy are also returned. In other words: subfolders.
=back
This method will fail, returning C<undef>, if C<$mailbox_pattern> is
C<*>. This behavior is not built into the IMAP protocol; it is wired
into C<Net::IMAP>. Doing otherwise could be rude to both the client
and server machines. If you want to know why, imagine doing
C<list('#news.', '*')> on a machine with a full news feed. The C<%>
character should be used to build up a folder tree incrementally.
If successful, the server sends a series of C<list> responses.
Please note that the C<$referencename> is an IMAPism, not a Perl
reference. Also note that the wildcards usable in C<$mailbox_pattern>
are specific to IMAP. Perl regexps are not usable here.
=cut
sub list {
return undef if ($_[2] eq '*');
$_[0]->imap_command('list',
ASTRING, _encode_mailbox($_[1]),
ASTRING, _encode_mailbox($_[2]));
}
=head2 lsub $referencename, $mailbox_pattern
Sends an IMAP C<lsub> command to the server. The C<lsub> command is
similar to the C<list> command, except that the server only returns
subscribed mailboxes. This method is valid only when the session is
in the authenticated or selected states.
The parameters are the same as those for the C<list> method.
If successful, the server sends a series of C<lsub> responses.
=cut
sub lsub { $_[0]->imap_command('lsub',
ASTRING, _encode_mailbox($_[1]),
ASTRING, _encode_mailbox($_[2])) }
=head2 status $mailbox, @statusattrs
Retrieves status information for the specified C<$mailbox>. This
method is valid only when the session is in the authenticated or
selected states.
Per RFC2060, the C<@statusattrs> can contain any of the following
strings:
=over 4
=item * messages
The number of messages in the mailbox.
=item * recent
The number of messages with the C<\recent> flag set.
=item * uidnext
The UID expected to be assigned to the next mailbox appended to the
mailbox. This requires some explanation. Rather than using this
value for prefetching the next UID, it should be used to detect
whether messages have been added to the mailbox. The value will not
change until messages are appended to the mailbox.
=item * uidvalidity
The unique identifier validity value of the mailbox.
=item * unseen
The number of messages without the C<\seen> flag set.
=back
This method will fail, returning C<undef> if C<$mailbox> is the
currently open mailbox.
If successful, the server sends one or more C<status> responses.
The status operation can be rather expensive on some folder
implementations, so clients should use this method sparingly.
=cut
sub status {
my $self = shift;
my $mailbox = shift;
return undef if ($self->{Mailbox} eq $mailbox);
$self->imap_command('status',
ASTRING, _encode_mailbox($mailbox), PARENS, [@_]);
}
=head2 append $mailbox, $message [, Flags => $flaglistref] [, Date => $date]
Appends the email message specified in C<$message> to the mailbox
specified in C<$mailbox>. This method is valid only when the session
is in the authenticated or selected states.
In general, the email message should be a real RFC822 message,
although exceptions such as draft messages are reasonable in some
situations. Also note that the line terminators in C<$message> need
to be CRLF.
The C<Flags> option allows a set of flags to be specified for the
message when it is appended. Servers are not required to honor this,
but most, if not all, do so.
The C<Date> option forces the internaldate to the specified value. If
C<$date> is a string, the format of the string is C<dd-mmm-yyyy
hh:mm:ss [-+]zzzz>, where C<dd> is the day of the month (starting from
1), C<mmm> is the three-character abbreviation for the month name,
C<yyyy> is the 4-digit year, C<hh> is the hour, C<mm> is the minutes,
C<ss> is the seconds, and C<[-+]zzzz> is the numeric timezone offset.
This happens to be the same format returned by the C<internaldate>
item from the C<fetch> command. If C<$date> is a list reference, it is
expected to contain two elements: a time integer and a timezone offset
string. The timezone string is expected to be formatted as
C<[-+]zzzz>. These two values will be used to synthesize a string in
the format expected by the IMAP server. As with the C<Flags> options,
servers are not required to honor the C<Date> option, but most, if not
all, do so.
Note that the options are specified at the end of the list of method
arguments. This is due to the fact that it is possible to have a
C<$mailbox> named C<Flags> or C<Date>. Processing the options at the
end of the argument list simplifies argument processing. The order of
the arguments will be changed if enough people complain.
If server returns a C<no> response containing a C<trycreate> response
code, this means C<$mailbox> does not exist but the server thinks the
command would have succeeded if the an appropriate C<create> command
was issued. On the other hand, failure with no C<trycreate> response
code generally means that a C<create> should not be attempted.
=cut
sub append {
my $self = shift;
my $mailbox = shift;
my $lit = shift;
my %options = @_;
my @args;
push @args, ASTRING, _encode_mailbox($mailbox);
if (defined($options{Flags})) {
for my $flag (@{$options{Flags}}) {
unless ($self->_valid_flag($flag)) {
carp "$flag is not a system flag";
return undef;
}
}
push @args, PARENS, [@{$options{Flags}}];
}
if (defined($options{Date})) {
my $date;
if ((ref($options{Date}) eq 'ARRAY')
&& defined($options{Date}->[1])){
my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
my @gmtime = gmtime($options{Date}->[0]);
$date = sprintf("%02d-%2s-%4d %02d:%02d:%02d %s",
$gmtime[3], $months[$gmtime[4]], $gmtime[5] + 1900,
$gmtime[2], $gmtime[1], $gmtime[0],
$options{Date}->[1]);
} else {
$date = $options{Date};
}
if ($date !~ /^[ \d][\d]-[a-zA-Z]{3}-\d{4} \d\d:\d\d:\d\d [\+\-]\d{4}$/) {
carp "invalid date value for append command";
return undef;
}
push @args, ATOM, "\"$date\"";
}
$lit =~ s/\n/\r\n/mg if ($self->{Options}{EOL} eq 'lf');
push @args, ASTRING, $lit;
$self->imap_command('append', @args);
}
=head2 check
Ask the server to perform a checkpoint of its data. This method is
valid only when the session is in the selected state.
While not always needed, this should be called if the client issues a
large quantity of updates to a folder in an extended session.
=cut
sub check { $_[0]->imap_command('check') }
=head2 close
Close the current mailbox. This method is valid only when the session
is in the selected state.
If successful, the session state is changed to I<authenticated>.
=cut
sub close { $_[0]->imap_command('close') }
=head2 expunge
Delete messages marked for deletion. This method is valid only when
the session is in the selected state.
If successful, the server sends a series of C<expunge> responses.
It will return C<undef> is the mailbox is marked read-only.
=cut
sub expunge {
return undef if $_[0]->is_readonly;
$_[0]->imap_command('expunge');
}
=head2 search [Charset => $charset,] @searchkeys
Searches the mailbox for messages matching the criteria contained in
C<@searchkeys>. This method is valid only when the session is in the
selected state.
The C<@searchkeys> list contains strings matching the format described
in Section 6.4.4 of RFC2060.
If successful, the server send zero or more C<search> responses. Lack
of a C<search> response means the server found no matches. Note that
the server can send the results of one search in multiple responses.
=cut
sub search {
my $self = shift;
my @args;
if ($_[0] =~ /^charset$/i) {
shift;
my $charset = shift;
push @args, ATOM, 'charset', ASTRING, $charset;
}
push @args, map { (ATOM, $_) } @_;
$self->imap_command('search', @args);
}
=head2 fetch $msgset, 'all'|'full'|'fast'|$fetchattr|@fetchattrs
Retrieves data about a set of messages. This method is valid only
when the session is in the selected state.
The C<$msgset> parameter identifies the set of messages from which to
retrieve the items of interest. The notation accepted is similar to
that found in C<.newsrc> files, except that C<:> is used to specify
ranges, instead of C<->. Thus, to specify messages 1, 2, 3, 5, 7, 8,
9, the following string could be used: C<'1:3,5,7:9'>. The character
C<*> can be used to indicate the highest message number in the
mailbox. Thus, to specify the last 4 messages in an 8-message
mailbox, you can use C<'5-*'>.
The following list enumerates the items that can be retrieved with
C<fetch>. Refer to Section 6.4.5 of RFC2060 for a description of each
of these items.
=over 4
=item * body[$section]E<lt>$partialE<gt>
=item * body.peek[$section]E<lt>$partialE<gt>
Important: the response item returned for a C<body.peek> is C<body>.
=item * bodystructure
=item * body
=item * envelope
=item * flags
=item * internaldate
=item * rfc822
=item * rfc822.header
=item * rfc822.size
=item * rfc822.text
=item * uid
=back
Please note that the items returning messages, or portion of messages,
return strings terminated with CRLF.
RFC2060 also defines several items that are actually macros for other
sets of items:
=over 4
=item * all
A macro equivalent to C<('flags', 'internaldate', 'rfc822.size', 'envelope')>.
=item * full
A macro equivalent to C<('flags', 'rfc822.size', 'envelope', 'body')>.
=item * fast
A macro equivalent to C<('flags', 'internaldate', 'rfc822.size')>.
=back
The C<all>, C<full>, and C<fast> items are not intended to be used
with other items.
If successful, the server responses with one or more C<fetch>
responses.
If the completion response from a C<fetch> command is C<no>, the
client should send a C<noop> command, to force any pending expunge
responses from the server, and retry the C<fetch> command with
C<$msgset> adjusted accordingly.
=cut
sub fetch {
my $self = shift;
my $msgset = shift;
my @args;
if (scalar(@_) == 1) {
push @args, ATOM, shift;
} else {
push @args, PARENS, [@_];
}
$self->imap_command('fetch', ATOM, $msgset, @args);
}
=head2 store $msgset, $itemname, @storeattrflags
Sets various attributes for the messages identified in C<$msgset>.
This method is valid only when the session is in the selected state.
The C<$msgset> parameter is described in the section describing C<fetch>.
The C<$itemname> can be one of the following:
=over 4
=item * flags
Replaces the current flags with the flags specified in C<@storeattrflags>.
=item * +flags
Adds the flags specified in C<@storeattrflags> to the current flags.
=item * -flags
Removes the flags specified in C<@storeattrflags> from the current
flags.
=back
The C<$itemname> can also have C<.silent> appended, which causes the
server to not send back update responses for the messages.
If successful, and C<.silent> is used used in C<$itemname>, the server
response with a series of C<fetch> responses reflecting the updates to
the specified messages.
If the completion response from a C<store> command is C<no>, the
client should send a C<noop> command, to force any pending expunge
responses from the server, and retry the C<store> command with
C<$msgset> adjusted accordingly.
The C<@storeattrflags> is a list of flag strings.
=cut
sub store {
my $self = shift;
my $msgset = shift;
my $itemname = shift;
for my $flag (@_) {
unless ($self->_valid_flag($flag)) {
carp "$flag is not a system flag";
return undef;
}
}
$self->imap_command('store', ATOM, $msgset, ATOM, $itemname, PARENS, [@_]);
}
=head2 copy $msgset, $mailbox
Copy the messages C<$msgset> to the specified mailbox. This method is
valid only when the session is in the selected state.
The C<$msgset> parameter is described in the section describing C<fetch>.
If server returns a C<no> response containing a C<trycreate> response
code, this means C<$mailbox> does not exist but the server thinks the
command would have succeeded if the an appropriate C<create> command
was issued. On the other hand, failure with no C<trycreate> response
code generally means that a C<create> should not be attempted.
=cut
sub copy { $_[0]->imap_command('copy',
ATOM, $_[1], ASTRING, _encode_mailbox($_[2])) }
=head2 uid_copy $msgset, $mailbox
A variant of C<copy> that uses UIDs in C<$msgset>, instead of message
numbers. This method is valid only when the session is in the
selected state.
=cut
sub uid_copy { $_[0]->imap_command('uid copy',
ATOM, $_[1],
ASTRING, _encode_mailbox($_[2])) }
=head2 uid_fetch $msgset, 'all'|'full'|'fast'|$fetchattr|@fetchattrs
A variant of C<fetch> that uses UIDs, instead of message numbers, in
C<$msgset> and C<fetch> responses. This method is valid only when the
session is in the selected state.
=cut
sub uid_fetch {
my $self = shift;
my $msgset = shift;
my @args;
if (scalar(@_) == 1) {
push @args, ATOM, shift;
} else {
push @args, PARENS, [@_];
}
$self->imap_command('uid fetch', ATOM, $msgset, @args);
}
=head2 uid_search [Charset => $charset,] @searchkeys
A variant of C<search> that uses UIDs, instead of message numbers, in
C<$msgset> and C<search> responses. This method is valid only when
the session is in the selected state.
=cut
sub uid_search {
my $self = shift;
my @args;
if ($_[0] =~ /^charset$/i) {
shift;
my $charset = shift;
push @args, ATOM, 'charset', ASTRING, $charset;
}
push @args, map { (ATOM, $_) } @_;
$self->imap_command('uid search', @args);
}
=head2 uid_store $msgset, $itemname, @storeattrflags
A variant of C<store> that uses UIDs, instead of message numbers, in
C<$msgset> and C<fetch> responses. This method is valid only when the
session is in the selected state.
=cut
sub uid_store {
my $self = shift;
my $msgset = shift;
my $itemname = shift;
for my $flag (@_) {
unless ($self->_valid_flag($flag)) {
carp "$flag is not a system flag";
return undef;
}
}
$self->imap_command('uid store',
ATOM, $msgset, ATOM, $itemname, PARENS, [@_]);
}
###############################################################################
=head1 CONVENIENCE ROUTINES
In addition to the core protocol methods, C<Net::IMAP> provides
several methods for accessing various pieces of information.
=head2 is_preauth
Returns a boolean valud indicating whether the IMAP session is
preauthenticated.
=cut
sub is_preauth { $_[0]->{PreAuth} }
=head2 banner
Returns the banner string issued by the server at connect time.
=cut
sub banner { $_[0]->{Banner} }
=head2 capabilities
Returns the list of capabilities supported by the server, minus the
authentication capabilities. The list is not guaranteed to be in any
specific order.
=cut
sub capabilities { keys %{$_[0]->{Capabilities}} }
=head2 has_capability $capname
Returns a boolean value indicating whether the server supports the
specified capability.
=cut
sub has_capability { defined($_[0]->{Capabilities}{uc($_[1])}) }
=head2 authtypes
Returns a list of authentication types supported by the server.
=cut
sub authtypes { keys %{$_[0]->{AuthTypes}} }
=head2 has_authtype $authname
Returns a boolean value indicating whether the server supports the
specified authentication type.
=cut
sub has_authtype { defined($_[0]->{AuthTypes}{uc($_[1])}) }
=head2 qty_messages
Returns the quantity of messages in the currently selected folder.
=cut
sub qty_messages { $_[0]->{MailboxStatus}{'exists'} }
=head2 qty_recent
Returns the quantity of recent messages in the currently selected folder.
=cut
sub qty_recent { $_[0]->{MailboxStatus}{'recent'} }
=head2 first_unseen
Returns the message number of the first unseen messages in the
currently selected folder.
=cut
sub first_unseen { $_[0]->{MailboxStatus}{'unseen'} }
=head2 uidvalidity
Returns the C<uidvalidity> value for the currently selected folder.
This is useful for IMAP clients that cache data in persistent storage.
Cache data for a mailbox should only be considered valid if the
C<uidvalidity> is the same for both cached data and the remote
mailbox. See Section 2.3.1.1 of RFC2060 for further details.
=cut
sub uidvalidity { $_[0]->{MailboxStatus}{'uidvalidity'} }
=head2 uidnext
Returns the C<uidnext> value for the currently selected folder.
=cut
sub uidnext { $_[0]->{MailboxStatus}{'uidnext'} }
=head2 permanentflags
Returns the list of permanent flags the server has identified for the
currently open mailbox.
If a C<\*> flag is present, the server allows new persistent keywords
to be created.
=cut
sub permanentflags { keys %{$_[0]->{MailboxStatus}{'permanentflags'}} }
=head2 is_permanentflag $flag
Returns a boolean value indicating whether the server considers
C<$flag> to be a permanent flag.
=cut
sub is_permanentflag {
defined($_[0]->{MailboxStatus}{'permanentflags'}{lc($_[1])});
}
=head2 flags
Returns a list of the flags associated with the mailbox.
=cut
sub flags { keys %{$_[0]->{MailboxStatus}{'flags'}} }
=head2 has_flag $flag
Returns a boolean value indicating whether the given $flag is defined
for the mailbox.
=cut
sub has_flag { defined($_[0]->{MailboxStatus}{'flags'}{lc($_[1])}) }
=head2 mailbox
Returns the name of the currently open mailbox. Returns C<undef> if
no mailbox is currently open.
=cut
sub mailbox { $_[0]->{Mailbox} }
=head2 is_readonly
Returns a boolean value indicating whether the currently open mailbox
is read-only.
=cut
sub is_readonly { $_[0]->{ReadOnly} }
#------------------------------------------------------------------------------
sub _encode_mailbox {
my $str = $_[0];
$str =~ s/&/&-/g;
return $str;
}
sub _decode_mailbox {
my $str = $_[0];
$str =~ s/&-/&/g;
return $str;
}
###############################################################################
=head1 NAMESPACE EXTENSION
The following methods are available if the server advertises support
for RFC2342 (IMAP4 Namespace). Refer to that RFC for additional
information.
=head2 namespace
Sends a C<namespace> command to the server, if the server advertises
support for the extension extension.
=cut
sub namespace {
my $self = shift;
return undef unless $self->has_capability('NAMESPACE');
$self->imap_command('namespace');
}
###############################################################################
=head1 ACCESS CONTROL EXTENSION
The following methods are available if the server advertises support
for RFC2086 (IMAP4 ACL Extension). Refer to that RFC for additional
information.
=head2 setacl $mailbox, $identifier, $modrights
Sets the access control list for C<$identifier> on C<$mailbox>
according to the rights contained in C<$modrights>.
The C<$identifier> typically identifies an account name, but can also
specify abstract entities, such as groups.
The format for C<$modrights> is documented in RFC2086.
=cut
sub setacl {
my $self = shift;
return undef unless $self->has_capability('ACL');
$self->imap_command('setacl',
ASTRING, _encode_mailbox($_[0]),
ASTRING, $_[1],
ASTRING, $_[2]);
}
=head2 getacl $mailbox
Retrieves the access control list for C<$mailbox>.
=cut
sub getacl {
my $self = shift;
return undef unless $self->has_capability('ACL');
$self->imap_command('getacl', ASTRING, _encode_mailbox($_[0]));
}
=head2 deleteacl $mailbox, $identifier
Deletes all access control list entries for C<$identifier> from
C<$mailbox>.
=cut
sub deleteacl {
my $self = shift;
return undef unless $self->has_capability('ACL');
$self->imap_command('deleteacl',
ASTRING, _encode_mailbox($_[0]), ASTRING, $_[1]);
}
=head2 listrights $mailbox, $identifier
List the rights available to C<$identifier> for C<$mailbox>.
=cut
sub listrights {
my $self = shift;
return undef unless $self->has_capability('ACL');
$self->imap_command('listrights',
ASTRING, _encode_mailbox($_[0]), ASTRING, $_[1]);
}
=head2 myrights $mailbox
List the rights the current user has for C<$mailbox>.
=cut
sub myrights {
my $self = shift;
return undef unless $self->has_capability('ACL');
$self->imap_command('myrights', ASTRING, _encode_mailbox($_[0]));
}
###############################################################################
=head1 QUOTA EXTENSION
The following methods are available if the server advertises support
for RFC2087 (IMAP4 Quota Extension). Refer to that RFC for additional
information.
=head2 getquota $quotaroot
Lists the resource usage and limits for C<$quotaroot>.
=cut
sub getquota {
my $self = shift;
return undef unless $self->has_capability('QUOTA');
$self->imap_command('getquota', ASTRING, $_[0]);
}
=head2 setquota $quotaroot, @setquotalist
Sets the resource limits for C<$quotaroot> to C<@setquotalist>.
Valid values for C<@setquotalist> are server-dependant.
=cut
sub setquota {
my $self = shift;
my $quotaroot = shift;
return undef unless $self->has_capability('QUOTA');
$self->imap_command('setquota', ASTRING, $quotaroot, PARENS, [@_]);
}
=head2 getquotaroot $mailbox
Lists the quota roots for C<$mailbox>.
=cut
sub getquotaroot {
return undef unless $_[0]->has_capability('QUOTA');
$_[0]->imap_command('getquotaroot', ASTRING, _encode_mailbox($_[1]));
}
###############################################################################
=head1 UIDPLUS EXTENSION
The following method is available if the server advertises support for
RFC2359 (IMAP4 UIDPLUS Extension). Refer to that RFC for additional
information.
=head2 uid_expunge $msgset
A variant of C<expunge> that allows the operation to be narrowed to
the messages with UIDs specified in C<$msgset>.
The C<$msgset> parameter is described in the section describing C<fetch>.
=cut
sub uid_expunge {
return undef unless $_[0]->has_capability('UIDPLUS');
$_[0]->imap_command('uid expunge', ATOM, $_[1]);
}
###############################################################################
sub imap_command {
my $self = shift;
if (!defined($cmd_callbacks{$_[0]})) {
carp("unknown imap command: $_[0]");
return undef;
}
unless ($cmd_callbacks{$_[0]}->[1] & $self->{State}) {
carp("invalid state for issuing $_[0] command");
return undef
}
$self->command($self->imap_cmd_callback($_[0]), @_);
}
###############################################################################
=head1 CALLBACKS
Many of the command methods result in the server sending back response
data. C<Net::IMAP> processes each response by parsing the data,
packages it in an appropriate object, and optionally calls a
programmer-defined callback for the response. This callback mechanism
is how programmers get access to the data retrieved from the server.
=head2 set_untagged_callback $item, $coderef
Assigns a programmer-defined code reference to the associated untagged
response. When an untagged response matching C<$item> is received,
C<$coderef> is called, with the IMAP object and the associated
response object passed as parameters.
The default callback for the C<ok>, C<bye>, C<bad>, and C<no> untagged
responses includes code to output the text from C<alert> responses to
stderr, using C<carp>. If you set your own callback for these
responses, be sure to code handle C<alert> codes. Per Section 7.1 of
RFC2060, clients are required to clearly display C<alert> messages to
users.
=cut
sub set_untagged_callback {
my $self = shift;
my $item = shift;
my $funcref = shift;
return undef unless defined($untagged_callbacks{$item});
$untagged_callbacks{$item}->[0] = $funcref;
}
#------------------------------------------------------------------------------
sub imap_cmd_callback {
my $self = shift;
my $cmd = shift;
return sub {
my $resp = shift;
return unless (defined($cmd_callbacks{$cmd})
&& defined($cmd_callbacks{$cmd}->[0]));
my $func = $cmd_callbacks{$cmd}->[0];
return $self->$func($resp);
}
}
sub imap_response_callback {
my $self = shift;
# my $seq = $self->next_sequence;
return sub {
my $response = shift;
my ($tag, $rest) = split(/\s/, $response, 2);
if ($tag eq '*') {
return $self->_imap_process_untagged_response($rest);
} elsif ($tag =~ /^\d+$/) {
return $self->_imap_process_tagged_response($tag, $rest);
} else {
croak("gack! server returned bogus tag: [$tag]");
}
}
}
sub _imap_process_untagged_response {
my $self = shift;
my $str = shift;
my @args;
my $num;
my ($cmd, $rest) = split(/\s/, $str, 2);
if ($cmd =~ /^\d+$/) {
push @args, $cmd;
($cmd, $rest) = split(/\s/, $rest, 2);
}
push @args, $rest if defined($rest);
$cmd = lc($cmd);
if (defined($untagged_callbacks{$cmd})) {
my $class = "Net::IMAP::" . ucfirst(lc($cmd));
my $ret = $class->new($self, @args);
# trigger a user callback, maybe - user callback is passed $self
# and the object created by the internal callback
if (defined($ret)) {
if (defined($untagged_callbacks{$cmd}->[0])) {
&{$untagged_callbacks{$cmd}->[0]}($self, $ret);
}
$self->debug_print(0, "untagged resp callback returned $ret")
if $self->debug;
} else {
carp("untagged resp callback returned undef");
}
return undef;
} else {
carp("received unknown response from server: [$cmd]\n");
}
}
sub _imap_process_tagged_response {
my $self = shift;
my $tag = shift;
my $str = shift;
my $resp = Net::IMAP::Response->new;
my ($cond, $text) = split(/\s/, $str, 2);
my $resp_code = undef;
if (substr($text, 0, 1) eq '[') {
($resp_code, $text) = _extract_resp_code($text);
}
$resp->{Sequence} = $tag;
$resp->{Status} = lc($cond);
$resp->{StatusCode} = $resp_code;
$resp->{Text} = $text;
if ($self->{Disconnect}) {
$self->close_connection or carp "error closing connection: $!";
}
return $resp;
}
###############################################################################
sub _select_cmd_callback {
my $self = shift;
my $resp = shift;
if ($resp->status eq 'ok') {
$self->{State} = IMAP_STATE_SELECT;
my $status = $resp->status_code;
$self->{ReadOnly} = (defined($status) && ($status->[0] eq 'read-only'));
} else {
$self->{State} = IMAP_STATE_AUTH;
$self->{Mailbox} = '';
}
}
sub _login_cmd_callback {
$_[0]->{State} = IMAP_STATE_AUTH if ($_[1]->status eq 'ok');
}
sub _close_cmd_callback {
if ($_[1]->status eq 'ok') {
$_[0]->_init_mailbox;
$_[0]->{State} = IMAP_STATE_AUTH;
}
}
#------------------------------------------------------------------------------
sub _default_aux_callback {
my $self = shift;
my $resp = shift;
my $code = $resp->code;
if (defined($code) && ($code->[0] eq 'alert')) {
carp "Alert: ", $resp->text, "\n";
}
}
###############################################################################
sub _valid_flag { ((substr($_[1], 0, 1) ne "\\")
|| defined($_system_flags{lc($_[1])})) }
###############################################################################
sub _extract_resp_code {
my $line = shift;
$line =~ m{
\[
([^\]]+) # response code
\]
(?:
\s
(.*) # remainder of response line
)?
$
}x;
my $resp_code = $1;
my $rest = $2;
my $resp_code_list = Net::xAP->parse_fields($resp_code);
$resp_code_list->[0] = lc($resp_code_list->[0]);
return($resp_code_list, $rest);
}
###############################################################################
# use Data::Dumper;
# sub _dump_internals { print STDERR "----\n", Dumper($_[0]), "----\n" }
###############################################################################
=head1 RESPONSE OBJECTS
As mention in the previous section, responses are parsed and packaged
into response objects, which are then passed to callbacks. Each type
of response has a corresponding object class. This section describes
the various response objects provided.
All of the class names itemized below are prefixed with C<Net::IMAP>.
As a general rule, IMAP C<nil> items are set to C<undef> in the parsed
data, and IMAP parenthetical lists are converted to list references
(of one form or another). In addition, atoms, quoted strings, and
literals are presented as Perl strings.
The condition responses (C<ok>, C<no>, C<bad>, C<bye>, and C<preauth>)
can include a response code. Refer to Section 7.1 in RFC2060 for a
description of each of the standard response codes.
=head1 Response
This is the object class for completion responses.
=head2 is_tagged
Returns a boolean value indicating whether the response is tagged. In
the case of tagged completion responses, this value is always C<1>.
=cut
package Net::IMAP::Response;
use vars qw(@ISA);
@ISA = qw(Net::xAP::Response);
sub is_tagged { 1 }
=head2 has_trycreate
Returns a boolean value indicating whether the C<TRYCREATE> response
code is present in the response. This can be used after a failed
C<append> or C<copy> command to determine whether the server thinks
the operation would succeed if a C<create> was issued for the
associated mailbox.
=cut
sub has_trycreate {
my $status_code = $_[0]->status_code;
return (defined($status_code) && (lc($status_code->[0]) eq 'trycreate'));
}
###############################################################################
=head1 UntaggedResponse
This class is common to all untagged server responses.
=head2 tag
Returns a string containing the tag associated with the response. In
the case of untagged responses, this is always C<*>.
=head2 is_tagged
Returns a boolean value indicating whether the response is tagged.
Obviously, in the case of untagged responses, this value is always
C<0>.
=head2 parent
Returns a reference to the parent IMAP object.
=cut
package Net::IMAP::UntaggedResponse;
sub tag { '*' }
sub is_tagged { 0 }
sub parent { $_[0]->{Parent} }
#------------------------------------------------------------------------------
package Net::IMAP::Cond;
use vars qw(@ISA);
@ISA = qw(Net::IMAP::UntaggedResponse);
use Carp;
sub new {
my $class = shift;
my $type = ref($class) || $class;
my $parent = shift;
my $str = shift;
my $self = {};
bless $self, $class;
$self->{Parent} = $parent;
my $resp_code = undef;
if (substr($str, 0, 1) eq '[') {
($resp_code, $str) = Net::IMAP::_extract_resp_code($str);
}
$self->{RespCode} = $resp_code;
$self->{Text} = $str;
carp "Alert: $str\n" if (defined($resp_code) && $resp_code->[0] eq 'alert');
if (($self->name eq 'bye') && !$self->parent->{Disconnect}) {
# a logout command wasn't issued, so it's probably the result of
# an autologout timer expiring
$self->parent->close_connection or carp "error closing connection: $!";
}
return $self;
}
sub code { $_[0]->{RespCode} }
sub name { undef }
#------------------------------------------------------------------------------
=head1 Ok
This is a container for untagged C<ok> responses from the server.
=head2 code
Returns a list reference containing response code elements in the
response. Returns C<undef> if no response code is present.
=head2 name
Returns the name of the response. In the case of C<Ok>, this returns
'ok'. This method is provided as a convenience for end-programmers
wanting to write one common subroutine for one or more of the
responses C<Ok>, C<No>, C<Bad>, and C<Bye>.
=cut
package Net::IMAP::Ok;
use vars qw(@ISA);
@ISA = qw(Net::IMAP::Cond);
sub name { 'ok' };
#------------------------------------------------------------------------------
=head1 No
This is a container for untagged C<no> responses from the server.
=cut
package Net::IMAP::No;
use vars qw(@ISA);
@ISA = qw(Net::IMAP::Cond);
sub name { 'no' };
#------------------------------------------------------------------------------
=head1 Bad
This is a container for untagged C<bad> responses from the server.
=cut
package Net::IMAP::Bad;
use vars qw(@ISA);
@ISA = qw(Net::IMAP::Cond);
sub name { 'bad' };
#------------------------------------------------------------------------------
=head1 Bye
This is a container for untagged C<bye> responses from the server.
=cut
package Net::IMAP::Bye;
use vars qw(@ISA);
@ISA = qw(Net::IMAP::Cond);
sub name { 'bye' };
###############################################################################
=head1 Expunge
This is a container for C<expunge> responses from the server.
The information returned by C<qty_messages> is automatically updated
when C<expunge> responses are received.
=head2 msgnum
Returns the message number specified in the C<expunge> response.
=cut
package Net::IMAP::Expunge;
use vars qw(@ISA);
@ISA = qw(Net::IMAP::UntaggedResponse);
sub name { 'expunge' }
sub new {
my $class = shift;
my $type = ref($class) || $class;
my $parent = shift;
my $str = shift;
my $self = {};
bless $self, $class;
$self->{Parent} = $parent;
$self->{Msgnum} = $str;
return $self;
}
sub msgnum { $_[0]->{Msgnum} }
###############################################################################
=head1 Capability
This is a container for C<capability> responses.
=head2 capabilities
Returns the list of capabilities supported by the server, minus the
authentication capabilities. The list is not guaranteed to be in any
specific order.
=head2 has_capability $capname
Returns a boolean value indicating whether the server supports the
specified capability.
=head2 authtypes
Returns a list of authentication types supported by the server.
=head2 has_authtype $authname
Returns a boolean value indicating whether the server supports the
specified authentication type.
=cut
package Net::IMAP::Capability;
use vars qw(@ISA);
@ISA = qw(Net::IMAP::UntaggedResponse);
sub name { 'capability' }
sub new {
my $class = shift;
my $type = ref($class) || $class;
my $parent = shift;
my $str = shift;
my $self = {};
bless $self, $class;
$self->{Parent} = $parent;
undef $self->{Parent}{Capabilities}; # needs to be repopulated each time
undef $self->{Parent}{AuthTypes}; # needs to be repopulated each time
for my $cap (split(/\s/, $str)) {
$cap = uc($cap);
$self->{Parent}{Capabilities}{$cap}++;
$self->{Parent}{AuthTypes}{$1}++ if $cap =~ /^AUTH=(.*)$/;
$self->{Capabilities}{$cap}++;
$self->{AuthTypes}{$1}++ if $cap =~ /^AUTH=(.*)$/;
}
# force the non-synchronous literals option off if the server
# doesn't support it
$self->{Parent}{Options}{NonSyncLits} = 0
unless defined($self->{Parent}{Capabilities}{'LITERAL+'});
return $self;
}
sub capabilities { keys %{$_[0]->{Capabilities}} }
sub has_capability { defined($_[0]->{Capabilities}{uc($_[1])}) }
sub authtypes { keys %{$_[0]->{AuthTypes}} }
sub has_authtype { defined($_[0]->{AuthTypes}{uc($_[1])}) }
###############################################################################
=head1 List
This is a container for C<list> responses.
=head2 mailbox
Returns the name of the mailbox contained in the object.
=head2 delimiter
Returns the hierarchy delimiter associated with the mailbox.
=head2 flags
Returns a list of the flags associated with the mailbox.
=head2 has_flag $flag
Returns a boolean value indicating whether the given $flag is defined
for the mailbox.
=cut
package Net::IMAP::List;
use vars qw(@ISA);
@ISA = qw(Net::IMAP::UntaggedResponse);
sub name { 'list' }
sub new {
my $class = shift;
my $type = ref($class) || $class;
my $parent = shift;
my $str = shift;
my $self = {};
bless $self, $class;
$self->{Parent} = $parent;
my $fields = Net::xAP->parse_fields($str);
for my $flag (@{$fields->[0]}) {
$self->{Flags}{lc($flag)}++;
}
$self->{Delim} = $fields->[1];
$self->{Mailbox} = Net::IMAP::_decode_mailbox($fields->[2]);
return $self;
}
sub mailbox { $_[0]->{Mailbox} }
sub delimiter { $_[0]->{Delim} }
sub flags { keys %{$_[0]->{Flags}} }
sub has_flag { defined($_[0]->{Flags}{lc($_[1])}) }
#------------------------------------------------------------------------------
=head1 List
This is a container for C<lsub> responses. It provides the same
interface as the C<Net::IMAP::List> class.
=cut
package Net::IMAP::Lsub;
use vars qw(@ISA);
@ISA = qw(Net::IMAP::List);
sub name { 'lsub' }
###############################################################################
=head1 Fetch
This is a container for C<fetch> responses.
Responses for partial fetches bear special mention. While both the
starting byte and quantity of bytes are specified when doing partial
fetches with the C<fetch> command, the corresponding response will
only show the starting byte. In other words, the command
C<$imap-E<gt>fetch(1, 'body[]E<lt>0.1024E<gt>'> will, if successful,
result in a fetch response item of C<body[]E<lt>0E<gt>> containing a
1024 octet value. To match a given response for a partial fetch, you
might need to use C<length> to match it up with the corresponding item
specified in the C<fetch> command.
=head2 msgnum
Returns the message number identified in the response.
=head2 items
Returns the list of data item names contained in the response. The
list is not guaranteed to be in any specific order.
=head2 item $item
Returns the data associated with the specified data item.
The following list enumerates the data types associated with each
fetch item:
=over 14
=item envelope
Net::IMAP::Envelope
=item bodystructure
Net::IMAP::BodyStructure
=item body
Net::IMAP::BodyStructure
=item flags
Net::IMAP::Flags
=item UID
Integer
=item rfc822.size
Integer
=item I<default>
String
=back
=cut
package Net::IMAP::Fetch;
use vars qw(@ISA);
@ISA = qw(Net::IMAP::UntaggedResponse);
sub name { 'fetch' }
sub new {
my $class = shift;
my $type = ref($class) || $class;
my $parent = shift;
my $msgnum = shift;
my $str = shift;
my $self = {};
bless $self, $class;
$self->{Parent} = $parent;
$self->{Msgnum} = $msgnum;
my %hash = @{Net::xAP->parse_fields($str)->[0]};
for my $key (keys %hash) {
my $lckey = lc($key);
print "$lckey $hash{$key}\n"
if $parent->debug;
if ($lckey eq 'envelope') {
$self->{Items}{$lckey} = Net::IMAP::Envelope->new($hash{$key});
} elsif (($lckey eq 'bodystructure') || ($lckey eq 'body')) {
$self->{Items}{$lckey} = Net::IMAP::BodyStructure->new($hash{$key});
} elsif ($lckey eq 'flags') {
$self->{Items}{$lckey} = Net::IMAP::Flags->new($parent);
for my $flag (@{$hash{$key}}) {
$self->{Items}{$lckey}{Flags}{lc($flag)}++;
}
} else {
if ($self->{Parent}{Options}{EOL} eq 'lf') {
if ((substr($lckey, 0, 5) eq 'body[')
|| ($lckey eq 'rfc822')
|| ($lckey eq 'rfc822.header')
|| ($lckey eq 'rfc822.text')) {
$hash{$key} =~ s/\r\n/\n/mg;
}
}
$self->{Items}{$lckey} = $hash{$key};
}
}
return $self;
}
sub msgnum { $_[0]->{Msgnum} }
sub items { keys %{$_[0]->{Items}} }
sub item { $_[0]->{Items}{lc($_[1])} }
###############################################################################
=head1 Status
This is a container for C<status> responses.
=head2 mailbox
Returns a string containing the mailbox the status information is
associated with.
=head2 items
Returns the list of status items contains in the status response.
=head2 item $item
Returns the value of the C<$item> status item.
=cut
package Net::IMAP::Status;
use vars qw(@ISA);
@ISA = qw(Net::IMAP::UntaggedResponse);
sub name { 'status' }
sub new {
my $class = shift;
my $type = ref($class) || $class;
my $parent = shift;
my $str = shift;
my $self = {};
bless $self, $class;
$self->{Parent} = $parent;
my $fields = Net::xAP->parse_fields($str);
$self->{Mailbox} = Net::IMAP::_decode_mailbox($fields->[0]);
my %hash = @{$fields->[1]};
for my $key (keys %hash) {
$self->{Items}{lc($key)} = $hash{$key};
}
return $self;
}
sub mailbox { $_[0]->{Mailbox} }
sub items { keys %{$_[0]->{Items}} }
sub item { $_[0]->{Items}{lc($_[1])} }
###############################################################################
=head1 Search
This is a container for C<search> responses.
=head2 msgnums
Returns the list of message numbers contained in the response.
=cut
package Net::IMAP::Search;
use vars qw(@ISA);
@ISA = qw(Net::IMAP::UntaggedResponse);
sub name { 'search' }
sub new {
my $class = shift;
my $type = ref($class) || $class;
my $parent = shift;
my $str = shift;
my $self = {};
bless $self, $class;
$self->{Parent} = $parent;
if (!defined $str) {
$self->{Msgnums} = {};
return $self;
}
for my $item (split(/\s/, $str)) {
$self->{Msgnums}{$item}++;
}
return $self;
}
sub msgnums { keys %{$_[0]->{Msgnums}} }
###############################################################################
=head1 Flags
This is a container for C<flags> responses.
=head2 flags
Returns the list of flags contained in the response.
=head2 has_flag $flag
Returns a boolean value indicating whether the specified flag is
contained in the response.
As a convenience, the information from the C<flags> response is also
stored in the parent C<Net::IMAP> object, and is available via
C<Net::IMAP> versions of the C<flags> and C<has_flags> methods.
=cut
package Net::IMAP::Flags;
use vars qw(@ISA);
@ISA = qw(Net::IMAP::UntaggedResponse);
sub name { 'flags' }
sub new {
my $class = shift;
my $type = ref($class) || $class;
my $parent = shift;
my $str = shift;
my $self = {};
bless $self, $class;
$self->{Parent} = $parent;
if (defined($str)) {
for my $flag (@{Net::xAP->parse_fields($str)->[0]}) {
$self->{Flags}{lc($flag)}++;
$self->{Parent}{MailboxStatus}{'flags'}{lc($flag)}++;
}
}
return $self;
}
sub flags { keys %{$_[0]->{Flags}} }
sub has_flag { defined($_[0]->{Flags}{lc($_[1])}) }
###############################################################################
=head1 Exists
This is a container for C<exists> responses.
=head2 exists
Returns the quantity of messages in the currently selected mailbox.
This is information is also available in the C<qty_messages> method in
the C<Net::IMAP> class.
=cut
package Net::IMAP::Exists;
use vars qw(@ISA);
@ISA = qw(Net::IMAP::UntaggedResponse);
sub name { 'exists' }
sub new {
my $class = shift;
my $type = ref($class) || $class;
my $parent = shift;
my $str = shift;
my $self = {};
bless $self, $class;
$self->{Parent} = $parent;
$self->{Parent}{MailboxStatus}{'exists'} = $str;
$self->{Value} = $str;
return $self;
}
sub exists { $_[0]->{Value} }
###############################################################################
=head1 Recent
This is a container for C<recent> responses.
=head2 recent
Returns the number of messages with the C<\recent> flag set.
This information is also available in the C<qty_recent> method in the
C<Net::IMAP> class.
=cut
package Net::IMAP::Recent;
use vars qw(@ISA);
@ISA = qw(Net::IMAP::UntaggedResponse);
sub name { 'recent' }
sub new {
my $class = shift;
my $type = ref($class) || $class;
my $parent = shift;
my $str = shift;
my $self = {};
bless $self, $class;
$self->{Parent} = $parent;
$self->{Parent}{MailboxStatus}{'recent'} = $str;
$self->{Value} = $str;
return $self;
}
sub recent { $_[0]->{Value} }
###############################################################################
=head1 Namespace
This is a container for C<namespace> responses.
=head2 personal [$namespace]
With no argument specified, returns a list of personal namespaces. If
C<$namespace> is specified, returns the delimiter character for the
specific personal namespace.
=head2 other_users [$namespace]
With no argument specified, returns a list of other users' namespaces.
If C<$namespace> is specified, returns the delimiter character for the
specific other users' namespace.
=head2 shared [$namespace]
With no argument specified, returns a list of shared namespaces. If
C<$namespace> is specified, returns the delimiter character for the
specific shared namespace.
=cut
package Net::IMAP::Namespace;
use vars qw(@ISA);
@ISA = qw(Net::IMAP::UntaggedResponse);
sub name { 'namespace' }
my @namespace_types = qw(personal other_users shared);
sub new {
my $class = shift;
my $type = ref($class) || $class;
my $parent = shift;
my $str = shift;
my $self = {};
bless $self, $class;
$self->{Parent} = $parent;
my $fields = Net::xAP->parse_fields($str);
if (lc($fields->[1]) eq 'nil')
{
for my $n (0 .. 2) {
$self->{Namespaces}{$namespace_types[$n]}{$fields->[0]} = '';
}
}
else
{
for my $n (0 .. 2) {
my $field = $fields->[$n];
for my $item (@{$field}) {
$self->{Namespaces}{$namespace_types[$n]}{$item->[0]} = $item->[1];
}
}
}
return $self;
}
sub personal {
return $_[0]->{Namespaces}{'personal'}{lc($_[1])} if (defined($_[1]));
keys %{$_[0]->{Namespaces}{'personal'}};
}
sub other_users {
return $_[0]->{Namespaces}{'other_users'}{lc($_[1])} if (defined($_[1]));
keys %{$_[0]->{Namespaces}{'other_users'}};
}
sub shared {
return $_[0]->{Namespaces}{'shared'}{lc($_[1])} if (defined($_[1]));
keys %{$_[0]->{Namespaces}{'shared'}};
}
###############################################################################
=head1 ACL
This is a container for C<acl> responses>
=head2 mailbox
Returns the name of the mailbox associated with the given ACL data.
=head2 identifiers
Returns a list of identifiers contained in the ACL data.
=head2 identifier $identifier
=cut
package Net::IMAP::Acl;
use vars qw(@ISA);
@ISA = qw(Net::IMAP::UntaggedResponse);
sub name { 'acl' }
sub new {
my $class = shift;
my $type = ref($class) || $class;
my $parent = shift;
my $str = shift;
my $self = {};
bless $self, $class;
$self->{Parent} = $parent;
my @fields = @{Net::xAP->parse_fields($str)};
$self->{Mailbox} = shift(@fields);
my %hash = @fields;
for my $key (keys %hash) {
$self->{Identifiers}{lc($key)} = $hash{$key};
}
return $self;
}
sub mailbox { $_[0]->{Mailbox} }
sub identifiers { keys %{$_[0]->{Identifiers}} }
sub identifier { $_[0]->{Identifiers}{lc($_[1])} }
###############################################################################
=head1 Listrights
This is a container for C<listrights> responses.
=head2 mailbox
Returns the name of the mailbox associated with the given rights.
=head2 identifier
Returns a string containing the identifier associated with the rights.
=head2 rights
Returns a string containing the rights contained in the response.
=cut
package Net::IMAP::Listrights;
use vars qw(@ISA);
@ISA = qw(Net::IMAP::UntaggedResponse);
sub name { 'listrights' }
sub new {
my $class = shift;
my $type = ref($class) || $class;
my $parent = shift;
my $str = shift;
my $self = {};
bless $self, $class;
$self->{Parent} = $parent;
my @fields = @{Net::xAP->parse_fields($str)};
$self->{Mailbox} = shift(@fields);
$self->{Identifier} = shift(@fields);
$self->{Rights} = [@fields];
return $self;
}
sub mailbox { $_[0]->{Mailbox} }
sub identifier { $_[0]->{Identifier} }
sub rights { (wantarray) ? @{$_[0]->{Rights}} : $_[0]->{Rights} }
###############################################################################
=head1 Myrights
This is a container for C<myrights> responses
=head2 mailbox
Returns the name of the mailbox associated with the given rights.
=head2 rights
Returns a string containing the rights contained in the response.
=cut
package Net::IMAP::Myrights;
use vars qw(@ISA);
@ISA = qw(Net::IMAP::UntaggedResponse);
sub name { 'myrights' }
sub new {
my $class = shift;
my $type = ref($class) || $class;
my $parent = shift;
my $str = shift;
my $self = {};
bless $self, $class;
$self->{Parent} = $parent;
my $fields = Net::xAP->parse_fields($str);
$self->{Mailbox} = $fields->[0];
$self->{Rights} = $fields->[1];
return $self;
}
sub mailbox { $_[0]->{Mailbox} }
sub rights { $_[0]->{Rights} }
###############################################################################
=head1 Quota
This is a container for C<quota> responses.
=head2 quotaroot
Returns a string containing the name of the quota root in the response.
=head2 quotas
Returns a list of the quotas contained in the response.
=head2 usage $quota
Returns the usage value associated with the given C<$quota>. Returns
C<undef> is the given C<$quota> is not present in the response.
=head2 limit $quota
Returns the usage limit associated with the given C<$quota>. Returns
C<undef> is the given C<$quota> is not present in the response.
=cut
package Net::IMAP::Quota;
use vars qw(@ISA);
@ISA = qw(Net::IMAP::UntaggedResponse);
sub name { 'quota' }
sub new {
my $class = shift;
my $type = ref($class) || $class;
my $parent = shift;
my $str = shift;
my $self = {};
bless $self, $class;
$self->{Parent} = $parent;
my @fields = @{Net::xAP->parse_fields($str)};
$self->{QuotaRoot} = shift(@fields);
while (@fields) {
my ($resource, $usage, $limit) = splice(@{$fields[0]}, 0, 3);
$self->{Quotas}{lc($resource)} = [$usage, $limit];
}
return $self;
}
sub quotaroot { $_[0]->{QuotaRoot} }
sub quotas { keys %{$_[0]->{Quotas}} }
sub usage { $_[0]->{Quotas}{lc($_[1])}->[0] }
sub limit { $_[0]->{Quotas}{lc($_[1])}->[1] }
###############################################################################
=head1 Quotaroot
This is a container for C<quotaroot> responses.
=head2 mailbox
Returns the name of the mailbox associated with the quotaroot data.
=head2 quotaroots
If called in an array context, returns the list of quotaroots
associated with the mailbox. If called in a scalar context, returns a
list reference.
=cut
package Net::IMAP::Quotaroot;
use vars qw(@ISA);
@ISA = qw(Net::IMAP::UntaggedResponse);
sub name { 'quotaroot' }
sub new {
my $class = shift;
my $type = ref($class) || $class;
my $parent = shift;
my $str = shift;
my $self = {};
bless $self, $class;
$self->{Parent} = $parent;
my @fields = @{Net::xAP->parse_fields($str)};
$self->{Mailbox} = shift(@fields);
$self->{Quotaroots} = [@fields];
return $self;
}
sub mailbox { $_[0]->{Mailbox} }
sub quotaroots { (wantarray) ? @{$_[0]->{Quotaroots}} : $_[0]->{Quotaroots} }
###############################################################################
=head1 MISC FETCH OBJECTS
A C<fetch> response can be relatively complicated. This section
documents various classes and methods associated with the various
pieces of information available in C<fetch> responses.
=cut
package Net::IMAP::FetchData;
sub new {
my $class = shift;
my $type = ref($class) || $class;
my $self = [];
if (defined($_[0])) {
push(@{$self},
map {
(lc($_) eq 'nil') ? undef : Net::xAP->dequote($_)
} @{$_[0]});
}
bless $self, $class;
}
###############################################################################
=head1 BodyStructure
This is a container for C<bodystructure> items in C<fetch> responses.
=head2 type
Returns a string containing the MIME type of the message. This is the
left-hand portion of a MIME media type. For example, the type of
C<text/plain> is C<text>.
=head2 subtype
Returns a string containing the MIME subtype of the message. This is
the right-hand portion of a MIME media type. For example, the subtype
of C<text/plain> is C<plain>.
=head2 parameters
Returns a reference to a hash containing the key/value attribute pairs
in the C<Content-Type> field.
If, for example, the C<Content-Type> field was:
Content-Type: text/plain; charset=us-ascii
The hash would contain one entry the a key of C<charset>, and a value
of C<us-ascii>. The key is always forced to be lowercase, but the
case of the value is retained from the server.
=head2 disposition
Returns the disposition type in the C<Content-Disposition> field.
Returns C<undef> if no such field exists.
=head2 disp_parameters
Returns a reference to a hash containing the key/value attributer
pairs in the C<Content-Disposition> field. A reference to an empty
hash is returned if no such field exists, or if there are no
parameters in the field.
=head2 language
Returns a reference to a list of the language tags present in the
C<Content-Language> field. Returns a reference to an empty hash if no
such field is present.
=cut
package Net::IMAP::BodyStructure;
sub new {
my $class = shift;
my $type = ref($class) || $class;
my $data = shift;
return Net::IMAP::Multipart->new($data) if (ref($data->[0]) eq 'ARRAY');
return Net::IMAP::Bodypart->new($data);
}
sub subtype { $_[0]->{Subtype} }
sub parameters { $_[0]->{Parms} }
sub disposition { $_[0]->{Disp} }
sub disp_parameters { $_[0]->{DispParms} }
sub language { $_[0]->{Lang} }
sub _parse_parms {
my $self = shift;
my $data = shift;
if (ref($data) eq 'ARRAY') {
my @parms = @{$data};
while (@parms) {
my ($key, $value) = splice(@parms, 0, 2);
$self->{Parms}{lc($key)} = $value;
}
}
}
sub _parse_disp {
my $self = shift;
my $data = shift;
$self->{Disp} = lc($data);
if (ref($data) eq 'ARRAY') {
if (lc($data->[1]) ne 'nil') {
my @parms = @{$data->[1]};
while (@parms) {
my ($key, $value) = splice(@parms, 0, 2);
$self->{DispParms}{lc($key)} = $value;
}
}
}
}
sub _parse_lang {
my $self = shift;
my $data = shift;
$data = lc($data);
if ($data ne 'nil') {
if (ref($data) eq 'ARRAY') {
$self->{Lang} = [map { lc($_) } @{$data}];
} else {
$self->{Lang} = [lc($data)];
}
}
}
#------------------------------------------------------------------------------
=head1 Multipart
This is a container for C<BodyStructure> objects that are multipart entities.
=head2 parts
Returns a list reference of the body parts contained in the multipart
entity.
=cut
package Net::IMAP::Multipart;
use vars qw(@ISA);
@ISA = qw(Net::IMAP::BodyStructure);
sub new {
my $class = shift;
my $type = ref($class) || $class;
my $data = shift;
my $self = {};
bless $self, $class;
$self->{Parts} = [];
my $i = 0;
for my $item (@{$data}) {
last if (ref($item) ne 'ARRAY');
if (ref($item->[0]) eq 'ARRAY') {
push @{$self->{Parts}}, Net::IMAP::Multipart->new($item);
} else {
push @{$self->{Parts}}, Net::IMAP::Bodypart->new($item);
}
$i++;
}
$self->{Subtype} = lc(Net::xAP->dequote($data->[$i++]));
$self->{Parms} = {};
$self->{Disp} = undef;
$self->{DispParms} = {};
$self->{Lang} = undef;
if (defined($data->[$i])) {
$self->_parse_parms($data->[$i++]);
if (defined($data->[$i])) {
$self->_parse_disp($data->[$i++]);
if (defined($data->[$i])) {
$self->_parse_lang($data->[$i++]);
if (defined($data->[$i])) {
carp("Note: bodystructure contains unknown extension fields\n");
}
}
}
}
return $self;
}
sub type { 'multipart' }
sub parts { $_[0]->{Parts} }
#------------------------------------------------------------------------------
=head1 Bodypart
This is a container for singlepart entities in C<BodyStructure> and
C<Multipart> objects.
=head2 id
Return a string containing the contents of the C<Content-ID> field, if
one is present, otherwise returns undef.
=head2 description
Return a string containing the contents of the C<Content-Description>
field, if one is present, otherwise returns undef.
=head2 encoding
Returns a string containing the contents of the
C<Content-Transfer-Encoding> field. Returns C<undef> if no such field
is in the entity.
=head2 size
Returns the number of octets in the entity.
=head2 lines
If the MIME content type is C<message/rfc822> or the major type is
C<text>, returns the number of lines in the entity, else returns C<undef>.
=head2 envelope
If the MIME content type is C<message/rfc822>, returns a
C<Net::IMAP::Envelope> object, otherwise returns undef.
=head2 bodystructure
If the MIME content type is C<message/rfc822>, returns a
C<Net::IMAP::BodyStructure> object, otherwise returns undef.
=head2 md5
Returns a string containing the contents of the C<Content-MD5> field.
Returns C<undef> if no such field is in the entity.
=cut
package Net::IMAP::Bodypart;
use vars qw(@ISA);
@ISA = qw(Net::IMAP::BodyStructure);
use Carp;
sub new {
my $class = shift;
my $type = ref($class) || $class;
my $data = shift;
my $self = {};
bless $self, $class;
my $i = 0;
$self->{Type} = lc(Net::xAP->dequote($data->[$i++]));
$self->{Subtype} = lc(Net::xAP->dequote($data->[$i++]));
$self->{Parms} = {};
$self->_parse_parms($data->[$i++]);
$self->{Id} = Net::xAP->dequote($data->[$i++]);
$self->{Description} = Net::xAP->dequote($data->[$i++]);
$self->{Encoding} = lc(Net::xAP->dequote($data->[$i++]));
$self->{Size} = $data->[$i++];
if (($self->{Type} eq 'message') && ($self->{Subtype} eq 'rfc822')) {
$self->{Envelope} = Net::IMAP::Envelope->new($data->[$i++]);
$self->{Bodystructure} = Net::IMAP::BodyStructure->new($data->[$i++]);
$self->{Lines} = $data->[$i++];
} elsif ($self->{Type} eq 'text') {
$self->{Lines} = $data->[$i++];
}
$self->{Envelope} ||= undef;
$self->{BodyStructure} ||= undef;
$self->{Lines} ||= undef;
if (defined($data->[$i])) {
$self->{MD5} = Net::xAP->dequote($data->[$i++]);
if (defined($data->[$i])) {
$self->_parse_disp($data->[$i++]);
if (defined($data->[$i])) {
$self->_parse_lang($data->[$i++]);
if (defined($data->[$i])) {
carp("Note: bodystructure contains unknown extension fields\n");
}
}
}
}
$self->{MD5} ||= undef;
$self->{Disp} ||= undef;
$self->{DispParms} ||= {};
$self->{Lang} ||= undef;
return $self;
}
sub type { $_[0]->{Type} }
sub id { $_[0]->{Id} }
sub description { $_[0]->{Description} }
sub encoding { $_[0]->{Encoding} }
sub size { $_[0]->{Size} }
sub lines { $_[0]->{Lines} } # message/rfc822 and text/*
sub envelope { $_[0]->{Envelope} } # message/rfc822
sub bodystructure { $_[0]->{Bodystructure} } # message/rfc822
sub md5 { $_[0]->{MD5} }
###############################################################################
=head1 Envelope
This is a container for envelope data in C<fetch> responses.
For those familiar with SMTP, this is not the same type envelope.
Rather, it is a composite structure containing key source,
destination, and reference information in the message. When retrieved
from the server, it is populated into a C<Net::IMAP::Envelope> object.
The following methods are available.
=head2 date
Returns a string with the contents of the C<Date> field.
=head2 subject
Returns a string with the contents of the C<Subject> field.
=head2 from
Returns a list reference of C<Net::IMAP::Addr> objects with the
contents of the C<From> field.
=head2 sender
Returns a list reference of C<Net::IMAP::Addr> objects with the
contents of the C<Sender> field. If no C<Sender> field is present in
the message, the server will default it to the contents of the C<From>
field.
=head2 reply_to
Returns a list reference of C<Net::IMAP::Addr> objects with the
contents of the C<Reply-To> field. If no C<Reply-To> field is present
in the message, the server will default it to the contents of the
C<From> field.
=head2 to
Returns a list reference of C<Net::IMAP::Addr> objects with the
contents of the C<To>field. Will return C<undef> if no C<To> field
exists in the message.
=head2 cc
Returns a list reference of C<Net::IMAP::Addr> objects with the
contents of the C<Cc> field. Will return C<undef> if no C<Cc> field
exists in the message.
=head2 bcc
Returns a list reference of C<Net::IMAP::Addr> objects with the
contents of the C<Bcc> field. Will return C<undef> if no C<Bcc> field
exists in the message.
=head2 in_reply_to
Returns a string with the contents of the C<In-Reply-To> field.
Returns C<undef> if no such field is present in the message.
=head2 message_id
Returns a string with the contents of the C<Date> field. Returns
C<undef> if no such field is present in the message.
=cut
package Net::IMAP::Envelope;
use vars qw(@ISA);
@ISA = qw(Net::IMAP::FetchData);
sub new {
my $class = shift;
my $type = ref($class) || $class;
my $data = shift;
my $self = Net::IMAP::FetchData->new
or return undef;
bless $self, $class;
$self->[0] = Net::xAP->dequote($data->[0]);
$self->[1] = Net::xAP->dequote($data->[1]);
for my $i (2 .. 7) {
if (lc($data->[$i]) eq 'nil') {
$self->[$i] = undef;
next;
}
push @{$self->[$i]}, map { Net::IMAP::Addr->new($_) } @{$data->[$i]};
}
$self->[8] = Net::xAP->dequote($data->[8]);
$self->[9] = Net::xAP->dequote($data->[9]);
return $self;
}
sub date { $_[0]->[0] }
sub subject { $_[0]->[1] }
sub from { $_[0]->[2] }
sub sender { $_[0]->[3] }
sub reply_to { $_[0]->[4] }
sub to { $_[0]->[5] }
sub cc { $_[0]->[6] }
sub bcc { $_[0]->[7] }
sub in_reply_to { $_[0]->[8] }
sub message_id { $_[0]->[9] }
#------------------------------------------------------------------------------
=head1 Addr
This is a container for address structures in C<Envelope> objects.
=head2 phrase
Returns a string containing the phrase portion of the address, or
C<undef> if no phrase is present.
=head2 route
Returns a string containing the route portion of the address, or
C<undef> if no route information is present.
=head2 localpart
Returns a string containing the localpart portion of the address, or
C<undef> if no localpart is present.
=head2 domain
Returns a string containing the domain portion of the address, or
C<undef> if no domain is present.
=head2 as_string
Returns a string representation of the contents of the object.
=cut
package Net::IMAP::Addr;
use vars qw(@ISA);
@ISA = qw(Net::IMAP::FetchData);
sub phrase { $_[0]->[0] }
sub route { $_[0]->[1] }
sub localpart { $_[0]->[2] }
sub domain { $_[0]->[3] }
sub as_string {
my $self = shift;
my $str;
my $domain = $self->domain;
my $localpart = $self->localpart;
my $route = $self->route;
my $phrase = $self->phrase;
return undef if (!defined($domain)); # part of a group list
return undef if (!defined($localpart));
$str = "$localpart\@$domain";
if (defined($route) || defined($phrase)) {
$str = "$route:$str" if defined($route);
$str = "<$str>"; # route-addrs and phrases need <>
$str = "$phrase $str" if defined($phrase);
}
return $str;
}
###############################################################################
=head1 CAVEATS
Minimal testing has been done against the various IMAP server
implementations. Refer to C<BUGS> for known bugs/malfeatures.
=head1 AUTHOR
Kevin Johnson E<lt>F<kjj@pobox.com>E<gt>
=head1 COPYRIGHT
Copyright (c) 1997-1999 Kevin Johnson <kjj@pobox.com>.
All rights reserved. This program is free software; you can
redistribute it and/or modify it under the same terms as Perl itself.
=cut
1;
|