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 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741
|
#!/usr/bin/perl
# bts: This program provides a convenient interface to the Debian
# Bug Tracking System.
#
# Written by Joey Hess <joeyh@debian.org>
# Modifications by Julian Gilbey <jdg@debian.org>
# Modifications by Josh Triplett <josh@freedesktop.org>
# Copyright 2001-2003 Joey Hess <joeyh@debian.org>
# Modifications Copyright 2001-2003 Julian Gilbey <jdg@debian.org>
# Modifications Copyright 2007 Josh Triplett <josh@freedesktop.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Use our own subclass of Pod::Text to
# a) Strip the POD markup before displaying it via "bts help"
# b) Automatically display the text which is supposed to be replaced by the
# user between <>, as per convention.
package Pod::BTS;
use strict;
use parent qw(Pod::Text);
sub cmd_i { return '<' . $_[2] . '>' }
package main;
=head1 NAME
bts - command-line interface for Debian's Bug Tracking System (BTS)
=cut
use 5.010; # for defined-or
use strict;
use warnings;
use File::Basename;
use File::Copy;
use File::HomeDir;
use File::Path qw(make_path rmtree);
use File::Spec;
use File::Temp qw/tempfile/;
use Net::SMTP;
use Cwd;
use IO::File;
use IO::Handle;
use Devscripts::DB_File_Lock;
use Devscripts::Debbugs;
use Dpkg::Path qw(find_command);
use Fcntl qw(O_RDWR O_RDONLY O_CREAT F_SETFD);
use Getopt::Long;
use Encode;
# Need support for ; as query param separator
use URI 1.37;
use URI::QueryParam;
use Scalar::Util qw(looks_like_number);
use POSIX qw(locale_h strftime isatty WNOHANG);
setlocale(LC_TIME, "C"); # so that strftime is locale independent
# Funny UTF-8 warning messages from HTML::Parse should be ignorable (#292671)
$SIG{'__WARN__'} = sub {
warn $_[0]
unless $_[0]
=~ /^Parsing of undecoded UTF-8 will give garbage when decoding entities/;
};
my $it = undef;
my $last_user = '';
my $lwp_broken = undef;
my $authen_sasl_broken;
my $ua;
sub have_lwp() {
return ($lwp_broken ? 0 : 1) if defined $lwp_broken;
eval {
require LWP;
require LWP::UserAgent;
require HTTP::Status;
require HTTP::Date;
};
if ($@) {
if ($@ =~ m%^Can\'t locate LWP%) {
$lwp_broken = "the libwww-perl package is not installed";
} else {
$lwp_broken = "couldn't load LWP::UserAgent: $@";
}
} else {
$lwp_broken = '';
}
return $lwp_broken ? 0 : 1;
}
sub have_authen_sasl() {
return ($authen_sasl_broken ? 0 : 1) if defined $authen_sasl_broken;
eval { require Authen::SASL; };
if ($@) {
if ($@ =~ m%^Can't locate Authen/SASL%) {
$authen_sasl_broken
= 'the libauthen-sasl-perl package is not installed';
} else {
$authen_sasl_broken = "couldn't load Authen::SASL: $@";
}
} else {
$authen_sasl_broken = '';
}
return $authen_sasl_broken ? 0 : 1;
}
# Constants
sub MIRROR_ERROR { 0; }
sub MIRROR_DOWNLOADED { 1; }
sub MIRROR_UP_TO_DATE { 2; }
my $NONPRINT = "\\x00-\\x1F\\x7F-\\xFF"; # we need this later for MIME stuff
our $onlinecheck_bypass_msg
= "\n Use the --offline option to bypass this check at your own peril.";
my $progname = basename($0);
my $modified_conf_msg;
my $debug = exists $ENV{'DEBUG'} && $ENV{'DEBUG'};
# Program version handling
# The BTS changed its format :/ Pages downloaded using old versions
# of bts won't look very good, so we force updating if the last cached
# version was downloaded by a devscripts version less than
# $new_cache_format_version
my $version = '###VERSION###';
$version = '2.9.6' if $version =~ /\#/; # for testing unconfigured version
my $new_cache_format_version = '2.9.6';
# The official list is mirrored
# bugs-mirror.debian.org:/srv/bugs.debian.org/etc/config
# in the variable @gTags; we copy it verbatim here.
#
# Note that it is also in the POD documentation in the bts_tag
# function below, look for "potato".
our (@gTags, @valid_tags, %valid_tags);
#<<< This variable definition should be kept verbatim from the BTS config
@gTags = ( "patch", "wontfix", "moreinfo", "unreproducible",
"help", "security", "upstream", "pending", "confirmed",
"ipv6", "lfs", "d-i", "l10n", "newcomer", "a11y", "ftbfs",
"fixed-upstream", "fixed", "fixed-in-experimental",
"sid", "experimental",
"potato", "woody",
"sarge", "sarge-ignore", "etch", "etch-ignore",
"lenny", "lenny-ignore", "squeeze", "squeeze-ignore",
"wheezy", "wheezy-ignore", "jessie", "jessie-ignore",
"stretch", "stretch-ignore", "buster", "buster-ignore",
"bullseye", "bullseye-ignore","bookworm","bookworm-ignore",
"trixie","trixie-ignore","forky","forky-ignore",
);
#>>>
*valid_tags = \@gTags;
%valid_tags = map { $_ => 1 } @valid_tags;
my @valid_severities = qw(wishlist minor normal important
serious grave critical);
$ENV{HOME} = File::HomeDir->my_home;
my $cachedir
= $ENV{XDG_CACHE_HOME} || File::Spec->catdir($ENV{HOME}, '.cache');
$cachedir = File::Spec->catdir($cachedir, 'devscripts', 'bts');
my $EMAIL = checkemail($ENV{'DEBEMAIL'})
|| checkemail($ENV{'EMAIL'});
my $timestampdb = File::Spec->catfile($cachedir, 'bts_timestamps.db');
my $prunestamp = File::Spec->catfile($cachedir, 'bts_prune.timestamp');
my %timestamp;
END {
# This works even if we haven't tied it
untie %timestamp;
}
my %clonedbugs = ();
my %donebugs = ();
my %fixedbugs = ();
my %ccpackages = ();
my %ccsubmitters = ();
# Global for commands generating replies
my %reply = (to => {}, cc => {});
# Global for commands that want to submit@ new bugs.
my %submit;
# Globals for btsmail() # TODO: rename btsmail -> ctlmail.
my @ctlcmds;
my $ctlsubject = '';
# Global for 'subscribe' and 'unsubscribe' commands
my %scription;
=head1 SYNOPSIS
=head2 Send Bug Change Request
B<bts> [I<options>] I<command> [B<#>I<comment>] [B<,> I<command> [B<#>I<comment>]] ...
=over 2
=item * Bug State I<command>s:
B<done>|B<close>, B<reopen>, B<archive>, B<unarchive>.
=item * Bug Organisation I<command>s:
B<reassign>, B<clone>, B<merge>, B<forcemerge>, B<unmerge>.
=item * Metadata I<command>s:
B<retitle>, B<summary>, B<severity>,
B<forwarded>, B<notforwarded>,
B<blocked>, B<unblock>,
B<submitter>.
=item * Bug Linking I<command>s:
B<affects>.
=item * Version Tracking I<command>s:
B<found>, B<notfound>, B<fixed>, B<notfixed>.
=item * Tagging I<command>s:
B<tags>, B<user>, B<usertags>.
=item * Coordination I<command>s:
B<owner>, B<noowner>|B<disown>, B<claim>, B<unclaim>.
=item * Blast radius control I<command>s:
B<package>, B<limit>.
=back
=head2 Compose Quoted Reply With In-Line Bug Changes
B<bts reply> I<bug-no>[B<#>I<msg-no>] , I<command> [B<#>I<comment>] [I<command> [B<#>I<comment>]]...
=head2 Set Implicit Bug from MUA Message Context
B<bts context> < bug-message.eml
=head2 Read Bugs (Web or E-Mail)
B<bts show>|B<bugs> I<bug-selection>...
=head2 Prepare to Work Offline
B<bts cache>|B<cleancache> I<bug-selection>...
=head2 Manage $EMAIL Subscription
B<bts subscribe>|B<unsubscribe> I<bug-number>
=head2 Contribute to Spam Fighting
B<bts reportspam>|B<spamreport> I<bug-number>...
=head2 Scripting
=over 2
=item * List matching bug numbers:
B<bts select> I<bug-selection>...
=item * Fetch Live Bug Status:
B<bts status> I<bug-number>
=item * List bugs in local cache (for shell completion):
B<bts listcachedbugs>
=back
=head2 About bts(1)
B<bts> B<version>|B<help>
=head1 EXAMPLE
=head2 Change bugs
$ bts severity 69042 normal
$ bts merge 69042 43233
$ bts retitle 69042 This is a better bug description
=head2 Many canges at once (new implicit bug syntax)
$ bts severity 69042 normal , merge with 43233 , retitle Another title
=head2 Many canges at once (classic syntax)
$ bts severity 69042 normal , merge it 43233 , retitle it Another title
$ bts severity 69042 normal , merge -1 43233 , retitle -1 Another title
=head2 Read complete bug report discussion
$ bts show 69042 # in a browser
$ bts show --mbox 69042 # in a mailreader - all messages
=head2 List bugs
$ bts show wget # all bugs in a package
$ bts show from:$EMAIL # reported by you
=head2 Read all mails for several bugs
$ bts show --mbox # in packages maintained by you
$ bts show --mbox deb@e.mail # .. or someone else's
$ bts show --mbox src:wget # in a source package
=head2 Reply to bug
$ bts reply 43233 # reply to bug no. 43233
$ bts reply 43233 , done # .. and add pseudoheader to close
$ bts done 43233 , reply # .. other way around also works
# Quote a message
$ bts reply 43233#15 # reply to bug no. 43233 quoting message 15
$ bts reply 43233#15 , done # .. and add Control: pseudoheader to close
=head2 Reply to bug on stdin, i.e. from command-line mailreader (MUA)
$ bts reply - # reply and quote piped bug message
$ bts reply - , close #.. and close bug
$ bts severity normal , close #.. 'reply -' is implied inside supported MUA
Hint: Run from (neo)mutt <B<pipe-entry>> command ("B<|>" key).
=head2 Change bug from command-line mailreader
$ bts context , retitle 'flub: Does not nub!' , reassign flub
=head2 Subscribe $EMAIL to a bug:
$ bts subscribe 69042
=head2 List selected bugs - for scripting:
$ bugs=$(bts select src:libc6)
$ for bug in $bugs; do echo $bug needs fixing; done
=head1 DESCRIPTION
B<bts> is the command-line interface for Debian's Bug Tracking System
(BTS). It is intended for use by Debian contributors and if you're reading
this that means I<*you*>.
B<bts> helps make the many common tasks involving bugs in Debian more
convenien and enhances your workflow with offline capabilities through
local caching.
=head2 Contributing to Bugs
Debian invites I<everyone> to contribute by reporting, analyzing, replying
to and triaging bugs -- without the need for permission or so much as an
account.
A standard e-mail address (see I<$EMAIL>) and a willingness to learn and
collaborate is all that's needed to participate.
That being said we ask you to use B<bts> and the BTS in general
responsibly. Start by subscribing to packages (pts-subscribe(1)) or
particular bugs of interest to you ("bts subscribe 69042"). Try to observe
other Debian contributors' working conventions. The Debian Mentors
community <https://wiki.debian.org/DebianMentors> is happy to help if you
have questions.
You can find more on how we work at <https://wiki.debian.org/BugTriage> and
<https://wiki.debian.org/BugReport/WorkingOn>.
Mistakes happen, but consider that other busy volunteers may have to use
time they could otherwise spend fixing bugs to help you clean them up.
To learn from other people in an in-person setting you may find a Bug
Squashing Party or more general Debian Event to attend near you:
<https://wiki.debian.org/BSP>,
<https://wiki.debian.org/DebianEvents>.
=head2 Workflows
B<bts> supports reading bugs in a web- or e-mail-based worflow, but to make
changes B<bts> will always send e-mail to a BTS I<service> e-mail address
(I<service>B<@bugs.debian.org>).
The web-based workflow supports both graphical and command-line
browsers. While graphical browsers such as firefox or chromium may be
familiar, you should consider traditional command-line browsers such as
w3m(1) or lynx(1) for allowing a more focused workflow without context
switches out of your terminal.
The software running the Debian BTS, "Debbugs", has first-class support for
these browsers being from the same era of computing.
To make reading and changing bugs enjoyable a highly configurable
command-line e-mail client (MUA) such as mutt(1), neomutt(1) or aerc(1) is
recommended. By using B<bts reply> and B<bts context> together with your
MUA's pipe command you can make full use of B<bts> without so much as
leaving your MUA. WARNING: Terminal mailing can be *highly* addictive.
=head2 E-Mail Processing
Being E-Mail BTS change requests are asynchrounous and may take
considerable time to get through anti-spam measures. You should expect up
to half an hour of delay when making your first change.
You will receive an acknowledgment mail from the BTS when the changes are
accepted. You can file ACK messages into a folder for mail delivery
troubleshooting purposes (check the B<X-Debian-PR-Message:> header for
automated filtering) or suppress them using B<--no-ack> or
B<BTS_SUPPRESS_ACKS>=yes.
=head2 Sending E-Mail
To get started with B<bts> right now use B<--smtp-reportbug> to send emails
exclusively to BTS addressess without having to worry about configuration
until you need more.
Once you want to send mail directly to wider internet destinations outside
BTS mail addresses (for CC'ing people) B<bts> supports the following:
=over 2
=item * interactive command-line E-Mail clients (MUAs): B<mutt>, B<neomutt> and B<aerc> using B<--mutt>,
=item * connecting directly to an SMTP server using B<--smtp-host>,
=item * system mailer (B<sendmail> compatible) (see B<--sendmail>)
=for comment TIL history: mail is oldest, then came sendmail, then mailx.
See https://heirloom.sourceforge.net/mailx_history.html
=back
=head2 Control Commands
The commands used by B<bts> mirror Debbugs control commands but with
support for abbreviations, more relaxed syntax and helpful local validation
and cross-checking of the current bug state on the BTS server.
Debbugs control reference: <https://www.debian.org/Bugs/server-control>
B<bts> is also less strict about what constitutes a valid bug number. For
example the following are understood:
$ bts severity Bug#85942 normal
$ bts severity \#85942 normal
In the latter command a POSIX shell will interpret the hash ("#") as
starting a a comment since it's not in the middle of a shellword, so you
need to quote or escape it it as we've done here.
B<bts> allows you to abbreviate commands to the shortest unique
substring. It understands "bts cl 85942" as an alias for the "close"
command.
=head2 Control Command Comments
It is possible to add comments to BTS control commands to explain why the
changes were made:
$ bts severity 30321 normal \#Not as severe as claimed
Note that POSIX shells will remove these comments unless the hash "#"
comment character is escaped with a backslash as we've done above or quoted
with single '' or double quotes "" as below.
$ bts severity 30321 normal '# Still not all that severe'
Generally speaking it's preferred to use the B<reply> command to include
C<Control> pseudoheaders in your response to the bug report
instead. However including comments can still be useful in that context to
document what you want to achive to other contributors in complex cases.
=head2 Multiple Commands
You can send multiple commands in a single e-mail by separating them with a
period or comma, like so:
$ bts severity 95672 normal , done 96642 0.38-7 \#Fixed by fix-it.patch
It is important the commas are surrounded by whitespace so your shell
passes them to B<bts> as distinct arguments.
$ bts severity 95672 normal , merge 95672 95673 \#they are the same!
=head2 Consistency Checks
Many commands support internal and online consistency checks. For example:
=over 2
=item * B<fixed>, B<found>: complain when the record that's being made
already exists in the BTS,
=item * B<notfixed>, B<notfound>: complain when the record being removed doesn't exist,
=item * B<done>: checks whether the bug is alread marked 'done',
=item * B<archive>, B<unarchive>: check whether the bug is already/not yet archived.
=back
When multiple commands all checks must succeed before any email is sent so
you may fearlessly iterate on B<bts> commands.
Many of the checks involve fetching online information from the BTS. Use
B<--offline> to disable these. Purely B<bts> internal consistency checks
such as marking the same bug as B<done> twice cannot be bypassed this way.
=head2 The Implicit Bug
To refer to the last mentioned bug number minus one "-1" may be used. The
deprecated alias "it" is also allowed. For example you could write:
$ bts severity 95672 wishlist , retitle -1 bts: please add a foo option
Alternatively you can also omit the bug number entirely as long as the
resulting usage is unambigous, i.e. the argument(s) don't look like
bug-numbers.
$ bts done 95672 , fixed 0.1-3
Every command allows at least one keyword of
B<to>/B<by>/B<from>/B<with>/B<since>/B<email>/B<+>/B<->/B<=> (see B<COMMANDS>) to
disambiguate the meaning.
Commands that take multiple bug numbers (B<assign>/B<merge>/B<blocked>)
require the use of a keyword to omit the implicit bug argument, but it is
optional for other commands.
$ bts reopen 95672 , merge with 123456 # is equivalent to:
$ bts reopen 95672 , merge -1 123456
$ bts reopen 95672 , blocked by 123456 # is equivalent to:
$ bts reopen 95672 , blocked -1 123456
When the B<clone> command is involved the meaning of -1 can become
confusing. Below we allocate -1 as a "new ID" instead of using it to refer
to the previously mentioned bug number 95672. Consequently:
$ bts done 95672 , clone to -1 -2 # is equivalent to:
$ bts done 95672 , clone 95672 to -1 -2
and similarly
$ bts done 95672 , clone -1 -1 -2 # expands to:
$ bts done 95672 , clone 95672 -1 -2
Further, after the B<clone -1> command 'B<-1>' no longer refers to the
implicit bug number, but rather the number newly allocated by the BTS
server. You can use 'B<it>' or the keyword syntax to disambiguate.
$ bts clone 95672 to -1 -2 , done # expands to:
$ bts clone 95672 to -1 -2 , done 95672
whereas
$ bts clone 95672 to -1 -2 , done -1 # is already fully expanded.
=head1 OPTIONS
B<bts> examines the B<devscripts> configuration files as described below.
Command-line options override the configuration file settings as you'd
expect.
=over 4
=item Workflow Mode Options
See also "Workflows" in B<DESCRIPTION>.
=over 2
=item B<-o>, B<--offline>
Make B<bts> use cached bugs for the B<show> and B<bugs> commands, if a cache
is available for the requested data. See the B<cache> command, below for
information on setting up a cache.
=item B<--online>, B<--no-offline>
Opposite of B<--offline>; overrides any configuration file directive to work
offline.
=item B<-m>|B<--mail>|B<--mbox>
Use command-line e-mail workflow for reading bugs and sending change
request emails. When asked to display bugs invoke a mail reader
(B<--mailreader>, B<BTS_MAIL_READER>). When sending emails default to
composing in a command-line email client (B<--mutt>, B<BTS_MUTT_COMMAND>).
=item B<-w>|B<--web>
Use web workflow for reading bugs. Opposite of B<--mail>. When asked to
display bugs use a web-browser (I<$BROWSER> or sensible-browser(1)).
=back
=item B<-n>, B<--no-action>
Do not send emails but print them to standard output.
=item B<--cache>, B<--no-cache>
Should we attempt to cache new versions of BTS pages when
performing B<show>/B<bugs> commands? Default is to cache.
=item B<--cache-mode=>{B<min>|B<mbox>|B<full>}
When running a B<bts cache> command, should we only mirror the basic
bug (B<min>), or should we also mirror the mbox version (B<mbox>), or should
we mirror the whole thing, including the mbox and the boring
attachments to the BTS bug pages and the acknowledgement emails (B<full>)?
Default is B<min>.
=item B<--cache-delay=>I<seconds>
Time in seconds to delay between each download, to avoid hammering the BTS
web server. Default is 0 seconds.
=item B<--mailreader=>I<COMMAND>
A (shell) command invoked to read a bug mailbox.
The I<COMMAND> must contain the replacement marker "B<%s>" which is
expanded to path to an mbox file.
Default depends on mailreaders avalable on the system. See
B<BTS_MAIL_READER> config option.
=item B<--cc-addr=>I<CC_EMAIL_ADDRESS>
Send carbon copies to a list of users. I<CC_EMAIL_ADDRESS> should be a
comma-separated list of email addresses. Multiple options add more CCs.
=item B<--use-default-cc>
Add the addresses specified in the configuration file option
B<BTS_DEFAULT_CC> to the list specified using B<--cc-addr>. This is the
default.
=item B<--no-use-default-cc>
Do not add addresses specified in B<BTS_DEFAULT_CC> to the carbon copy
list.
=item B<--sendmail=>I<SENDMAILCMD>
Specify the system mailer (B<sendmail> compatible) command to use for
sending email.
The command will be split on white space and will not be passed to a shell.
Default is F</usr/sbin/sendmail>. The B<-t> option will be automatically
added if the command is F</usr/sbin/sendmail> or F</usr/sbin/exim*>. For
other mailers, if they require a B<-t> option, this must be included in the
I<SENDMAILCMD>, for example: B<--sendmail="/usr/sbin/mymailer -t">.
Conflicts with explicit B<--mutt>, B<--smtp-hots> and
B<--smtp-reportbug>. Overrides implicit B<--mutt> and B<BTS_SMTP_HOST>.
=item B<--mutt>
Use interactive command line mail client (B<BTS_MUTT_COMMAND>) for sending
of mails instead of SMTP (B<--smtp-host>) or system mailer (B<--sendmail>).
Note that one of B<$DEBEMAIL> or B<$EMAIL> must be set in the environment
in order to use B<mutt> to send emails.
If B<--mutt> is given B<--interactive> and B<--force-interactive> are
ineffective.
B<--mutt> is implied when B<bts> is invoked from inside a command-line mail
client as determined by $_ (see B<BTS_MUTT_COMMAND> for detailed logic) and
e-mail workflow is active (B<--mail>, B<BTS_WORKFLOW=mail>).
=item B<--no-mutt>
Cancel implicit or explicit B<--mutt> reverting to sending with SMTP or
system mailer instead.
=item B<--soap-timeout=>I<SECONDS>
Timeout when fetching bug status information from the BTS in B<--online>
mode.
Defaults to 5 seconds when B<--interactive> or B<--mutt> are active; 30
seconds otherwise (B<--no-interactive>).
=item B<--smtp-host=>I<SMTPHOST>
Specify an SMTP host. If given, B<bts> will send mail by talking directly to
this SMTP host rather than by invoking a B<sendmail> command.
The host name may be followed by a colon (":") and a port number in
order to use a port other than the default. It may also begin with
"ssmtp://" or "smtps://" to indicate that SMTPS should be used.
If SMTPS not specified, B<bts> will still try to use STARTTLS if it's advertised
by the SMTP host.
Note that one of B<$DEBEMAIL> or B<$EMAIL> must be set in the environment
in order to use direct SMTP connections to send emails.
Conflicts with B<--mutt> and B<--sendmail>. Overidden by B<--smtp-reportbug>.
=item B<--smtp-reportbug>
Use the the reportbug.debian.org SMTP server to send bug reports and change
requests (no account registration or authentication needed).
Equivalent to B<--smtp-host=reportbug.debian.org:587 --interactive>.
Note that reportbug.debian.org is rate limited to a small number of mails
per hour and only email destined for bugs.debian.org is
accepted. Consequently using B<--cc-addr>, B<BTS_DEFAULT_CC>, B<reply> or
B<reassign> commands will likeley cause mails to be rejected while
sending.
=item B<--smtp-username=>I<USERNAME>, B<--smtp-password=>I<PASSWORD>
Specify the credentials to use when connecting to the SMTP server specified
by B<--smtp-host>. If the server does not require authentication then
these options should not be used.
If a username is specified but not a password, B<bts> will prompt for
the password before sending the mail.
=item B<--smtp-helo=>I<HELO>
Specify the name to use in the I<HELO> command when connecting to the SMTP
server; defaults to the contents of the file F</etc/mailname>, if it
exists.
Note that some SMTP servers may reject the use of a I<HELO> which either
does not resolve or does not appear to belong to the host using it.
=item B<--bts-server>
Use a debbugs server other than the default https://bugs.debian.org.
=item B<-f>, B<--force-refresh>
Download a bug report again, even if it does not appear to have
changed since the last B<cache> command. Useful if a B<--cache-mode=full> is
requested for the first time (otherwise unchanged bug reports will not
be downloaded again, even if the boring bits have not been
downloaded).
=item B<--no-force-refresh>
Suppress any configuration file B<--force-refresh> option.
=item B<--only-new>
Download only new bugs when caching. Do not check for updates in
bugs we already have.
=item B<--include-resolved>
When caching bug reports, include those that are marked as resolved. This
is the default behaviour.
=item B<--no-include-resolved>
Reverse the behaviour of the previous option. That is, do not cache bugs
that are marked as resolved.
=item B<--no-ack>
Suppress acknowledgment mails from the BTS. Note that this will only
affect the copies of messages CCed to bugs, not those sent to the
control bot.
=item B<--ack>
Do not suppress acknowledgement mails. This is the default behaviour.
=item B<-i>, B<--interactive>
Before sending an e-mail, display the content and allow it to be edited, or
the sending cancelled.
=item B<--force-interactive>
Force interactive editing immediately. Similar to B<--interactive>, except
editor is spawned before the send/cancel/edit prompt.
=item B<--no-interactive>
Immediately send bug change request e-mails without confirmation.
This is the default behaviour except if B<--mutt> is implicitly active and
for some commands which require composing a written reply (B<done>, B<reply>).
=item B<-q>, B<--quiet>
When running B<bts cache>, only display information about newly cached
pages, not messages saying already cached. If this option is
specified twice, only output error messages (to stderr).
=item B<--no-conf>, B<--noconf>
Do not read any configuration files. This can only be used as the
first option given on the command-line.
=back
=cut
# Start by setting default values
my $offlinemode = 0;
my $caching = 1;
my $cachemode = 'min';
my $cachemode_re = '^(full|mbox|min)$';
my $refreshmode = 0;
my $updatemode = 0;
my $mboxmode = 0;
my $mailreader = '';
my $muttcmd = '';
my $sendmailcmd = '/usr/sbin/sendmail';
my $smtphost = '';
my $smtpuser = '';
my $smtppass = '';
my $smtphelo = '';
my $expertmode = 0;
my $noaction = 0;
# regexp for mailers which require a -t option
my $sendmail_t = '^/usr/sbin/sendmail$|^/usr/sbin/exim';
my $includeresolved = 1;
my $requestack = 1;
my $interactive_re = '^(force|no|yes)$';
my $interactive = 'no';
my @ccemails = ();
my @bccemails = ();
my $toolname = "";
my $btsserver = 'https://bugs.debian.org';
my $btssmtp = 'reportbug.debian.org:587';
my $use_mutt = 0;
# Next, read read configuration files and then command line
# The next stuff is boilerplate
if (@ARGV and $ARGV[0] =~ /^--no-?conf$/) {
$modified_conf_msg = " (no configuration files read)";
shift;
} else {
my @config_files = ('/etc/devscripts.conf', '~/.devscripts');
my %config_vars = (
'BTS_OFFLINE' => 'no',
'BTS_CACHE' => 'yes',
'BTS_CACHE_MODE' => 'min',
'BTS_FORCE_REFRESH' => 'no',
'BTS_ONLY_NEW' => 'no',
'BTS_WORKFLOW' => 'web',
'BTS_MAIL_READER' => 'mutt -f %s',
'BTS_MUTT_COMMAND' => 'mutt -H %s',
'BTS_SENDMAIL_COMMAND' => '/usr/sbin/sendmail',
'BTS_INCLUDE_RESOLVED' => 'yes',
'BTS_SMTP_REPORTBUG' => 'no',
'BTS_SMTP_HOST' => '',
'BTS_SMTP_AUTH_USERNAME' => '',
'BTS_SMTP_AUTH_PASSWORD' => '',
'BTS_SMTP_HELO' => '',
'BTS_SUPPRESS_ACKS' => 'no',
'BTS_INTERACTIVE' => 'no',
'BTS_DEFAULT_CC' => '',
'BTS_NONMUA_BCC' => '',
'BTS_SERVER' => $btsserver,
'BTS_EXPERT' => 'no',
);
my %config_default = %config_vars;
my $shell_cmd;
# Set defaults
foreach my $var (keys %config_vars) {
$shell_cmd .= qq[$var="$config_vars{$var}";\n];
}
$shell_cmd .= 'for file in ' . join(" ", @config_files) . "; do\n";
$shell_cmd .= '[ -f $file ] && . $file; done;' . "\n";
# Read back values
foreach my $var (keys %config_vars) { $shell_cmd .= "echo \$$var;\n" }
my $shell_out = `/bin/bash -c '$shell_cmd'`;
@config_vars{ keys %config_vars } = split /\n/, $shell_out, -1;
# Check validity # TODO: Migrate rest of vars to die instead of default.
$config_vars{'BTS_OFFLINE'} =~ /^(yes|no)$/
or $config_vars{'BTS_OFFLINE'} = 'no';
$config_vars{'BTS_CACHE'} =~ /^(yes|no)$/
or $config_vars{'BTS_CACHE'} = 'yes';
$config_vars{'BTS_CACHE_MODE'} =~ $cachemode_re
or $config_vars{'BTS_CACHE_MODE'} = 'min';
$config_vars{'BTS_FORCE_REFRESH'} =~ /^(yes|no)$/
or $config_vars{'BTS_FORCE_REFRESH'} = 'no';
$config_vars{'BTS_ONLY_NEW'} =~ /^(yes|no)$/
or $config_vars{'BTS_ONLY_NEW'} = 'no';
$config_vars{'BTS_WORKFLOW'} =~ /^(web|mail)$/
or die "$progname: BTS_WORKFLOW must be 'web' or 'mail'\n";
$config_vars{'BTS_MAIL_READER'} =~ /\%s/
or die "$progname: BTS_MAIL_READER must contain '%s'.\n";
$config_vars{'BTS_MUTT_COMMAND'} =~ /\%s/
or die "$progname: BTS_MUTT_COMMAND must contain '%s'.\n";
$config_vars{'BTS_SENDMAIL_COMMAND'} =~ /./
or $config_vars{'BTS_SENDMAIL_COMMAND'} = '/usr/sbin/sendmail';
$config_vars{'BTS_INCLUDE_RESOLVED'} =~ /^(yes|no)$/
or $config_vars{'BTS_INCLUDE_RESOLVED'} = 'yes';
$config_vars{'BTS_SUPPRESS_ACKS'} =~ /^(yes|no)$/
or $config_vars{'BTS_SUPPRESS_ACKS'} = 'no';
$config_vars{'BTS_INTERACTIVE'} =~ $interactive_re
or die "$progname: BTS_INTERACTIVE must be 'force', 'yes' or 'no'.\n";
$config_vars{'BTS_EXPERT'} =~ /^(yes|no)$/
or die "$progname: BTS_EXPERT must be 'yes' or 'no'\n";
$config_vars{'BTS_SMTP_REPORTBUG'} =~ /^(yes|no)$/
or die "$progname: BTS_SMTP_REPORTBUG=$1 must be 'yes' or 'no'!\n";
if (!length $config_vars{'BTS_SMTP_HOST'}
and $config_vars{'BTS_SENDMAIL_COMMAND'} ne '/usr/sbin/sendmail') {
my $cmd = (split ' ', $config_vars{'BTS_SENDMAIL_COMMAND'})[0];
unless ($cmd =~ /^~?[A-Za-z0-9_\-\+\.\/]*$/) {
die
"BTS_SENDMAIL_COMMAND contained funny characters: $cmd\nPlease fix the configuration file.\n";
} elsif (!find_command($cmd)) {
die
"BTS_SENDMAIL_COMMAND $cmd could not be executed.\nPlease fix the configuration file.\n";
}
}
foreach my $var (sort keys %config_vars) {
if ($config_vars{$var} ne $config_default{$var}) {
$modified_conf_msg .= " $var=$config_vars{$var}\n";
}
}
$modified_conf_msg ||= " (none)\n";
chomp $modified_conf_msg;
$offlinemode = $config_vars{'BTS_OFFLINE'} eq 'yes' ? 1 : 0;
$caching = $config_vars{'BTS_CACHE'} eq 'no' ? 0 : 1;
$cachemode = $config_vars{'BTS_CACHE_MODE'};
$refreshmode = $config_vars{'BTS_FORCE_REFRESH'} eq 'yes' ? 1 : 0;
$updatemode = $config_vars{'BTS_ONLY_NEW'} eq 'yes' ? 1 : 0;
$mboxmode = $config_vars{'BTS_WORKFLOW'} eq 'mail' ? 1 : 0;
$mailreader = $config_vars{'BTS_MAIL_READER'};
$muttcmd = $config_vars{'BTS_MUTT_COMMAND'};
$sendmailcmd = $config_vars{'BTS_SENDMAIL_COMMAND'};
$smtphost = $config_vars{'BTS_SMTP_HOST'};
$smtphost = $btssmtp if $config_vars{'BTS_SMTP_REPORTBUG'} eq 'yes';
$smtpuser = $config_vars{'BTS_SMTP_AUTH_USERNAME'};
$smtppass = $config_vars{'BTS_SMTP_AUTH_PASSWORD'};
$smtphelo = $config_vars{'BTS_SMTP_HELO'};
$includeresolved = $config_vars{'BTS_INCLUDE_RESOLVED'} eq 'yes' ? 1 : 0;
$requestack = $config_vars{'BTS_SUPPRESS_ACKS'} eq 'no' ? 1 : 0;
$interactive = $config_vars{'BTS_INTERACTIVE'};
$btsserver = $config_vars{'BTS_SERVER'};
$expertmode = $config_vars{'BTS_EXPERT'} eq 'yes' ? 1 : 0;
my $conf_cc = $config_vars{'BTS_DEFAULT_CC'};
push(@ccemails, split(/,\s*/, $conf_cc)) if $conf_cc;
my $conf_bcc = $config_vars{'BTS_NONMUA_BCC'};
push(@bccemails, split(/,\s*/, $conf_bcc)) if $conf_bcc;
}
my ($opt_help, $opt_version, $opt_noconf);
my ($opt_cachemode, $opt_mailreader, $opt_sendmail, $opt_smtphost);
my ($opt_smtpuser, $opt_smtppass, $opt_smtphelo);
my $opt_cachedelay = 0;
my ($opt_web, $opt_mail);
my $opt_mutt;
my $opt_soap_timeout;
my $quiet = 0;
my @opt_ccemails = ();
my $use_default_cc = 1;
my $ccsecurity = "";
Getopt::Long::Configure(qw(gnu_compat bundling require_order));
GetOptions(
"help|h" => \$opt_help,
"version" => \$opt_version,
"o" => \$offlinemode,
"offline!" => \$offlinemode,
"online" => sub { $offlinemode = 0; },
"cache!" => \$caching,
"cache-mode|cachemode=s" => \$opt_cachemode,
"cache-delay=i" => \$opt_cachedelay,
"m|mbox|mail" => \$opt_mail,
"w|web" => \$opt_web,
"mailreader|mail-reader=s" => \$opt_mailreader,
"cc-addr=s" => \@opt_ccemails,
"sendmail=s" => \$opt_sendmail,
"smtp-host|smtphost=s" => \$opt_smtphost,
"smtp-reportbug" =>
sub { $opt_smtphost = $btssmtp; $interactive = 'yes'; },
"smtp-user|smtp-username=s" => \$opt_smtpuser,
"smtp-pass|smtp-password=s" => \$opt_smtppass,
"smtp-helo=s" => \$opt_smtphelo,
"f" => \$refreshmode,
"force-refresh!" => \$refreshmode,
"only-new!" => \$updatemode,
"n|no-action" => \$noaction,
"q|quiet+" => \$quiet,
"noconf|no-conf" => \$opt_noconf,
"include-resolved!" => \$includeresolved,
"ack!" => \$requestack,
"i|interactive" => sub { $interactive = 'yes'; },
"no-interactive" => sub { $interactive = 'no'; },
"force-interactive" => sub { $interactive = 'force'; },
"use-default-cc!" => \$use_default_cc,
"toolname=s" => \$toolname,
"bts-server=s" => \$btsserver,
"mutt!" => \$opt_mutt,
"soap-timeout:i" => \$opt_soap_timeout,
)
or die "Usage: $progname [options]\nRun $progname --help for more details\n";
if ($opt_noconf) {
die
"$progname: --no-conf is only acceptable as the first command-line option!\n";
}
if ($opt_help) { bts_help(); exit 0; }
if ($opt_version) { bts_version(); exit 0; }
if (!$use_default_cc) {
@ccemails = ();
}
if ($opt_mail && $opt_web) {
die "$progname: --mail and --web are mutually exclusive!\n";
}
$mboxmode = 1 if $opt_mail && !$opt_web;
$mboxmode = 0 if !$opt_mail && $opt_web;
say "bts debug: Workflow is mail" if $debug and $opt_mail;
say "bts debug: Workflow is web" if $debug and $opt_web;
my $default_mua = 'mutt';
$default_mua = 'aerc' if find_command('aerc');
$default_mua = 'neomutt' if find_command('neomutt');
$default_mua = 'mutt' if find_command('mutt');
# Prefer to use MUA we're running inside of. Turns out $_ is funky magic
# not only in perl but in the shell too o_O.
# See https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-_005f
my $inside_mua = $ENV{'_'} if $ENV{'_'} =~ /(^|\/)(aerc|neomutt|mutt)$/;
$default_mua = $2 if $inside_mua;
# For testing use the following (doesn't work without env):
# $ env _=/usr/bin/mutt ./bts.pl
say "bts debug: Detected default MUA: $default_mua" if $debug;
if ($opt_mailreader) {
if ($opt_mailreader =~ /\%s/) {
$mailreader = $opt_mailreader;
} else {
warn
"$progname: ignoring invalid --mailreader option: invalid mail command following it.\n";
}
} elsif (!$mailreader) {
my $aerc_I = $inside_mua ? '-I' : '';
$mailreader = 'aerc $aerc_I mbox:%s' if $default_mua eq 'aerc';
$mailreader = 'neomutt -f %s' if $default_mua eq 'neomutt';
$mailreader = 'mutt -f %s' if $default_mua eq 'mutt';
}
if (!$muttcmd) {
# TODO: Integrate aerc, Bug#1122192.
# $muttcmd = 'aerc-muttwrapper -H %s' if $default_mua eq 'aerc';
$muttcmd = 'neomutt -H %s' if $default_mua eq 'neomutt';
$muttcmd = 'mutt -H %s' if $default_mua eq 'mutt';
}
if ($inside_mua) { # use explicit path since we have it handy
$mailreader =~ s/^\S+/$inside_mua/;
$muttcmd =~ s/^\S+/$inside_mua/;
}
say "bts debug: Inside MUA: $inside_mua" if $debug and $inside_mua;
$use_mutt = 1 if $mboxmode && $inside_mua; # TODO: Remember $sub_mail
$use_mutt = $opt_mutt if defined $opt_mutt && $opt_mutt;
$use_mutt = 0 if $opt_sendmail or $opt_smtphost;
say "bts debug: \$mailreader: $mailreader" if $debug and $use_mutt;
say "bts debug: \$muttcmd: $muttcmd" if $debug and $use_mutt;
if ($opt_soap_timeout) {
Devscripts::Debbugs::soap_timeout($opt_soap_timeout);
} elsif ($use_mutt or $interactive ne 'no') {
Devscripts::Debbugs::soap_timeout(5);
}
if ($opt_sendmail and $opt_smtphost) {
die "$progname: --sendmail and --smtp-host are mutually exclusive!\n";
} elsif ($opt_sendmail and $opt_mutt) {
die "$progname: --sendmail and --mutt mutually exclusive!\n";
} elsif ($opt_smtphost and $opt_mutt) {
die "$progname: --smtp-host and --mutt are mutually exclusive!\n";
}
$smtphost = $opt_smtphost if $opt_smtphost;
$smtpuser = $opt_smtpuser if $opt_smtpuser;
$smtppass = $opt_smtppass if $opt_smtppass;
$smtphelo = $opt_smtphelo if $opt_smtphelo;
if ($opt_sendmail) {
if ( $opt_sendmail ne '/usr/sbin/sendmail'
and $opt_sendmail ne $sendmailcmd) {
my $cmd = (split ' ', $opt_sendmail)[0];
unless ($cmd =~ /^~?[A-Za-z0-9_\-\+\.\/]*$/) {
die "--sendmail command contained funny characters: $cmd\n";
} elsif (!find_command($cmd)) {
die "--sendmail command $cmd could not be executed.\n";
}
}
}
if ($opt_sendmail) {
$sendmailcmd = $opt_sendmail;
$smtphost = ''; # overrides BTS_SMTP_HOST
} else {
if (length $smtphost and !length $smtphelo) {
if (-e "/etc/mailname") {
if (open MAILNAME, '<', "/etc/mailname") {
$smtphelo = <MAILNAME>;
chomp $smtphelo;
close MAILNAME;
} else {
warn
"Unable to open /etc/mailname: $!\nUsing default HELO for SMTP\n";
}
}
}
}
if ($opt_cachemode) {
if ($opt_cachemode =~ $cachemode_re) {
$cachemode = $opt_cachemode;
} else {
warn
"$progname: ignoring invalid --cache-mode; must be one of min, mbox, full.\n";
}
}
if ($toolname) {
$toolname = " (using $toolname)";
}
my $btsurl;
if ($btsserver =~ m%^https?://(.*)/?$%) {
$btsurl = $btsserver . '/';
$btsserver = $1;
} else {
$btsurl = "https://$btsserver/";
}
$btsurl =~ s%//$%/%;
my $btscgiurl = $btsurl . 'cgi-bin/';
if ($btsserver =~ /^debbugs\.gnu\.org/) {
$btscgiurl = $btsurl . 'cgi/';
}
my $btscgipkgurl = $btscgiurl . 'pkgreport.cgi';
my $btscgibugurl = $btscgiurl . 'bugreport.cgi';
my $btscgispamurl = $btscgiurl . 'bugspam.cgi';
my $btssubmitemail = 'submit@' . $btsserver;
my $btsctlemail = 'control@' . $btsserver;
my $packagesserver = '';
if ($btsserver =~ /^bugs(-[\w-]+)?\.debian\.org/i) {
$packagesserver = 'packages.debian.org';
$btscgispamurl =~ s|$btsurl|https://bugs-master.debian.org/|;
}
no warnings 'once';
$Devscripts::Debbugs::btsurl = $btsurl;
use warnings 'once';
if (@ARGV == 0) {
bts_help();
exit 0;
}
# Otherwise, parse the arguments
my @shortcmd;
my @args;
our @comment = ('');
my $ncommand = 0;
my $iscommand = 1;
# 'reply' command is implied for --mail workflow when launched from MUA
my $implicit_reply = $mboxmode && $inside_mua;
say "bts debug: Implicit reply active" if $debug and $implicit_reply;
if (!isatty(\*STDIN)) {
open(TTY, "+</dev/tty") or die "Cannot open /dev/tty: $!";
} else {
open(TTY, "<&STDIN") or die "Could not dup STDIN: $!";
}
# Note: To test /dev/tty failure case use $ setsid -w sh -c './bts.pl reply'
while (@ARGV) {
$_ = shift @ARGV;
if ($_ =~ /^[\.,]$/) {
next if $iscommand; # ". ." in command line - oops!
$ncommand++;
$iscommand = 1;
$comment[$ncommand] = '';
} elsif ($iscommand) {
push @shortcmd, $_;
$iscommand = 0;
} elsif ($comment[$ncommand]) {
$comment[$ncommand] .= " $_";
} elsif (/^\#/ and not /^\#\d+$/) {
$comment[$ncommand] = $_;
} else {
push @{ $args[$ncommand] }, $_;
}
}
$ncommand-- if $iscommand;
# Grub through the symbol table to find matching commands.
my @command;
our $index;
# First pass, expand (abbreviated) commands.
for $index (0 .. $ncommand) {
my $cmd = $shortcmd[$index];
if (exists $::{"bts_$cmd"}) {
$command[$index] = "bts_$cmd";
} else {
my @matches = grep /^bts_\Q$cmd\E/, keys %::;
if (@matches != 1) {
die
"$progname: Couldn't find a unique match for the command $cmd!\nRun $progname --help for a list of valid commands.\n";
}
# Replace the abbreviated command with its expanded equivalent
$command[$index] = $matches[0];
}
# Some commands cancel implicit reply
my %cancel_cmds = (
bts_reply => 1,
bts_context => 1,
bts_show => 1,
bts_bugs => 1,
bts_status => 1,
);
my $lcmd = $command[$index];
if (exists $cancel_cmds{$lcmd}) {
say "bts debug: Cancelling implicit reply due to '$lcmd" if $debug;
$implicit_reply = 0;
}
}
if ($implicit_reply) {
unshift(@shortcmd, "reply");
unshift(@command, "bts_reply");
unshift(@args, ['-']);
$ncommand++;
}
# Second pass, actually run commands.
for $index (0 .. $ncommand) {
no strict 'refs';
if ($command[$index] =~ /^#/) {
mailbts('', $shortcmd[$index]);
} else {
$command[$index]->(@{ $args[$index] });
}
}
main();
# Unnecessary, but we'll do this for clarity, only subs below.
exit 0;
=head1 COMMANDS
For full details about the commands, see the BTS documentation.
L<https://www.debian.org/Bugs/server-control>
=over 4
=item B<bugs> [I<options>] [I<bug_number> | I<package> | I<maintainer> | B<:> ] [I<opt>B<=>I<val> ...]
=item B<show> [I<options>] [I<bug number> | I<package> | I<maintainer> | B<:> ] [I<opt>B<=>I<val> ...]
=item B<bugs> [I<options>] [B<src:>I<package> | B<from:>I<submitter>] [I<opt>B<=>I<val> ...]
=item B<show> [I<options>] [B<src:>I<package> | B<from:>I<submitter>] [I<opt>B<=>I<val> ...]
=item B<bugs> [I<options>] [B<tag:>I<tag> | B<usertag:>I<tag> ] [I<opt>B<=>I<val> ...]
=item B<show> [I<options>] [B<tag:>I<tag> | B<usertag:>I<tag> ] [I<opt>B<=>I<val> ...]
=item B<bugs> [B<release-critical> | B<release-critical/>... | B<RC>]
=item B<show> [B<release-critical> | B<release-critical/>... | B<RC>]
Display selected bugs in a web browser (default or B<--web>) or in a mail
reader when B<--mbox> is given.
Options that may be specified after the B<bugs> sub-command in addition to
or instead of options at the start of the command-line are:
B<-o>/B<--offline>/B<--online>, B<-m>/B<--mbox>, B<--mailreader> and
B<-->[B<no->]B<cache>. These are described earlier in this manpage. If
either the B<-o> or B<--offline> option is used, or there is already an
up-to-date copy in the local cache, the cached version will be used.
When using B<--mbox> reading more than one bug report's mails at once using
the argument syntax described below is possible.
The meanings of the possible arguments are as follows:
=over 8
=item (none)
If nothing is specified, B<bts bugs> will display your bugs, assuming
that either B<DEBEMAIL> or B<EMAIL> (examined in that order) is set to the
appropriate email address.
=item I<bug_number>
Display bug number I<bug_number>.
=item I<package>
Display the bugs for the package I<package>.
=item B<src:>I<package>
Display the bugs for the source package I<package>.
=item I<maintainer>
Display the bugs for the maintainer email address I<maintainer>.
=item B<from:>I<submitter>
Display the bugs for the submitter email address I<submitter>.
=item B<tag:>I<tag>
Display the bugs which are tagged with I<tag>.
=item B<usertag:>I<tag>
Display the bugs which are tagged with usertag I<tag>. See the BTS
documentation for more information on usertags. This will require the
use of a B<users=>I<email> option.
=item B<:>
Details of the bug tracking system itself, along with a bug-request
page with more options than this script, can be found on
https://bugs.debian.org/. This page itself will be opened if the
command 'bts bugs :' is used.
=item B<release-critical>, B<RC>
Display the front page of the release-critical pages on the BTS. This
is a synonym for https://bugs.debian.org/release-critical/index.html.
It is also possible to say release-critical/debian/main.html and the like.
RC is a synonym for release-critical/other/all.html.
=back
After the argument specifying what to display, you can optionally
specify options to use to format the page or change what it displayed.
These are passed to the BTS in the URL downloaded. For example, pass
dist=stable to see bugs affecting the stable version of a package,
version=1.0 to see bugs affecting that version of a package, or reverse=yes
to display newest messages first in a bug log.
If caching has been enabled (that is, B<--no-cache> has not been used,
and B<BTS_CACHE> has not been set to B<no>), then any page requested by
B<bts show> will automatically be cached, and be available offline
thereafter. Pages which are automatically cached in this way will be
deleted on subsequent "B<bts show>|B<bugs>|B<cache>" invocations if they have
not been accessed in 30 days. Warning: on a filesystem mounted with
the "noatime" option, running "B<bts show>|B<bugs>" does not update the cache
files' access times; a cached bug will then be subject to auto-cleaning
30 days after its initial download, even if it has been accessed in the
meantime.
=for comment =head2 Execution of Subsequent Commands
=for comment TODO: https://salsa.debian.org/debian/sensible-utils/-/merge_requests/14
Other B<bts> commands following on the command-line will be executed after
sensible-browser has quit. With most post modern graphical browsers
(firefox, chromium) will exit immediately, but when using a terminal
browser B<bts> wait for you to quit it before continuing command execution.
The desired browser can be specified and configured by setting the
B<BROWSER> environment variable. See L<sensible-browser(1)>.
The value of B<BROWSER> may consist of a colon-separated series of
browser command parts. These should be tried in order until one
succeeds. Each command part may optionally contain the string B<%s>; if
it does, the URL to be viewed is substituted there. If a command part
does not contain B<%s>, the browser is to be launched as if the URL had
been supplied as its first argument. The string B<%%> must be substituted
as a single %.
Rationale: We need to be able to specify multiple browser commands so
programs obeying this convention can do the right thing in either X or
console environments, trying X first. Specifying multiple commands may
also be useful for people who share files like F<.profile> across
multiple systems. We need B<%s> because some popular browsers have
remote-invocation syntax that requires it. Unless B<%%> reduces to %, it
won't be possible to have a literal B<%s> in the string.
=cut
sub bts_show {
goto &bts_bugs;
}
sub bts_bugs {
@ARGV = @_; # needed for GetOptions
my ($sub_offlinemode, $sub_caching, $sub_mail, $sub_mailreader);
GetOptions(
"o" => \$sub_offlinemode,
"offline!" => \$sub_offlinemode,
"online" => sub { $sub_offlinemode = 0; },
"cache!" => \$sub_caching,
"m|mbox|mail" => \$sub_mail,
"w|web" => sub { $sub_mail = 0; },
"mailreader|mail-reader=s" => \$sub_mailreader,
) or die "$progname: unknown options for bugs command\n";
@_ = @ARGV; # whatever's left
if (defined $sub_offlinemode) {
($offlinemode, $sub_offlinemode) = ($sub_offlinemode, $offlinemode);
}
if (defined $sub_caching) {
($caching, $sub_caching) = ($sub_caching, $caching);
}
if (defined $sub_mail) {
($mboxmode, $sub_mail) = ($sub_mail, $mboxmode);
}
if (defined $sub_mailreader) {
if ($sub_mailreader =~ /\%s/) {
($mailreader, $sub_mailreader) = ($sub_mailreader, $mailreader);
} else {
warn
"$progname: ignoring invalid --mailreader $sub_mailreader option:\ninvalid mail command following it.\n";
$sub_mailreader = undef;
}
}
my $url = sanitizething(shift);
if (!$url) {
$url = $EMAIL
or die
"bts bugs: Please set DEBEMAIL or EMAIL to your Debian email address.\n";
}
if ($url =~ /^.*\s<(.*)>\s*$/) { $url = $1; }
$url =~ s/^:$//;
browse($url, @_);
# revert options
if (defined $sub_offlinemode) {
$offlinemode = $sub_offlinemode;
}
if (defined $sub_caching) {
$caching = $sub_caching;
}
if (defined $sub_mail) {
$mboxmode = $sub_mail;
}
if (defined $sub_mailreader) {
$mailreader = $sub_mailreader;
}
}
=item B<select> [I<key>B<:>I<value> ...]
Uses the SOAP interface to output a list of bugs which match the given
selection requirements.
The following keys are allowed, and may be given multiple times.
=over 8
=item B<package>
Binary package name.
=item B<source>
Source package name.
=item B<maintainer>
E-mail address of the maintainer.
=item B<submitter>
E-mail address of the submitter.
=item B<severity>
Bug severity.
=item B<status>
Completion status of the bug. One of B<open>, B<done>, or B<forwarded>.
=item B<tag>
Tags applied to the bug. If B<users> is specified, may include
usertags in addition to the standard tags.
=item B<owner>
Bug's owner.
=item B<correspondent>
Address of someone who sent mail to the log.
=item B<affects>
Bugs which affect this package.
=item B<bugs>
List of bugs to search within.
=item B<users>
Users to use when looking up usertags.
=item B<archive>
Whether to search archived bugs or normal bugs; defaults to B<0>
(i.e. only search normal bugs). As a special case, if archive is
B<both>, both archived and unarchived bugs are returned.
=back
For example, to select the set of bugs submitted by
jrandomdeveloper@example.com and tagged B<wontfix>, one would use
bts select submitter:jrandomdeveloper@example.com tag:wontfix
If a key is used multiple times then the set of bugs selected includes
those matching any of the supplied values; for example
bts select package:foo severity:wishlist severity:minor
returns all bugs of package foo with either wishlist or minor severity.
=cut
sub bts_select {
my @args = @_;
my $bugs = Devscripts::Debbugs::select(@args);
if (not defined $bugs) {
die "Error while retrieving bugs from SOAP server";
}
print map { qq($_\n) } @{$bugs};
}
=item B<status> [I<bug> | B<file:>I<file> | B<fields:>I<field>[B<,>I<field> ...] | B<verbose>] ...
Uses the SOAP interface to output status information for the given bugs
(or as read from the listed files -- use B<-> to indicate STDIN).
By default, all populated fields for a bug are displayed.
If B<verbose> is given, empty fields will also be displayed.
If B<fields> is given, only those fields will be displayed. No validity
checking is performed on any specified fields.
=cut
sub fetch_bugs_status {
my @bugs = @_;
my $status = Devscripts::Debbugs::status(map { [bug => $_] } @bugs);
if ($debug > 1) {
use Data::Dumper;
say Dumper($status);
}
$status or die 'Failed to fetch bugs status via SOAP.\n';
foreach my $bug (@bugs) {
$$status{$bug} or die 'Failed to fetch Bug#$bug status via SOAP.\n';
}
return %$status;
}
sub bts_status {
my @args = @_;
my @bugs;
my $showempty = 0;
my %field;
my @field;
for my $bug (@args) {
if (looks_like_number($bug)) {
push @bugs, $bug;
} elsif ($bug =~ m{^file:(.+)}) {
my $file = $1;
my $fh;
if ($file eq '-') {
$fh = \*STDIN;
} else {
$fh = IO::File->new($file, 'r')
or die "Unable to open $file for reading: $!";
}
while (<$fh>) {
chomp;
next if /^\s*\#/;
s/\s//g;
next unless looks_like_number($_);
push @bugs, $_;
}
} elsif ($bug =~ m{^fields:(.+)}) {
my $fields = $1;
for my $field (split /,/, $fields) {
push @field, (lc $field) unless exists $field{$field};
$field{ lc $field } = 1;
}
$showempty = 1;
} elsif ($bug =~ m{^verbose$}) {
$showempty = 1;
}
}
my $bugs
= Devscripts::Debbugs::status(map { [bug => $_, indicatesource => 1] }
@bugs);
return if ($bugs eq "");
my $first = 1;
for my $bug (keys %{$bugs}) {
print "\n" if not $first;
$first = 0;
my @keys;
if (%field) {
@keys = @field;
} else {
@keys = grep { $_ ne 'bug_num' } (sort (keys %{ $bugs->{$bug} }));
unshift @keys, 'bug_num';
}
for my $key (@keys) {
if (%field) {
next unless exists $field{$key};
}
my $out;
if (ref($bugs->{$bug}{$key}) eq 'ARRAY') {
$out .= join(',', @{ $bugs->{$bug}{$key} });
} elsif (ref($bugs->{$bug}{$key}) eq 'HASH') {
$out .= join(',',
map { $_ . ' => ' . ($bugs->{$bug}{$key}{$_} || '') }
keys %{ $bugs->{$bug}{$key} });
} else {
$out .= $bugs->{$bug}{$key} || '';
}
if ($out || $showempty) {
print "$key\t$out\n";
}
}
}
}
# Extract bug number, subject and (body) message from email stream
# (optionally mbox).
sub read_bugmail {
my $handle = shift;
my $filemsg = shift;
my $msgid = shift;
my $nomulti = 0; # 0=Find last message
# Accumulate
my $hdr;
my %m;
my %last;
# State
use constant { Mbox => 1, Headers => 2, HeaderCont => 3, Body => 4, };
my $reading = Mbox;
my $empty = 1;
my $msgidx = 0; # positive means this is a multi message mbox
$! = 0;
while (my $line = readline($handle)) {
chomp($line);
$empty = 0;
if ($reading == Mbox || ($reading == Body && $msgidx)) {
# TODO: mutt doesn't escape /^From / lines properly on save wtf?
# BTS seems fine from code tho, but should actually test it.
if ($line =~ /^From (unknown |[^ @]*@)/) { # mbox header?
$msgidx++;
say "read_bugmail: got MBOX header ($msgidx): $line"
if $debug > 1;
$reading = Mbox;
}
if ($reading == Mbox) { # Reset message state and read headers
$reading = Headers;
if (exists $m{bug} && exists $m{subject}) {
%last = %m;
}
%m = ();
next;
}
} elsif ($reading == HeaderCont) {
if ($line =~ /^[ \t]/) { # continuation line
$m{$hdr} .= $line;
} else {
$m{$hdr} =~ s/^\s+|\s+$//g; # trim spaces
$m{$hdr} =~ s/\s+/ /g; # squash spaces
$reading = Headers;
}
}
if ($reading == Body) {
$m{msg} .= "$line\n";
} elsif ($reading == Headers) {
if (
$line # Avoid automated messages: closed|they-closed|forwarded|ack|ack-info
=~ /^X-Debian-PR-Message: (?:report|followup) ([0-9]+)$/i
) {
if (exists $m{bug} && $m{bug} ne $1 && $nomulti) {
goto err_several;
}
$m{bug} = $1;
} elsif ($line =~ /^(Subject|Date|From|To|Cc):(.*)$/i) {
$hdr = lc($1);
$m{$hdr} = $2;
say "HeaderCont: $hdr: $m{$hdr}" if $debug > 1;
if (exists $m{$hdr} && $nomulti) {
die
"bts reply: Several '$1' mail headers found! Not supported yet.\n";
}
$reading = HeaderCont; # read header continuation lines
} elsif ($line
=~ /^Content-Type: *text\/plain($|;|; *charset="?(us-ascii|utf-8)"?)/i
) {
# ok.
} elsif ($line =~ /^(Content-Type:[^;]*)/i) {
# others not supported for now
say "bts reply: Skipping mail due to unsupported '$1'";
$m{msg} = $m{msg}
// ">> bts: Failed to extract message body due to unsupported '$1'";
if (exists $m{bug} && exists $m{subject}) {
%last = %m;
}
%m = ();
if ($msgidx) {
$reading = Body;
} else {
last;
}
} elsif ($line eq '') {
$reading = Body;
}
}
}
if ($!) {
warn "bts reply: WARN: unexpected error while reading $filemsg: $!\n";
}
if ($empty) {
warn "bts reply: no input, skipping\n" if $debug;
return;
}
if (!$m{bug} && %last) {
%m = %last;
}
if ($debug) {
foreach my $key ('bug', 'subject', 'from', 'date') {
say "read_bugmail: found $key: $m{$key}" if exists $m{$key};
}
}
if ($m{subject} =~ /(?:Bug#([0-9]+):)/) {
if ($m{bug} && $m{bug} ne $1 && $nomulti) {
goto err_several;
}
$m{bug} = $1;
say "read_bugmail: bug number from Subject is $1" if $debug;
}
return %m;
err_several:
die "bts reply: Several bug numbers were found!
=> $m{bug} and $2
This is not yet supported.\n";
}
sub quote_message {
my $msg = shift;
if (length($msg)) {
$msg =~ s/^\s+//;
$msg =~ s/^/> /mg;
}
return $msg;
}
=item B<reply> [I<bug> | I<bug-number>B<#>I<message-no> | B<->]
Compose a reply to a bug BTS including bug changes.
A draft is prepared, quoting I<message-no> or the latest non-automated
message taken from either 1) the I<bug-number>'s online MBOX message
archive or 2) the MBOX or single raw email message written to standard
input (B<->).
All other bug change commands given are included in the mail as
pseudoheader lines -- mostly 'B<Control:>' but more idiomatic headers
B<bts> knows about may be used instead.
A B<reply> command reading from STDIN is executed implicitly before other
commands when B<bts> is invoked from a supported MUA (see B<--mutt>). The
implicit command is cancelled when an explicit B<reply>, B<context>,
B<show>|B<bugs> or B<status> command is present.
=cut
sub bts_reply {
my %m;
my $msgno = '';
if (@_ > 0 && $_[0] eq '-') {
say "bts reply: reading bug mail from stdin" if $debug;
our $stdin_consumed;
if ($stdin_consumed) {
die
"bts reply: reading stdin is only possible once$stdin_consumed\n";
}
$stdin_consumed = " (reply command)";
%m = read_bugmail(*STDIN, 'on stdin') or return;
$_[0] = delete $m{bug}
or die
"bts reply: no X-Debian-PR-Message line or Bug# Subject found on stdin.\n";
# TODO: Initial report doesn't have PR-Message line in mbox, but
# mail delivered to Maintainer/subscribers does. Fix it on Debbugs
# archival side or add special handling here?
#
# Test:
# $ curl 'https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=123456;msg=5;mboxmaint=yes' | grep -i X-Debian
} elsif (@_ > 0 && $_[0] =~ s/([0-9])#([0-9]+)$/$1/) {
$msgno = ";msg=$2"; # additional URL parameter
}
my $bug = bugargs(\@_, 1)
or die "bts reply: reply to which bug?\n";
@_ == 0 or die "bts reply: excess arguments: @_\n";
# Nothing other than deleted $m{bug} was found?
if (!%m && !$offlinemode) { # Get message from mbox
my $mbox_handle;
my $filemsg;
if (!have_lwp()) {
die "$progname: Couldn't run bts reply: $lwp_broken\n";
}
init_agent();
if ($msgno eq '') { # download whole bug mbox
warn "Downloading Bug#$bug mails ...\n" if $debug;
download(
$bug,
'', # no urlparams
0, #=manual
1, #=mboxing
);
my $filemsg = mboxfile($bug);
open($mbox_handle, "<", $filemsg);
} else { # download single message
warn "Downloading Bug#$bug message $msgno ...\n" if $debug;
($mbox_handle, undef) = tempfile(
"bts-bug$bug-XXXXXX",
SUFFIX => ".eml",
DIR => File::Spec->tmpdir,
UNLINK => 1
);
my $thing = "$bug$msgno";
$filemsg = "$thing mbox";
my $email = download_mbox($thing);
print($mbox_handle $email);
seek($mbox_handle, 0, SEEK_SET);
}
if ($mbox_handle) {
%m = read_bugmail($mbox_handle, "in $filemsg")
or die "bts reply: reading bug mbox failed\n";
close($mbox_handle);
}
}
# Query bug status if not working offline
my $bug_status;
if (!$offlinemode) {
warn "Querying BTS for Bug#$bug status ...\n";
$bug_status = Devscripts::Debbugs::status([bug => $bug]);
if ($bug_status->{$bug}->{archived}) {
warn
"bts reply: Bug#$bug is archived, adding unarchive command.\n";
mailbts('', "unarchive $bug")
unless grep(/^unarchive $bug/, @ctlcmds);
}
}
# Deal with Subject
if (!$m{subject} && $bug_status) {
$m{subject} = $bug_status->{$bug}->{subject}
or die
"bts reply: Failed to extract bug subject from bug status object.";
$m{subject} = "Bug#$bug: $m{subject}";
}
if (length($m{subject})) {
# Keep first seen subject
$reply{subject} ||= "Re: $m{subject}";
} else {
die "bts reply: No bug Subject available.
Try --online mode to fetch it from BTS.\n";
}
exists $m{from} or die "bts reply: No From: header found!\n";
# Validation done, commit to sending
(my $eml_handle, undef) = tempfile(
"bts-reply-bug$bug-XXXXXX",
SUFFIX => ".eml",
DIR => File::Spec->tmpdir,
UNLINK => 1
);
$eml_handle or die "bts reply: \$eml_handle is undef";
# Accumulate To: header
$reply{to}->{ $m{from} } = 1;
# TODO: Support nicer greetings for people in To in complex cases, eg
#
# Dear Submitter, # just one, put it first. could fetch submitter name
# Hi $m{from}, # cumulative
# Accumulate CC: header
if ($m{cc}) {
$reply{cc}->{ $m{cc} } = 1;
}
$reply{greeting} = 1;
$reply{body} .= "On $m{date} " if exists $m{date};
$reply{body} .= "$m{from} wrote:\n";
$reply{body} .= quote_message($m{msg}) . "\n";
}
=item B<context>
Read email or MBOX from stdin to establish implicit bug context.
Similar to B<reply> but for sending plain control@ messages without
including a written rationale.
=cut
sub bts_context {
my %m;
my $msgno = '';
say "bts context: reading bug mail from stdin" if $debug;
our $stdin_consumed;
if ($stdin_consumed) {
die
"bts context: reading stdin is only possible once$stdin_consumed\n";
}
$stdin_consumed = " ('context' command)";
%m = read_bugmail(*STDIN, 'on stdin') or return;
$m{bug}
or die
"bts context: no X-Debian-PR-Message line or Bug# Subject found on stdin.\n";
$main::it = $m{bug};
}
=item B<clone> [I<bug>] [B<to>] I<new_ID> [I<new_ID> ...]
The B<clone> command duplicates a I<bug> report.
It is useful in the case where a single report actually indicates that
multiple distinct bugs have occurred. "New IDs" are negative numbers,
separated by spaces, which may be used in subsequent control commands to
refer to the newly duplicated bugs. A new report is generated for each new
ID.
=cut
sub bts_clone {
my ($bug, undef) = bugargs(\@_, 1, '^to$')
or die "bts clone: clone what bug?\n";
@_ or die "bts clone: must specify at least one new ID\n";
foreach (@_) {
$_ =~ /^-\d+$/ or die "bts clone: new IDs must be negative numbers\n";
if (exists $clonedbugs{$_}) {
die "bts clone: new ID '$_' not unique!";
}
$clonedbugs{$_} = 1;
}
mailbts("cloning $bug", "clone $bug " . join(" ", @_));
}
=item B<done> [I<bug>] [B<in>|B<by>|B<since>] [I<version>]
=item B<close> [I<bug>] [B<in>|B<by>|B<since>] [I<version>]
Indicate no further action is expected on I<bug>.
Changes I<bug>'s completion state to "done", closing it for now. Optionally
add a version tracking record that it was B<fixed> in I<version>.
The BTS will record who completed a I<bug>. You can see this in the bug
status 'done' field:
$ bts status 123456 fields:done
The B<done> command always asks you to compose a mail interactively. Please
document why the bug is being closed in your message.
While you should specify which I<version> of the package fixed the bug if
possible you can also do this later with the B<fixed> command.
Bugs which remain closed for about a month without email activity are
archived (made read-only). Use B<unarchive> to undo this.
Closed, but non-archived bugs can be reopened with the B<found> command.
=cut
sub bts_close { goto &bts_done; }
sub bts_done {
my ($bug, undef) = bugargs(\@_, 1, '^(in|by|since)$', 'otherargs')
or die "bts $shortcmd[$index]: close what bug?\n";
my $version = shift // '';
opts_done(@_);
$version !~ /\//
or die
"bts $shortcmd[$index]: version '$version' must not contain a slash '/'!";
!exists $donebugs{$bug}
or die "bts $shortcmd[$index]: Duplicate 'done' command for Bug#$bug!";
$donebugs{$bug} = $index; # for bts_fixed, fixup_done_bugs
if (length($version)) {
check_fixedbugs($bug);
$fixedbugs{$bug} = $version;
}
# Note: Manipulation of globals for mailing happens in fixup_done_bugs.
}
sub fixup_done_bugs {
%donebugs or return;
# Done mails shouldn't be sent without an explanation. Forces
# interactive editing.
#$reply{greeting} = 1;
$interactive = 'force' if !$use_mutt;
my %status;
if (!$offlinemode) {
warn "bts done: Fetching Bug status from BTS ...\n";
%status = fetch_bugs_status(keys %donebugs);
}
if (not exists $reply{done}) {
$reply{done}
.= ">> bts: Explain why you're closing these bugs here:\n";
if (%status == 0) {
$reply{done}
.= ">> Bug #" . join(", #", keys %donebugs) . " <<\n\n";
} else {
foreach my $bug (sort keys %donebugs) {
$reply{done}
.= ">> - Bug #$bug: " . $status{$bug}->{subject} . "\n";
}
$reply{done} .= "\n\n";
}
}
# One done bug can be reply to -done addess, multiple must go to
# control@ or Control: pseudoheader.
if (0 && %donebugs == 1) { # Disabled due to IRC feedback
my ($bug) = keys %donebugs;
$reply{to}->{ "$bug-done@" . $btsserver } = 1;
return;
}
foreach my $bug (keys %donebugs) {
$reply{to}->{ "$bug-submitter@" . $btsserver } = 1;
$index = $donebugs{$bug}; # very ugly global hack FIXME
my $version = $fixedbugs{$bug} // '';
mailbts("closing $bug", "close $bug $version");
}
}
=item B<reopen> [I<bug>] [I<submitter>]
(Deprecated) Record that a I<bug> previously marked B<done> should be acted
upon again by the maintainer. Optionally change I<submitter> -- unclear why
you'd want to do this here.
Clears all B<fixed> version tracking records only if I<bug> is currently
closed -- not very predictable behaviour and it is somewhat rude.
Instead prefer the more predictable B<found> command (without arguments) if
you really want to do this, but also consider the more respectful approach
documented there.
=cut
sub bts_reopen {
my $bug = bugargs(\@_, 1) or die "bts reopen: reopen what bug?\n";
my $submitter = shift || ''; # optional
opts_done(@_);
# TODO: Document = and !
# TODO: Add $submitter to CC.
# TODO: Add warning about cleared versiontracking records (from SOAP)
# TODO: SOAP Check if bug is actually marked 'done'
$expertmode
or die
"bts reopen: Deprecated (expert) command due to unpredictable behaviour.
Appeal to maintainer using 'reply' command or use more predictable 'found'
expert command instead.\n";
mailbts("reopening $bug", "reopen $bug $submitter");
}
=item B<archive> [I<bug>]
Archive a I<bug> that has previously been archived but is currently not.
The I<bug> must fulfill all of the requirements for archiving with the
exception of those that are time-based.
=cut
sub bts_archive {
my $bug = bugargs(\@_, 1) or die "bts archive: archive what bug?\n";
opts_done(@_);
mailbts("archiving $bug", "archive $bug");
}
=item B<unarchive> [I<bug>]
Unarchive a I<bug> that is currently archived.
=cut
sub bts_unarchive {
my $bug = bugargs(\@_, 1) or die "bts unarchive: unarchive what bug?\n";
opts_done(@_);
if (!$offlinemode) {
my %status = fetch_bugs_status($bug);
my %bug_status = %{ $status{$bug} };
$bug_status{archived}
or die
"bts unarchive: Bug#$bug is not archived!$onlinecheck_bypass_msg\n";
}
mailbts("unarchiving $bug", "unarchive $bug");
}
=item B<retitle> [I<bug>] I<title>
Change the I<title> of the I<bug>.
=cut
sub bts_retitle {
my $bug = bugargs(\@_, 1) or die "bts retitle: retitle what bug?\n";
my $title = join(" ", @_);
if (!length $title) {
die "bts retitle: set title of $bug to what?\n";
}
my %status = fetch_bugs_status($bug);
my %bug_status = %{ $status{$bug} };
$title =~ s/^\s+|\s+$//g; # trim spaces
if ($bug_status{subject} eq $title) {
warn "bts retitle: Bug#$bug alread has subject '$title'.\n";
} else {
mailbts("retitle $bug to $title", "retitle $bug $title");
}
}
=item B<summary> [I<bug>] [I<messagenum>]
Select a message number that should be used as
the summary of a I<bug>.
If no message number is given, the summary is cleared.
=cut
sub bts_summary {
my $bug = bugargs(\@_, 1)
or die "bts summary: change summary of what bug?\n";
my $msg = shift || '';
# TODO: Document messagenum=0, make it work nicely with bts_reply.
# TODO: Consider adding support for Message-ID on Debbugs side for mail
# workflow. Or figure out clientside way to synthesize msgnum also
# useful for 'bts reply -#123' to select a message from in an mbox
# while offline.
mailbts("summary $bug $msg", "summary $bug $msg");
}
=item B<submitter> [I<bug> ...] I<submitter-email>
Change the submitter mail address of a I<bug> or a number of bugs, with
B<!> meaning the BTS should use the mail address of the change request
e-mail message.
=cut
sub bts_submitter {
@_ or die "bts submitter: change submitter of what bug?\n";
my $submitter = checkemail(pop, 1);
if (!defined $submitter) {
die "bts submitter: change submitter to what?\n";
}
my @bugs = bugargs(\@_, 0)
or die "bts submitter: invalid bug number\n";
@bugs >= 1
or die "bts submitter: need at least one bug number\n";
foreach (@bugs) {
mailbts("submitter $_", "submitter $_ $submitter");
}
}
=item B<assign> [I<bug> ...] [B<to>] I<package>[B<,>I<package> ...] [I<version>]
=item B<reassign> [I<bug> ...] [B<to>] I<package>[B<,>I<package> ...] [I<version>]
Change the assigned I<package> set for all I<bug>s given. This indicates
all the specified bugs are presumed to need fixing in one of these
packages.
Clears all existing version tracking records (B<found> and B<fixed>) for
each I<bug>. If the optional I<version> is given a 'found' record for the
new packages is added. If the affected version is is not yet known use the
B<found> command once an analysis is avalable.
If other packages are merely receiving unactionable reports use the
B<affects> command to make the I<bug> show up in their bug listings.
If the bug is likeley to need individual fixes across several packages you
should instead B<clone> the bug and B<reassign> the clone to the other
package(s). For example:
$ bts clone 69042 to -1 , assign -1 to other-package
The command adds the maintainers of the new package to CC if B<--mutt> or
B<--force-interactive> are active.
=cut
sub bts_assign { goto &bts_reassign; }
sub bts_reassign {
my @bugs = bugargs(\@_, 0, '^to$', 'otherargs')
or die "bts reassign: reassign what bug(s)?\n";
my $package = shift
or die "bts reassign: reassign bug(s) to what package?\n";
my $version = shift // '';
if (length $version and $version !~ /\d/) {
die "bts reassign: version number $version contains no digits!\n";
}
opts_done(@_);
foreach my $bug (@bugs) {
mailbts("reassign $bug to $package",
"reassign $bug $package $version");
}
foreach my $packagename (split /,/, $package) {
$packagename =~ s/^src://;
$ccpackages{$packagename} = 1;
}
}
sub check_versiontracking {
my $bug = shift;
my $version = shift;
my $cmd = shift;
my $verb = $cmd =~ 'fixed' ? 'fixed' : 'found';
warn "check_versiontracking: $bug, $version, $cmd, $verb\n"
if $debug;
my %status = fetch_bugs_status($bug);
my %bug_status = %{ $status{$bug} };
my $done = $bug_status{done};
my $srcpkgs = split(/, /, $bug_status{source}); # can be multiple O_O
my $binpkg = $bug_status{package};
my %fixed = %{ $bug_status{$verb} or {} }; # ugh! perl! :X
#^ Note: read %fixed as fixed or found depending on $verb.
if ($debug > 1) {
use Data::Dumper;
say Dumper(\%fixed);
}
my $pkgmsg;
my $vermsg = $version;
if ($version) {
if ($version =~ /^src:/) {
die "bts $cmd: Invalid 'fixed' version record '$version'\n";
}
if ($version =~ /^([^\/]+)\/(.+)$/) {
$pkgmsg = "source package src:$1";
$vermsg = $2;
} else {
$pkgmsg = "binary package $binpkg";
}
my $is_fixed = exists $fixed{$version};
$verb =~ s/^not//;
my $msg = "bts $cmd: Bug#$bug";
my $tail = "in $pkgmsg.$onlinecheck_bypass_msg\n";
my $fixedvers = %fixed
&& "\nMaybe you meant one of these '$verb' records:\n"
. join('', map { " - " . $_ . "\n" } keys %fixed);
$cmd !~ '^not'
&& $is_fixed
&& die
"$msg is already recorded as being $verb at version '$vermsg' $tail\n";
$cmd =~ '^not'
&& !$is_fixed
&& die
"$msg has no record of being $verb at version '$vermsg' $tail$fixedvers\n";
}
return $done;
}
=item B<found> [I<bug>] [in] [I<source-package>B</>]I<version>
Add a version tracking record to indicate I<bug> was found to be present in
the given I<version> of the binary package to which I<bug> is currently
assigned or I<source-package> if given.
This implicitly changes I<bug>'s completion state to not B<done> indicating
it should be acted upon by the maintainer unless I<version> is less than
the current highest fixed version on record, see:
$ bts status 123456 fields:fixed_versions
=item B<found> [I<bug>]
(Expert) Clear all B<fixed> version tracking records in I<bug> and change
it's completion state to indicate that it is not B<done> and should be
acted upon my the maintainer -- this is somewhat rude so you better be
sure.
To be respectful consider using the B<reply> command and appeal to the
maintainer for why they should still act on the bug. You can simultaniously
use additional B<found> commands to record which I<version>s you can
demonstrate to be affected in the BTS.
=cut
sub bts_found {
my ($bug, undef) = bugargs(\@_, 1, '^in$', 'otherargs')
or die "bts found: found what bug?\n";
my $version = shift;
if (!defined $version) {
$expertmode or die "bts found: what version?\n
(Enable expert mode to allow clearing fixed_versions implicitly)\n";
# TODO: Introduce +-= for versiontracking to make CLI more
# consistent.
warn
"bts found: no version given. This will clear 'fixed' version tracking records.
Sending to the BTS anyway as your expertly highness requested.\n";
$version = "";
}
opts_done(@_);
$offlinemode or check_versiontracking($bug, $version, 'found');
mailbts("found $bug in $version", "found $bug $version");
}
=item B<notfound> [I<bug>] [B<in>] [I<source-package>B</>]I<version>
Remove a mistaken record that I<bug> is present in the given I<version> of
the binary package to which it is currently assigned or I<source-package>
if given.
Do not use this if changes were actively made in Debian to address
I<bug>. Use B<done> or B<fixed> instead as appropriate.
Version tracking records for a bug are cleared entirely by the B<reassign>
command.
=cut
sub bts_notfound {
my ($bug, undef) = bugargs(\@_, 1, '^in$', 'otherargs')
or die "bts notfound: what bug?\n";
my $version = shift
or die "bts notfound: remove record \#$bug from which version?\n";
opts_done(@_);
$offlinemode or check_versiontracking($bug, $version, 'notfound');
mailbts("notfound $bug in $version", "notfound $bug $version");
}
=item B<fixed> [I<bug>] [B<in>|B<by>|B<since>] [I<source-package>B</>]I<version>
Add a version tracking record to indicate a closed I<bug> was also fixed in
I<version> of the binary package I<bug> is currently assigned to or
I<source-package> if given.
This does not affect I<bug>'s completion state. Use the B<done> command to
indicate no further action is expected on a bug instead.
=cut
sub bts_fixed {
my ($bug, undef) = bugargs(\@_, 1, '^(in|by|since)$', 'otherargs')
or die "bts fixed: what bug?\n";
my $version = shift or die "bts fixed: Bug#$bug fixed in which version?\n";
opts_done(@_);
check_fixedbugs($bug);
if (!$offlinemode && !check_versiontracking($bug, $version, 'fixed')) {
die
"bts fixed: Bug#$bug not marked as Done yet. Use \"bts done $bug since $version\" to make it so.$onlinecheck_bypass_msg\n"
unless exists $donebugs{$bug};
}
mailbts("fixed $bug in $version", "fixed $bug $version");
$fixedbugs{$bug} = $version;
}
sub check_fixedbugs {
my $bug = shift;
!exists $fixedbugs{$bug}
or die
"bts $shortcmd[$index]: Preceeding command already marked Bug#$bug as fixed in version '$fixedbugs{$bug}'!";
}
=item B<notfixed> [I<bug>] [B<in>|B<by>|B<since>] [I<source-package>B</>]I<version>
Remove an erroniosly added version tracking record for I<bug> being fixed
in the given I<version> of the binary package to which it currently
assigned or I<source-package> if given.
This does not affect I<bug>'s completion state. Use the B<found> command to
reopen a bug that was erroniously marked B<done> and B<fixed> in
I<version>.
If the bug is not assigned to the correct package use the B<reassign>
command instead which also removes all version tracking records.
Note: B<notfixed> is equivalent to the sequence of commands "B<found>
I<bug> I<version>", "B<notfound> I<bug> I<version>".
=cut
sub bts_notfixed {
my ($bug, undef) = bugargs(\@_, 1, '^(in|by|since)$', 'otherargs')
or die "bts notfixed: what bug?\n";
my $version = shift or die "bts notfixed: which version?\n";
opts_done(@_);
check_fixedbugs($bug);
$offlinemode or check_versiontracking($bug, $version, 'notfixed');
mailbts("notfixed $bug in $version", "notfixed $bug $version");
}
=item B<block> [I<bug>] [B<by>|B<with>] I<blocker-bug> [I<blocker-bug> ...]
=item B<blocked> [I<bug>] [B<by>|B<with>] I<blocker-bug> [I<blocker-bug> ...]
Record that a I<bug> is blocked from being fixed by a set of other blocker-bugs.
=cut
sub bts_blocked {
my ($bug, undef) = bugargs(\@_, 1, '^(with|by)$')
or die "bts block: what bug is blocked?\n";
my @blockers = bugargs(\@_, 0, undef, undef, 'after with/by')
or die "bts block: $bug is blocking which other bug?\n";
@blockers >= 1
or die "bts block: need at least one blocker\n";
mailbts("block $bug with @blockers", "block $bug with @blockers");
}
=item B<unblock> [I<bug>] [B<from>|B<with>|B<by>] I<blocker-bug> [I<blocker-bug> ...]
Remove records that I<bug> is blocked from being fixed by each of the blocker bugs.
=cut
sub bts_unblock {
my ($bug, undef) = bugargs(\@_, 1, '^(from|with|by)$')
or die "bts unblock: what bug is blocked?\n";
my @blockers = bugargs(\@_, 0, undef, undef, 'after from/with/by');
@blockers >= 1
or die "bts unblock: need at least one blocker\n";
mailbts("unblock $bug with @blockers", "unblock $bug with @blockers");
}
=item B<merge> [I<bug>] [B<with>] I<bug> [I<bug> ...]
Merge a set of bugs together.
=cut
sub bts_merge {
@_ >= 1 or die "bts merge: need at least one argument\n";
my ($bug, undef) = bugargs(\@_, 1, '^with$')
or die "bts merge: which bug(s)?";
my @bugs = ($bug);
# Note: Disallow implicit expansion after 'with'
push @bugs, bugargs(\@_, 0, undef, undef, "after 'with'");
@bugs >= 2 or die "bts merge: need at least two bugs\n";
mailbts("merging @bugs", "merge @bugs");
}
=item B<forcemerge> [I<bug>] [B<with>] I<bug> [I<bug> ...]
Forcibly merge a set of bugs together. The first I<bug> listed is the
master bug, and its settings (those which must be equal in a normal
B<merge>) are assigned to the bugs listed next.
=cut
sub bts_forcemerge {
@_ >= 1 or die "bts forcemerge: need at least one argument\n";
my (@bugs, undef) = bugargs(\@_, 1, '^with$');
# Note: Disallow implicit expansion after 'with'
push @bugs, bugargs(\@_, 0, undef, undef, "after 'with' (or first bug)");
@bugs >= 2 or die "bts forcemerge: need at least two bugs\n";
mailbts("forcibly merging @bugs", "forcemerge @bugs");
}
=item B<unmerge> [I<bug>]
Unmerge a I<bug>.
=cut
sub bts_unmerge {
my $bug = bugargs(\@_, 1) or die "bts unmerge: unmerge what bug?\n";
opts_done(@_);
mailbts("unmerging $bug", "unmerge $bug");
}
=item B<tag> [I<bug>] [B<+>|B<->|B<=>] I<tag> [I<tag> ...]
=item B<tags> [I<bug>] [B<+>|B<->|B<=>] I<tag> [I<tag> ...]
Add or remove a I<tag>s on a I<bug>. The tag must be from the predefined
list of valid tags below or abbreviated to a unique substring of one.
=over 2
=item Abbreviations
Using B<fixed> will set the tag B<fixed>, not B<fixed-upstream>. However
B<fix> would not be acceptable.
=item Multiple tags
Operating on several tags in one command is possible. The B<+> or B<->
operators define whether subsequent tags are added or removed.
=item Adding and removing
The B<tag> command defaults to adding tags (B<+>) while the B<tags> command
will currently complain if none of B<+>/B<->/B<=> are specified. In a
future release (Forky+1) the 'tags' deafult operation will change to
overriding the tags set (B<=>).
At least one tag must be specified, unless the B<=> flag is used. The
command below will remove all tags from the specified I<bug>.
$ bts tags <bug> =
=item CCs
Adding or removing the B<security> tag will add "team@security.debian.org"
to the CC list of the control email.
=item Avaliable tags
The list of valid tags and their significance is available at
L<https://www.debian.org/Bugs/Developer#tags>. The current valid tags
are:
patch, wontfix, moreinfo, unreproducible, fixed, help, security, upstream,
pending, d-i, confirmed, ipv6, lfs, fixed-upstream, l10n, newcomer,
a11y, ftbfs
There is also a tag for each release of Debian since "potato". Note
that this list may be out of date, see the website for the most up to
date source.
=item Examples
# Add moreinfo tag
$ bts tag 123456 moreinfo
$ bts tag 123456 +moreinfo
$ bts tag 123456 + moreinfo
# Add fixed, remove wontfix and unreproducible tags
$ bts tag 123456 +fixed -wontfix -unreproducible
$ bts tag 123456 +fixed -wontfix unreproducible
# Clear tag list
$ bts tags 123456 =
=back
=cut
# note that the tag list is also in the @gtag variable, look for
# "potato" above.
sub bts_tags {
my ($bug, $sep) = bugargs(\@_, 1, '^(\+|-|=)$', 'otherargs')
or die "bts tags: tag what bug?\n";
$sep && unshift(@_, $sep);
if (!@_) {
die "bts tags: set what tag?\n";
}
# Parse the rest of the command line.
my $base_command = "tags $bug";
my $commands = [];
my $curop;
foreach my $tag (@_) {
if ($tag =~ s/^([-+=])//) {
my $op = $1;
if ($op eq '=') {
$curop = '=';
$commands = [];
$ccsecurity = '';
} elsif (!$curop || $curop ne $op) {
$curop = $op;
}
next unless $tag;
}
if (!$curop) {
$curop = '+';
if ($command[$index] eq 'tags') {
die
"bts tags: Defaulted + not allowed for 'tags' command anymore (since Forky). Use 'tag' command or explicit '+' instead.\n";
# TODO Forky+1: Default to =.
}
}
if (!exists $valid_tags{$tag}) {
# Try prefixes
my @matches = grep /^\Q$tag\E/, @valid_tags;
if (@matches != 1) {
die "bts tags: \"$tag\" is not a "
. (@matches > 1 ? "unique" : "valid")
. " tag prefix. Choose from: "
. join(" ", @valid_tags) . "\n";
}
$tag = $matches[0];
}
if (!@$commands || $curop ne $commands->[-1]{op}) {
push(@$commands, { op => $curop, tags => [] });
}
push(@{ $commands->[-1]{tags} }, $tag);
if ($tag eq "security") {
$ccsecurity = "team\@security.debian.org";
}
}
my $cmd = '';
foreach my $cmd (@$commands) {
if ($cmd->{op} ne '=' && !@{ $cmd->{tags} }) {
die "bts tags: set what tag?\n";
}
$cmd .= " $cmd->{op} " . join(' ', @{ $cmd->{tags} });
}
if (!$cmd && $curop eq '=') {
$cmd = " $curop";
}
if ($cmd) {
mailbts("tagging $bug", $base_command . $cmd);
}
}
=item B<affects> [I<bug>] [B<+>|B<->|B<=>] I<package> [I<package> ...]
Record that a I<bug> affects a I<package> other than the bug's assigned
package.
The given I<bug> will be listed in the affected I<package>'s bug list.
This should generally be used where the I<bug> is severe enough to cause
multiple reports from users to be assigned to the wrong package. At least
one I<package> must be specified, unless the B<=> flag is used. The command
$ bts affects <bug> =
will remove all indications that I<bug> affects other packages.
=cut
# TODO: Does Debbugs support "affects + foo - bar" like for "tags"?
sub bts_affects {
my ($bug, $sep) = bugargs(\@_, 1, '^(\+|-|=)$', 'otherargs')
or die "bts affects: mark what bug as affecting another package?\n";
$sep && unshift(@_, $sep);
@_ or die "bts affects: mark which package as affected?\n";
# Parse the rest of the command line.
my $cmd = "affects $bug";
my $flag = "";
if ($_[0] =~ /^[-+=]$/) {
$flag = $_[0];
$cmd .= " $flag";
shift;
} elsif ($_[0] =~ s/^([-+=])//) {
$flag = $1;
$cmd .= " $flag";
}
if ($flag ne '=' && !@_) {
die "bts affects: mark which package as affected?\n";
}
foreach my $package (@_) {
$cmd .= " $package";
}
mailbts("affects $bug", $cmd);
}
=item B<user> I<email>
Specify a user I<email> address before using the B<usertags> command.
=cut
sub bts_user {
my $email = checkemail(shift)
or die "bts user: set user to what email address?\n";
if (!length $email) {
die "bts user: set user to what email address?\n";
}
opts_done(@_);
if ($email ne $last_user) {
mailbts("user $email", "user $email");
}
$last_user = $email;
}
=item B<usertag> [I<bug>] [B<+>|B<->|B<=>] [I<freeform-tag> ...]
=item B<usertags> [I<bug>] [B<+>|B<->|B<=>] [I<freeform-tag> ...]
Mirrors B<tags> command, but with freeform tags namespaced by preceeding
B<user> command or $EMAIL/$DEBEMAIL (in that order) from the enviornment.
Add or remove freeform "usertags" on a I<bug>. The name of I<freeform-tag>s
must be exact, there is no pre-defined list of valid tag names unlike with
the B<tags> command.
See B<tags> command for detailed usage. TODO: check usage is exactly the
same regarding '+moreinfo' vs '+ moreinfo'.
=cut
sub bts_usertags {
my ($bug, $sep) = bugargs(\@_, 1, '^(\+|-|=)$', 'otherargs')
or die "bts usertags: tag what bug?\n";
$sep && unshift(@_, $sep);
if (!@_) {
die "bts usertags: set what user tag?\n";
}
# Parse the rest of the command line.
# TODO: Common up with bts_tags() logic?
my $cmd = "usertags $bug";
my $flag = "";
if ($_[0] =~ /^[-+=]$/) {
$flag = $_[0];
$cmd .= " $flag";
shift;
} elsif ($_[0] =~ s/^([-+=])//) {
$flag = $1;
$cmd .= " $flag";
}
if (!$flag) {
$flag = '=';
if ($command[$index] eq 'usertags') {
die
"bts usertags: Defaulted + not allowed for 'usertags' command anymore (since Forky). Use 'usertag' command or explicit '+' instead .\n";
# TODO Forky+1: Default to =.
}
}
if ($flag ne '=' && !@_) {
die "bts usertags: set what user tag?\n";
}
$cmd .= sprintf(' %s', join(' ', @_));
mailbts("usertagging $bug", $cmd);
}
=item B<claim> [I<bug>] [for] [I<claim>]
Record that you have claimed a I<bug> (e.g. for a bug squashing party).
I<claim> should be a unique token allowing the bugs you have claimed
to be identified; an e-mail address is often used.
If no I<claim> is specified, the environment variable B<DEBEMAIL>
or B<EMAIL> (checked in that order) is used.
See L<https://lists.debian.org/msgid-search/20050908170731.GA20584@cyan.localnet>.
=cut
sub bts_claim {
my ($bug, $sep) = bugargs(\@_, 1, '^for$')
or die "bts claim: claim what bug?\n";
$sep && $sep ne 'for' && unshift(@_, $sep);
my $claim = shift || $EMAIL || "";
checkemail($claim)
or die "bts claim: claim '$claim' must be a valid email address!\n";
if (!length($claim)) {
die "bts claim: use what claim token?\n";
}
opts_done(@_);
$claim = extractemail($claim);
bts_user("bugsquash\@qa.debian.org");
bts_usertags("$bug", "+$claim");
}
=item B<unclaim> [I<bug>] [B<for>] [I<claim>]
Remove the record that you have claimed a bug.
If no I<claim> is specified, the environment variable B<DEBEMAIL>
or B<EMAIL> (checked in that order) is used.
=cut
sub bts_unclaim {
my ($bug, $sep) = bugargs(\@_, 1, '^for$')
or die "bts unclaim: unclaim what bug?\n";
$sep && $sep ne 'for' && unshift(@_, $sep);
my $claim = shift || $EMAIL || "";
checkemail($claim)
or die "bts claim: claim '$claim' must be a valid email address!\n";
if (!length $claim) {
die "bts unclaim: use what claim token?\n";
}
opts_done(@_);
$claim = extractemail($claim);
bts_user("bugsquash\@qa.debian.org");
bts_usertags("$bug", "-$claim");
}
=item B<severity> [I<bug>] I<severity>
Change the I<severity> of a I<bug>. Available severities are: B<wishlist>, B<minor>, B<normal>,
B<important>, B<serious>, B<grave>, B<critical>. The severity may be abbreviated to any
unique substring.
=cut
sub bts_severity {
my $bug = bugargs(\@_, 1)
or die "bts severity: change the severity of what bug?\n";
my $severity = lc(shift // '')
or die "bts severity: set \#$bug\'s severity to what?\n";
my @matches = grep /^\Q$severity\E/i, @valid_severities;
if (@matches != 1) {
die
"bts severity: \"$severity\" is not a valid severity.\nChoose from: @valid_severities\n";
}
opts_done(@_);
mailbts("severity of $bug is $matches[0]", "severity $bug $matches[0]");
}
=item B<forwarded> [I<bug>] I<address>
Mark the I<bug> as forwarded to the given I<address> (usually an email address or
a URL for an upstream bug tracker).
=cut
sub bts_forwarded {
my $bug = bugargs(\@_, 1)
or die "bts forwarded: mark what bug as forwarded?\n";
my $email = join(' ', @_);
if ($email =~ /$btsserver/) {
die
"bts forwarded: We don't forward bugs within $btsserver, use bts reassign instead\n";
}
if (!length $email) {
die
"bts forwarded: mark bug $bug as forwarded to what email address?\n";
}
mailbts("bug $bug is forwarded to $email", "forwarded $bug $email");
}
=item B<notforwarded> [I<bug>]
Mark a I<bug> as not forwarded.
=cut
sub bts_notforwarded {
my $bug = bugargs(\@_, 1) or die "bts notforwarded: what bug?\n";
opts_done(@_);
mailbts("bug $bug is not forwarded", "notforwarded $bug");
}
=item B<package> [I<package> ...]
The following commands will only apply to bugs against the listed
I<package>s; this acts as a safety mechanism for the BTS. If no packages
are listed, this check is turned off again.
=cut
sub bts_package {
if (@_) {
bts_limit(map { "package:$_" } @_);
} else {
bts_limit('package');
}
}
=item B<limit> [I<key>[B<:>I<value>]] ...
The following commands will only apply to bugs which meet the specified
criterion; this acts as a safety mechanism for the BTS. If no I<value>s are
listed, the limits for that I<key> are turned off again. If no I<key>s are
specified, all limits are reset.
=over 8
=item B<submitter>
E-mail address of the submitter.
=item B<date>
Date the bug was submitted.
=item B<subject>
Subject of the bug.
=item B<msgid>
Message-id of the initial bug report.
=item B<package>
Binary package name.
=item B<source>
Source package name.
=item B<tag>
Tags applied to the bug.
=item B<severity>
Bug severity.
=item B<owner>
Bug's owner.
=item B<affects>
Bugs affecting this package.
=item B<archive>
Whether to search archived bugs or normal bugs; defaults to B<0>
(i.e. only search normal bugs). As a special case, if archive is
B<both>, both archived and unarchived bugs are returned.
=back
For example, to limit the set of bugs affected by the subsequent control
commands to those submitted by jrandomdeveloper@example.com and tagged
B<wontfix>, one would use
bts limit submitter:jrandomdeveloper@example.com tag:wontfix
If a key is used multiple times then the set of bugs selected includes
those matching any of the supplied values; for example
bts limit package:foo severity:wishlist severity:minor
only applies the subsequent control commands to bugs of package foo with
either B<wishlist> or B<minor> severity.
=cut
sub bts_limit {
my @args = @_;
my %limits;
# Ensure we're using the limit fields that debbugs expects. These are the
# keys from Debbugs::Status::fields
my %valid_keys = (
submitter => 'originator',
date => 'date',
subject => 'subject',
msgid => 'msgid',
package => 'package',
source => 'source',
src => 'source',
tag => 'keywords',
severity => 'severity',
owner => 'owner',
affects => 'affects',
archive => 'unarchived',
);
for my $arg (@args) {
my ($key, $value) = split /:/, $arg, 2;
next unless $key;
if (!defined $value) {
die "bts limit: No value given for '$key'\n";
}
if (exists $valid_keys{$key}) {
# Support "$key:" by making it look like "$key", i.e. no $value
# defined
undef $value unless length($value);
if ($key eq "archive") {
if (defined $value) {
# limit looks for unarchived, not archive. Verify we have
# a valid value and then switch the boolean value to match
# archive => unarchive
if ($value =~ /^yes|1|true|on$/i) {
$value = 0;
} elsif ($value =~ /^no|0|false|off$/i) {
$value = 1;
} elsif ($value ne 'both') {
die "bts limit: Invalid value ($value) for archive\n";
}
}
}
$key = $valid_keys{$key};
if (defined $value and $value) {
push(@{ $limits{$key} }, $value);
} else {
$limits{$key} = ();
}
} elsif ($key eq 'clear') {
%limits = ();
$limits{$key} = 1;
} else {
die "bts limit: Unrecognized key: $key\n";
}
}
for my $key (keys %limits) {
if ($key eq 'clear') {
mailbts('clear all limit(s)', 'limit clear');
next;
}
if (defined $limits{$key}) {
my $value = join ' ', @{ $limits{$key} };
mailbts("limit $key to $value", "limit $key $value");
} else {
mailbts("clear $key limit", "limit $key");
}
}
}
=item B<owner> [I<bug>] I<owner-email>
Change the "owner" address of a I<bug>, with B<!> meaning
"use the address on the current email as the new owner address".
The owner of a bug accepts responsibility for dealing with it.
=cut
sub bts_owner {
my $bug = bugargs(\@_, 1) or die "bts owner: change owner of what bug?\n";
my $owner = checkemail(shift, 1)
or die "bts owner: change owner to what?\n";
opts_done(@_);
mailbts("owner $bug", "owner $bug $owner");
}
=item B<noowner> [I<bug>]
=item B<disown> [I<bug>]
Mark a bug as having no "owner".
=cut
sub bts_disown { goto &bts_noowner }
sub bts_noowner {
my $bug = bugargs(\@_, 1) or die "bts noowner: what bug?\n";
opts_done(@_);
mailbts("bug $bug has no owner", "noowner $bug");
}
=item B<subscribe> [I<bug>] [B<email>] [I<email>]
Subscribe the given I<email> address to the specified I<bug> reports.
If no email address is specified, the environment variable B<DEBEMAIL> or
B<EMAIL> (in that order) is used. If those are not set, or B<!> is given
as email address, your mail system will determine the address used.
After executing this command, you will be sent a subscription confirmation to
which you have to reply. When subscribed to a bug report, you receive all
relevant emails and notifications.
Use the B<unsubscribe> command to undo the subscription.
=cut
sub bts_subscribe {
my @bugs = bugargs(\@_, 0, '^(email)$', 'otherargs')
or die "bts subscribe: subscribe to what bugs?\n";
my $email = checkemail(shift, 1);
opts_done(@_);
$scription{$_} = ['sub', $email] foreach @bugs;
}
=item B<unsubscribe> [I<bug> ...] [B<email>] [I<email>]
Unsubscribe the given email address from the specified I<bug> reports.
As with subscribe above, if no email address is specified, the environment
variables B<DEBEMAIL> or B<EMAIL> (in that order) is used. If those are
not set, or B<!> is given as email address, your mail system will determine
the address used.
You will receive an unsubscription confirmation to which you need to reply
for the unsubscription to be effectiv.
Currently there is no self-service mechanism to list all your subscriptions
or to unsubscribe from all bugs. Contact the Debian Listmaster Team
<https://wiki.debian.org/Teams/ListMaster> who are responsible for the bug
subscription infrastructure.
=cut
sub bts_unsubscribe {
my @bugs = bugargs(\@_, 0, '^(email)$', 'otherargs')
or die "bts unsubscribe: unsubscribe from what bugs?\n";
my $email = checkemail(shift, 1);
$email = lc($email) if defined $email;
opts_done(@_);
$scription{$_} = ['unsub', $email] foreach @bugs;
}
=item B<spamreport> [I<bug>] ...
=item B<reportspam> [I<bug>] ...
Record that I<bug> constains SPAM messages. A Debian contributor will
review the bug log and remove the offending message(s).
=cut
sub bts_spamreport { goto &bts_reportspam; }
sub bts_reportspam {
my @bugs = bugargs(\@_, 0)
or die "bts reportspam: invalid bug number\n";
@bugs >= 1
or die "bts reportspam: need at least one bug number\n";
if (!have_lwp()) {
die "$progname: Couldn't run bts reportspam: $lwp_broken\n";
}
init_agent() unless $ua;
foreach my $bug (@bugs) {
my $url = "$btscgispamurl?bug=$bug;ok=ok";
if ($noaction) {
print "bts reportspam: would report $bug as containing spam (URL: "
. $url . ")\n";
} else {
my $request = HTTP::Request->new('GET', $url);
my $response = $ua->request($request);
if (!$response->is_success) {
warn "$progname: failed to report $bug as containing spam: "
. $response->status_line . "\n";
}
}
}
}
=item B<cache> [I<options>] [I<maint_email> | I<pkg> | B<src:>I<pkg> | B<from:>I<submitter>]
=item B<cache> [I<options>] [B<release-critical> | B<release-critical/>... | B<RC>]
Generate or update a cache of bug reports for the given email address
or package. By default it downloads all bugs belonging to the email
address in the B<DEBEMAIL> environment variable (or the B<EMAIL> environment
variable if B<DEBEMAIL> is unset). This command may be repeated to cache
bugs belonging to several people or packages. If multiple packages or
addresses are supplied, bugs belonging to any of the arguments will be
cached; those belonging to more than one of the arguments will only be
downloaded once. The cached bugs are stored in
F<$XDG_CACHE_HOME/devscripts/bts/> or, if B<XDG_CACHE_HOME> is not set, in
F<~/.cache/devscripts/bts/>.
You can use the cached bugs with the B<-o> switch. For example:
bts -o bugs
bts -o show 12345
Also, B<bts> will update the files in it in a piecemeal fashion as it
downloads information from the BTS using the B<show> command. You might
thus set up the cache, and update the whole thing once a week, while
letting the automatic cache updates update the bugs you frequently
refer to during the week.
Some options affect the behaviour of the B<cache> command. The first is
the setting of B<--cache-mode>, which controls how much B<bts> downloads
of the referenced links from the bug page, including boring bits such
as the acknowledgement emails, emails to the control bot, and the mbox
version of the bug report. It can take three values: B<min> (the
minimum), B<mbox> (download the minimum plus the mbox version of the bug
report) or B<full> (the whole works). The second is B<--force-refresh> or
B<-f>, which forces the download, even if the cached bug report is
up-to-date. The B<--include-resolved> option indicates whether bug
reports marked as resolved should be downloaded during caching.
Each of these is configurable from the configuration
file, as described below. They may also be specified after the
B<cache> command as well as at the start of the command-line.
Finally, B<-q> or B<--quiet> will suppress messages about caches being
up-to-date, and giving the option twice will suppress all cache
messages (except for error messages).
Beware of caching RC, though: it will take a LONG time! (With 1000+
RC bugs and a delay of 5 seconds between bugs, you're looking at a
minimum of 1.5 hours, and probably significantly more than that.)
=cut
sub bts_cache {
@ARGV = @_;
my ($sub_cachemode, $sub_refreshmode, $sub_updatemode);
my $sub_quiet = $quiet;
my $sub_includeresolved = $includeresolved;
GetOptions(
"cache-mode|cachemode=s" => \$sub_cachemode,
"f" => \$sub_refreshmode,
"force-refresh!" => \$sub_refreshmode,
"only-new!" => \$sub_updatemode,
"q|quiet+" => \$sub_quiet,
"include-resolved!" => \$sub_includeresolved,
) or die "$progname: unknown options for cache command\n";
@_ = @ARGV; # whatever's left
if (defined $sub_refreshmode) {
($refreshmode, $sub_refreshmode) = ($sub_refreshmode, $refreshmode);
}
if (defined $sub_updatemode) {
($updatemode, $sub_updatemode) = ($sub_updatemode, $updatemode);
}
if (defined $sub_cachemode) {
if ($sub_cachemode =~ $cachemode_re) {
($cachemode, $sub_cachemode) = ($sub_cachemode, $cachemode);
} else {
warn
"$progname: ignoring invalid --cache-mode $sub_cachemode;\nmust be one of min, mbox, full.\n";
}
}
# This may be a no-op, we don't mind
($quiet, $sub_quiet) = ($sub_quiet, $quiet);
($includeresolved, $sub_includeresolved)
= ($sub_includeresolved, $includeresolved);
prunecache();
if (!have_lwp()) {
die "$progname: Couldn't run bts cache: $lwp_broken\n";
}
if (!-d $cachedir) {
my $err;
make_path($cachedir, { error => \$err });
if (@$err) {
my ($path, $msg) = each(%{ $err->[0] });
die "$progname: couldn't mkdir $path: $msg\n";
}
}
download("css/bugs.css");
my $tocache;
if (@_ > 0) { $tocache = sanitizething(shift); }
else { $tocache = ''; }
if (!length $tocache) {
$tocache = $EMAIL || '';
if ($tocache =~ /^.*\s<(.*)>\s*$/) { $tocache = $1; }
}
if (!length $tocache) {
die "bts cache: cache what?\n";
}
my $sub_thgopts = '';
$sub_thgopts = ';pend-exc=done'
if (!$includeresolved && $tocache !~ /^release-critical/);
my %bugs = ();
my %oldbugs = ();
do {
%oldbugs = (%oldbugs,
map { $_ => 1 } bugs_from_thing($tocache, $sub_thgopts));
# download index
download($tocache, $sub_thgopts, 1);
%bugs
= (%bugs, map { $_ => 1 } bugs_from_thing($tocache, $sub_thgopts));
$tocache = sanitizething(shift);
} while (defined $tocache);
# remove old bugs from cache
if (keys %oldbugs) {
tie(%timestamp, "Devscripts::DB_File_Lock", $timestampdb,
O_RDWR() | O_CREAT(),
0600, $DB_HASH, "write")
or die
"$progname: couldn't open DB file $timestampdb for writing: $!\n"
if !tied %timestamp;
}
foreach my $bug (keys %oldbugs) {
if (!$bugs{$bug}) {
deletecache($bug);
}
}
untie %timestamp;
# download bugs
my $bugcount = 1;
my $bugtotal = scalar keys %bugs;
foreach my $bug (keys %bugs) {
if (-f cachefile($bug, '') and $updatemode) {
print "Skipping $bug as requested ... $bugcount/$bugtotal\n"
if !$quiet;
$bugcount++;
next;
}
download($bug, '', 1, 0, $bugcount, $bugtotal);
sleep $opt_cachedelay;
$bugcount++;
}
# revert options
if (defined $sub_refreshmode) {
$refreshmode = $sub_refreshmode;
}
if (defined $sub_updatemode) {
$updatemode = $sub_updatemode;
}
if (defined $sub_cachemode) {
$cachemode = $sub_cachemode;
}
$quiet = $sub_quiet;
$includeresolved = $sub_includeresolved;
}
=item B<cleancache> I<package> | B<src:>I<package> | I<maintainer>
=item B<cleancache from:>I<submitter> | B<tag:>I<tag> | B<usertag:>I<tag> | I<number> | B<ALL>
Clean the cache for the specified I<package>, I<maintainer>, etc., as
described above for the B<bugs> command, or clean the entire cache if
B<ALL> is specified. This is useful if you are going to have permanent
network access or if the database has become corrupted for some
reason. Note that for safety, this command does not default to the
value of B<DEBEMAIL> or B<EMAIL>.
=cut
sub bts_cleancache {
prunecache();
my $toclean = sanitizething(shift);
if (!defined $toclean) {
die "bts cleancache: clean what?\n";
}
if (!-d $cachedir) {
return;
}
if ($toclean eq 'ALL') {
if (system("/bin/rm", "-rf", $cachedir) >> 8 != 0) {
warn "Problems cleaning cache: $!\n";
}
return;
}
# clean index
tie(%timestamp, "Devscripts::DB_File_Lock", $timestampdb,
O_RDWR() | O_CREAT(),
0600, $DB_HASH, "write")
or die "$progname: couldn't open DB file $timestampdb for writing: $!\n"
if !tied %timestamp;
if ($toclean =~ /^\d+$/) {
# single bug only
deletecache($toclean);
} else {
my @bugs_to_clean = bugs_from_thing($toclean);
deletecache($toclean);
# remove old bugs from cache
foreach my $bug (@bugs_to_clean) {
deletecache($bug);
}
}
untie %timestamp;
}
=item B<listcachedbugs> [I<number>]
List cached bug ids (intended to support bash completion). The optional number argument
restricts the list to those bug ids that start with that number.
=cut
sub bts_listcachedbugs {
my $number = shift;
if (not defined $number) {
$number = '';
}
if ($number =~ m{\D}) {
return;
}
my $untie = 0;
if (not tied %timestamp) {
tie(%timestamp, "Devscripts::DB_File_Lock", $timestampdb,
O_RDONLY(), 0600, $DB_HASH, "read")
or die
"$progname: couldn't open DB file $timestampdb for reading: $!\n";
$untie = 1;
}
print join "\n", grep { $_ =~ m{^$number\d+$} } sort keys %timestamp;
print "\n";
if ($untie) {
untie %timestamp;
}
}
# Add any new commands here.
=item B<version>
Display version and copyright information.
=cut
sub bts_version {
print <<"EOF";
$progname version $version
Copyright (C) 2001-2003 by Joey Hess <joeyh\@debian.org>.
Modifications Copyright (C) 2002-2004 by Julian Gilbey <jdg\@debian.org>.
Modifications Copyright (C) 2007 by Josh Triplett <josh\@freedesktop.org>.
It is licensed under the terms of the GPL, either version 2 of the
License, or (at your option) any later version.
EOF
}
=item B<help>
Display a short summary of commands, suspiciously similar to parts of this
man page.
=cut
# Other supporting subs
# This must be the last bts_* sub
sub bts_help {
my $inlist = 0;
my $insublist = 0;
print <<"EOF";
Usage: $progname [options] command [args] [\#comment] [.|, command ... ]
Valid options are:
-o, --offline Do not attempt to connect to BTS for show/bug
commands: use cached copy
--online, --no-offline Attempt to connect (default)
-n, --no-action Do not send emails but print them to standard output.
--no-cache Do not attempt to cache new versions of BTS
pages when performing show/bug commands
--cache Do attempt to cache new versions of BTS
pages when performing show/bug commands (default)
--cache-mode={min|mbox|full}
How much to cache when we are caching: the sensible
bare minimum (default), the mbox as well, or
everything?
--cache-delay=seconds Time to sleep between each download when caching.
-m, --mail, --mbox With show or bugs, open a mailreader to read the mbox
version instead
-w, --web Opposite of --mail, open bugs in a web-browser.
--mailreader=CMD Run CMD to read an mbox; default is 'mutt -f %s'
(must contain %s, which is replaced by mbox name)
--cc-addr=CC_EMAIL_ADDRESS
Send carbon copies to a list of users.
CC_EMAIL_ADDRESS should be a comma-separated list of
e-mail addresses. Multiple options add more CCs.
--use-default-cc Send carbon copies to any addresses specified in the
configuration file BTS_DEFAULT_CC (default)
--no-use-default-cc Do not do so
--sendmail=cmd Sendmail command to use (default /usr/sbin/sendmail)
--mutt Use mutt for sending of mails.
--no-mutt Do not use mutt for sending mail
--smtp-host=host SMTP host to use
--smtp-username=user } Credentials to use when connecting to an SMTP
--smtp-password=pass } server which requires authentication
--smtp-helo=helo HELO to use when connecting to the SMTP server;
(defaults to the content of /etc/mailname)
--bts-server The name of the debbugs server to use
(default https://bugs.debian.org)
-f, --force-refresh Reload all bug reports being cached, even unchanged
ones
--no-force-refresh Do not do so (default)
--only-new Download only new bugs when caching. Do not check
for updates in bugs we already have.
--include-resolved Cache bugs marked as resolved (default)
--no-include-resolved Do not cache bugs marked as resolved
--no-ack Suppress BTS acknowledgment mails
--ack Do not do so (default)
-i, --interactive Prompt for confirmation before sending e-mail.
--force-interactive Force interactive editing immediately. Similar to
--interactive, except editor is spawned before prompt.
--no-interactive Send e-mail immediately, without prompt (default).
-q, --quiet Only display information about newly cached pages.
If given twice, only display error messages.
--no-conf, --noconf Do not read devscripts config files;
must be the first option given
-h, --help Display this message
-v, --version Display version and copyright info
Valid commands are:
EOF
my $pod = '';
seek DATA, 0, 0;
while (<DATA>) {
$inlist = 1 if /^=over 4/;
next unless $inlist;
$insublist = 1 if /^=over [^4]/;
$insublist = 0 if /^=back/;
if (/^=item\sB<([^->].*)>/ and !$insublist) {
if ($1 eq 'help') {
last;
}
$pod .= $_ . "\n";
}
}
# Strip POD markup before displaying and ensure we don't wrap
# longer lines
my $parser = Pod::BTS->new(width => 100);
$parser->no_whining(1);
$parser->output_fh(\*STDOUT);
$parser->parse_string_document($pod);
print <<"EOF";
Settings modified from defaults by devscripts configuration files:g
$modified_conf_msg
EOF
}
# Strips any leading # or Bug# and trailing : from a thing if what's left is
# a pure positive number;
# also RC is a synonym for release-critical/other/all.html
sub sanitizething {
my $bug = $_[0];
defined $bug or return undef;
return 'release-critical/other/all.html' if $bug eq 'RC';
return 'release-critical/index.html' if $bug eq 'release-critical';
$bug =~ s/^(?:(?:Bug)?\#)?(\d+):?$/$1/;
return $bug;
}
# Perform basic validation of an argument which should be an email address,
# handling ! if allowed
sub checkemail {
my $email = $_[0] or return;
my $allowbang = $_[1];
if ($email !~ /\@/ && (!$allowbang || $email ne '!')) {
return;
}
return $email;
}
# bugargs($@args, $max_bugs, $sep_re, $quiet, $disallow_implicit_msg);
# Remove up to $max_bugs arguments looking like bug numbers from $args
# array reference, stopping at arg matching $sep_re.
#
# Implicit bug ($it):
#
# Expansion happens if $@args are empty, $sep_re appears as first arg,
# '-1' or 'it' are given. If $disallow_implicit_msg is trueish die
# instead.
#
# Notes:
#
# - Strips out extraneous leading junk, allowing for things like
# "#74041" and "Bug#94921"
#
# - Leaves unconsumed arguments in passed array, so check or reject them
# with opts_done(@_)!
#
# Examples:
#
# Consume zero or more bugs -- error on invalid bug-number:
#
# Usage: [bug]...
# my @bugs = bugargs(\@_) or die 'no bugs!';
#
# Consume at most one bug -- error on invalid bug-number:
#
# Usage: [bug]...
# my $bug = bugargs(\@_, 1) or die 'no bugs!';
#
# Consume at most one bug up to a separator or non-bugish arg:
#
# Usage: [bug] [to] [other@non-bugish=args]...
# my ($bug, $sep) = bugargs(\@_, 1, '^to$', 'otherargs') or die 'no bugs!';
#
# Consume at most one up to something non-bugish:
#
# Usage: [bug] [some@email]...
# my $bug = bugargs(\@_, 1, undef, 'otherargs') or die 'no bugs!';
#
#
# Note on bugargs() transition: The following tricky cases should work:
# done 123456 , clone it -1
# done 123456 , clone -1 -1
# done 123456 , clone to -2
#
# done 123456 , clone to -1 , reassign it -1 to pkg
# ==> clone 123456 -1 , reassign 123456 pkg
# done 123456 , clone -1 -1 , reassign -1 -1 to pkg
# ==> clone 123456 -1 , reassign 123456 pkg
# # TODO: Should clone new IDs be assigned to $main::it? Aren't rn.
#
# done 123456 , reassign it pkg
#
# These should error:
# done 123456 , clone -2
sub bugargs {
my $args = shift; # reference to caller's args array
my $max_bugs = shift; # 0/undef means consume all valid bug numbers
my $sep_re = shift;
my $otherargs = (shift // '') eq 'otherargs';
my $disallow_implicit_msg = shift;
my $sep = '';
my @bugs = ();
if (@$args == 0 && defined $main::it) {
goto out;
} elsif (@$args == 0 && $max_bugs > 0) {
die
"$progname: need at least one bug number (implitic bug not defined)\n";
}
while (@$args) {
my $arg = @{$args}[0];
if ($sep_re && $arg =~ $sep_re) {
$sep = $arg;
shift @{$args}; # remove from args array
last;
}
if ($max_bugs && @bugs >= $max_bugs) {
last;
}
# Be careful since '-1' is ambigous if it's already been used as a
# 'clone' new ID.
my $italias
= $arg eq '-1' && defined $main::it && !exists $clonedbugs{-1};
if ($arg eq 'it' || $italias) {
if ($disallow_implicit_msg) {
die
"$progname: The implict bug '$arg' is not allowed $disallow_implicit_msg!\n";
}
if (not defined $main::it) {
die
"$progname: You provided the implict bug '$arg' without context!\n";
}
$arg = $main::it;
# only allow using $it once
$disallow_implicit_msg = 'again';
goto valid;
}
# Remove cruft around the raw number
$arg =~ s/^(?:(?:bug)?\#)?(-?\d+):?$/$1/i;
say "bugargs: valid bug? $arg" if $debug;
if ($arg !~ /^[0-9]{4,}$/ && !exists $clonedbugs{$arg}) {
if ($otherargs) {
last;
} else {
my $clones = '';
if (%clonedbugs && $arg =~ '^-') {
$clones
= "\nMaybe you meant one of the available clones:\n"
. " "
. join(", ", keys %clonedbugs) . "?\n";
}
die "$progname: '$arg' is not a valid bug number!\n$clones";
}
}
# Got a valid bug number.
$main::it = $arg; # allow user to refer back to 'it' later
valid:
shift @{$args}; # remove from caller's args array
push @bugs, $arg;
}
out:
if (@bugs == 0) {
if (defined $main::it) {
push @bugs, $main::it if !$disallow_implicit_msg;
} else {
die "$progname: Implict bug used without context!\n";
}
}
say "bugargs: bugs=(@bugs), sep='$sep', args=(@$args)" if $debug;
if ($max_bugs == 1 && $sep_re) {
return $bugs[0] ? ($bugs[0], $sep) : undef;
} elsif ($max_bugs == 1) {
return $bugs[0];
}
return @bugs;
}
# Stores up some extra information for a mail to the bts.
sub mailbts {
my $short_subj = shift;
my $cmd = shift || die 'no cmd';
if ($ctlsubject eq '') {
$ctlsubject = $short_subj;
} elsif (length($ctlsubject) + length($short_subj) < 100) {
$ctlsubject .= ", $short_subj" if length($short_subj);
} elsif ($ctlsubject !~ / ...$/) {
$ctlsubject .= " ...";
}
die '$index undef, called outside command loop?' if not defined $index;
push @ctlcmds, "$comment[$index]" if $comment[$index];
push @ctlcmds, "$cmd";
}
sub make_pseudoheader {
my $phdr = '';
$phdr = (join("\n", @_) . "\n") if @_;
foreach (@ctlcmds) {
# Optimize pseudoheader a bit.
if (keys %donebugs == 1) {
s/^close ([0-9]+) ([^ \/]+)$/Version: $2/ && goto out;
s/^fixed ([0-9]+) ([^ \/]+)$/Version: $2/ && goto out;
}
s/^/Control: /;
out:
$phdr .= $_ . "\n";
}
return $phdr ? ($phdr . "\n") : '';
}
# Extract an array of email addresses from a string
sub extract_addresses {
my $s = shift;
my @addresses;
# Original regular expression from git-send-email, slightly modified
while ($s and $s =~ /([^,<>"\s\@]+\@[^.,<>"\s@]+(?:\.[^.,<>"\s\@]+)+)(.*)/)
{
push @addresses, $1;
$s = $2;
}
return @addresses;
}
sub pick_sender {
my $from = shift;
return 'noaction' if $noaction;
return 'mua' if $use_mutt and $from; # TODO: really needs From?
return 'smtp' if length $smtphost;
return 'sendmail';
}
# Send one full mail message.
sub send_mail {
my ($hdrs, $rcpts, $subject, $body, $from) = @_;
@$hdrs or die "no headers given";
@$rcpts or die "no rcpts given";
my $msgid
= sprintf("%s-%s", time(), int(rand(1000000000))) . "-bts";
my $date = strftime "%a, %d %b %Y %T %z", localtime;
my $charset = `locale charmap`;
chomp $charset;
$charset =~ s/^ANSI_X3\.4-19(68|86)$/US-ASCII/;
$subject = MIME_encode_mimewords($subject, 'Charset' => $charset);
$from = $from // get_from_header();
$from = MIME_encode_mimewords($from, 'Charset' => $charset) if $from;
# TODO: s/$message/$headers/
my $message = '';
$message .= fold_from_header("From: $from") . "\n" if $from;
$message .= join("\n", @{$hdrs}) . "\n";
$message .= "X-Debbugs-No-Ack: Yes\n" if not $requestack;
$message .= "Subject: $subject\n" if length $subject;
$message
.= "Date: $date\n"
. "User-Agent: devscripts bts/$version$toolname\n"
. "Message-ID: <$msgid>\n" . "\n";
my $sender = pick_sender($from);
say
"bts debug: Sending using '$sender'. (use_mutt=$use_mutt, interactive=$interactive, noaction=$noaction)"
if $debug;
($message, $body) = confirmmail($message, $body);
return if not defined $body;
$message .= "$body\n";
if ($sender eq 'noaction') {
print "$message\n";
} elsif ($sender eq 'mua') {
send_using_mua($message);
} elsif ($sender eq 'smtp') {
send_using_smtp($from, $rcpts, $message);
} elsif ($sender eq 'sendmail') {
send_using_sendmail($message);
} else {
die 'unhandled $sender';
}
}
sub get_from_header {
if (!$ENV{'DEBEMAIL'} && !$ENV{'EMAIL'}) {
return;
}
my ($email, $name);
if (exists $ENV{'DEBFULLNAME'}) { $name = $ENV{'DEBFULLNAME'}; }
if (exists $ENV{'DEBEMAIL'}) {
$email = $ENV{'DEBEMAIL'};
if ($email =~ /^(.*?)\s+<(.*)>\s*$/) {
$name ||= $1;
$email = $2;
}
}
if (exists $ENV{'EMAIL'}) {
if ($ENV{'EMAIL'} =~ /^(.*?)\s+<(.*)>\s*$/) {
$name ||= $1;
$email ||= $2;
} else {
$email ||= $ENV{'EMAIL'};
}
}
if (!$name) {
# Perhaps not ideal, but it will have to do
$name = (getpwuid($<))[6];
$name =~ s/,.*//;
}
return $name ? "$name <$email>" : $email;
}
sub get_interactive_cc {
my %cc = ();
if ($packagesserver) {
$cc{"$_\@$packagesserver"} = 1 foreach keys %ccpackages;
}
if ($btsserver) {
$cc{"$_-submitter\@$btsserver"} = 1 foreach keys %ccsubmitters;
}
return %cc;
}
sub get_mail_cc {
my %cc;
if ($interactive eq 'force' || $use_mutt) {
%cc = (%cc, get_interactive_cc());
}
$cc{$_} = 1 foreach (@ccemails, @opt_ccemails);
if ($ccsecurity) {
$cc{$ccsecurity} = 1;
}
return %cc;
}
sub get_nonmua_bcc {
return () if $use_mutt;
return map { ($_ => 1) } @bccemails;
}
sub send_using_mua {
my $message = shift;
my ($fh, $filename) = tempfile(
"btsXXXXXX",
SUFFIX => ".eml",
DIR => File::Spec->tmpdir,
UNLINK => 1
);
open(MAILOUT, ">&", $fh)
or die "$progname: writing to temporary file failed: $!\n";
print MAILOUT $message;
my $mailcmd = $muttcmd;
$mailcmd =~ s/\%([%s])/$1 eq '%' ? '%' : $filename/eg;
system("$mailcmd </dev/tty") >> 8 == 0
or die "$progname: unable to start MUA '$mailcmd': $!";
}
sub send_using_smtp {
my $from = shift
or die
"$progname: When sending with SMTP \$EMAIL or \$DEBEMAIL MUST be set to
determine envelope sender (RCPT FROM).\n";
my $rcpts;
my $message = shift;
my @fromaddresses = extract_addresses($from);
@fromaddresses
or die "Something went wrong: Couldn't extract From address";
my $fromaddress = "$fromaddresses[0]";
my $smtp;
my $smtps = $smtphost =~ m%^(?:(?:ssmtp|smtps)://)(.*)$%;
if ($smtps) {
my ($host, $port) = split(/:/, $1);
$port ||= '465';
$smtp = Net::SMTP->new(
$host,
Port => $port,
Hello => $smtphelo,
SSL => 1,
)
or die
"$progname: failed to open SMTP connection with TLS to $smtphost\n($@)\n";
} else {
my ($host, $port) = split(/:/, $smtphost);
$port ||= '25';
$smtp = Net::SMTP->new(
$host,
Port => $port,
Hello => $smtphelo,
)
or die
"$progname: failed to open SMTP connection to $smtphost\n($@)\n";
}
if ($smtpuser) {
if (have_authen_sasl) {
$smtppass = getpass() if not $smtppass;
# Enforce STARTTLS, unless we're using SMTPS; Net::SMTP will
# otherwise refuse auth() in the next step, and terminate the
# connection with FIN.
$smtp->starttls()
or die "$progname: Could not upgrade with STARTTLS"
unless $smtps;
$smtp->auth($smtpuser, $smtppass)
or die "$progname: failed to authenticate to $smtphost\n($@)\n";
} else {
die
"$progname: failed to authenticate to $smtphost: $authen_sasl_broken\n";
}
}
$smtp->mail($fromaddress)
or die "$progname: failed to set SMTP from address $fromaddress\n($@)\n";
foreach my $rcpt (map { extract_addresses($_) } @{$rcpts}) {
$smtp->recipient($rcpt)
or die "$progname: failed to set SMTP recipient $rcpt\n($@)\n";
}
$smtp->data($message)
or die "$progname: failed to send message as SMTP DATA\n($@)\n";
$smtp->quit
or die "$progname: failed to quit SMTP connection\n($@)\n";
}
sub send_using_sendmail {
my $message = shift;
my $pid = open(MAIL, "|-");
if (!defined $pid) {
die "$progname: Couldn't fork: $!\n";
}
$SIG{'PIPE'} = sub { die "$progname: pipe for $sendmailcmd broke\n"; };
if ($pid) {
# parent
print MAIL $message;
close MAIL or die "$progname: $sendmailcmd error: $!\n";
} else {
# child
if ($debug) {
say
"bts debug: Using 'cat' instead of '$sendmailcmd' due to \$DEBUG\n";
system("/bin/cat") >> 8 == 0
or die "$progname: error running cat: $!\n";
} else {
my @mailcmd = split ' ', $sendmailcmd;
push @mailcmd, "-t" if $sendmailcmd =~ /$sendmail_t/;
system(@mailcmd) >> 8 == 0
or die "$progname: error running $sendmailcmd: $!\n";
}
}
}
sub send_scriptions {
# TODO: Archived bugs don't allow subscriptions. Somehow also do an
# unarchive (how without race?) or just complain.
foreach my $bug (keys %scription) {
my ($act, $email) = @{ $scription{$bug} };
if (defined $email and $email eq '!') {
$email = undef;
} else {
$email ||= $EMAIL;
$email = extractemail($email) if defined $email;
}
mailto(
"${act}scription request for bug #$bug",
'', # empty body
$bug . '-subscribe@' . $btsserver,
$email # From
);
}
}
sub main {
my @hdrs = ();
my %to = ();
my %cc = ();
my %bcc = get_nonmua_bcc();
my $subject;
my $body;
fixup_done_bugs();
# Decide on control@, submit@ or reply mail.
if ($reply{greeting} || %submit) {
%to = %{ $reply{to} };
%cc = (get_mail_cc(), %{ $reply{cc} });
if (%submit) {
%cc = (%to, %cc);
%to = ($btssubmitemail => 1);
}
$subject = $reply{subject} // $ctlsubject;
# ctlsubject fallback for 'done' without 'reply'. See
# fixup_done_bugs.
my @phdrs = ();
if (%submit) {
$subject = $submit{subject};
(my $package = $submit{package}) =~ s/^/Package: /;
push(@phdrs, $package);
push(@hdrs, "X-Debbugs-CC: " . join(', ', sort keys %cc));
#^ Note: In hdrs because phdrs don't support continuation lines
# and CC lists tend to get rather long. Grep for 'my %pheader'
# in Debbugs.
%cc = ();
}
$body = $reply{greeting} ? "Hi,\n\n" : '';
$body .= $reply{done} // ''; # Template from fixup_done_bugs
$body .= $reply{body} // '';
$body = make_pseudoheader(@phdrs) . $body;
} elsif (@ctlcmds) { # control@ mail
$to{$btsctlemail} = 1;
%cc = get_mail_cc();
$subject = $ctlsubject;
$body = join "", map { $_ . "\n" } @ctlcmds;
$body .= "thanks\n";
}
if (%to) {
unshift(@hdrs, "Bcc: " . join(', ', sort keys %bcc)) if %bcc;
unshift(@hdrs, "Cc: " . join(', ', sort keys %cc)) if %cc;
unshift(@hdrs, "To: " . join(', ', sort keys %to));
$body = addfooter($body) if not $use_mutt;
send_mail(\@hdrs, [keys %to, keys %cc, keys %bcc], $subject, $body);
}
send_scriptions();
}
sub confirmmail {
my ($header, $body) = @_;
return ($header, $body) if $noaction or $use_mutt;
# $use_mutt bypassess code below because it already has an interactive
# confirmation.
$body = edit($body) if $interactive eq 'force';
my $setHeader = 0;
if ($interactive ne 'no') {
while (1) {
print "\n", $header, "\n", $body, "\n---\n";
my $def = 'y';
if ($body =~ /^(> )?>> *bts:/m) {
warn
"WARN: Mail contans template message '>> bts: ...' please replace it with your message\n";
$def = 'e';
print "Send despite warning? [yes/no/Edit] ";
} else {
print "OK to send? [Yes/no/edit] ";
}
$_ = <TTY> // die 'reading from TTY failed';
if (/^n/i) {
print "Not sending as requested.\n";
$body = undef;
last;
} elsif (/^y/i || $def eq 'y') {
last;
} elsif (/^e/i || $def eq 'e') {
# Since the user has chosen to edit the message, we go ahead
# and add the $ccpackages Ccs (if they haven't already been
# added due to interactive).
if ($interactive ne 'force' && !$setHeader) {
$setHeader = 1;
my $ccs = join(', ', get_interactive_cc());
if ($header =~ m/^Cc: (.*?)$/m) {
$ccs = "$1, $ccs";
$header =~ s/^Cc: .*?$/Cc: $ccs/m;
} else {
$header =~ s/^(To: .*?)$/$1\nCc: $ccs/m;
}
}
$body = edit($body);
}
}
}
return ($header, $body);
}
sub addfooter {
my $body = shift;
if (-r $ENV{'HOME'} . "/.signature") {
if (open SIG, "<", $ENV{'HOME'} . "/.signature") {
$body .= "-- \n";
while (<SIG>) {
$body .= $_;
}
close SIG;
}
}
return $body;
}
sub getpass() {
system "stty -echo cbreak </dev/tty";
die "$progname: error disabling stty echo\n" if $?;
print "\a${smtpuser}";
print "\@$smtphost" if $smtpuser !~ /\@/;
print "'s SMTP password: ";
$_ = <TTY> // die 'reading from TTY failed';
chomp;
print "\n";
system "stty echo -cbreak </dev/tty";
die "$progname: error enabling stty echo\n" if $?;
return $_;
}
sub extractemail() {
my $thing = shift or die "$progname: extract e-mail from what?\n";
if ($thing =~ /^(.*?)\s+<(.*)>\s*$/) {
$thing = $2;
}
return $thing;
}
# A simplified version of mailbtsall which sends one message only to
# a specified address using the specified email From: header
sub mailto {
my ($subject, $body, $to, $from) = @_;
send_mail(["To: $to"], [$to], $subject, $body, $from);
}
# The following routines are taken from a patched version of MIME::Words
# posted at http://mail.nl.linux.org/linux-utf8/2002-01/msg00242.html
# by Richard ÄŒepas (Chepas) <rch@richard.eu.org>
sub MIME_encode_B {
my $str = shift;
require MIME::Base64;
MIME::Base64::encode_base64($str, '');
}
sub MIME_encode_Q {
my $str = shift;
$str
=~ s{([_\?\=\015\012\t $NONPRINT])}{$1 eq ' ' ? '_' : sprintf("=%02X", ord($1))}eog
; # RFC-2047, Q rule 3
$str;
}
sub MIME_encode_mimeword {
my $word = shift;
my $encoding = uc(shift || 'Q');
my $charset = uc(shift || 'ISO-8859-1');
my $encfunc = (($encoding eq 'Q') ? \&MIME_encode_Q : \&MIME_encode_B);
"=?$charset?$encoding?" . &$encfunc($word) . "?=";
}
sub MIME_encode_mimewords {
my ($rawstr, %params) = @_;
# check if we have something to encode
$rawstr !~ /[$NONPRINT]/o and $rawstr !~ /\=\?/o and return $rawstr;
my $charset = $params{Charset} || 'ISO-8859-1';
# if there is 1/3 unsafe bytes, the Q encoded string will be 1.66 times
# longer and B encoded string will be 1.33 times longer than original one
my $encoding = lc(
$params{Encoding}
|| (
length($rawstr) > 3 * ($rawstr =~ tr/[\x00-\x1F\x7F-\xFF]//)
? 'q'
: 'b'
));
# Encode any "words" with unsafe bytes.
my ($last_token, $last_word_encoded, $token) = ('', 0);
$rawstr =~ s{([^\015\012\t ]+|[\015\012\t ]+)}{ # get next "word"
$token = $1;
if ($token =~ /[\015\012\t ]+/) { # white-space
$last_token = $token;
} else {
if ($token !~ /[$NONPRINT]/o and $token !~ /\=\?/o) {
# no unsafe bytes, leave as it is
$last_word_encoded = 0;
$last_token = $token;
} else {
# has unsafe bytes, encode to one or more encoded words
# white-space between two encoded words is skipped on
# decoding, so we should encode space in that case
$_ = $last_token =~ /[\015\012\t ]+/ && $last_word_encoded ? $last_token.$token : $token;
# We limit such words to about 18 bytes, to guarantee that the
# worst-case encoding give us no more than 54 + ~10 < 75 bytes
s{(.{1,15}[\x80-\xBF]{0,4})}{
# don't split multibyte characters - this regexp should
# work for UTF-8 characters
MIME_encode_mimeword($1, $encoding, $charset).' ';
}sxeg;
$_ = substr($_, 0, -1); # remove trailing space
$last_word_encoded = 1;
$last_token = $token;
$_;
}
}
}sxeg;
$rawstr;
}
# This is a stripped-down version of Mail::Header::_fold_line, but is
# not as general-purpose as the original, so take care if using it elsewhere!
# The heuristics are changed to prevent splitting in the middle of an
# encoded word; we should not have any commas or semicolons!
sub fold_from_header {
my $header = shift;
chomp $header; # We assume there wasn't a newline anyhow
my $maxlen = 76;
my $max = int($maxlen - 5); # 4 for leading spcs + 1 for [\,\;]
if (length($header) > $maxlen) {
# Split the line up:
# first split at a whitespace,
# else we are looking at a single word and we won't try to split
# it, even though we really ought to
# But this could only happen if someone deliberately uses a really
# long name with no spaces in it.
my @x;
push @x, $1
while (
$header =~ s/^\s*
([^\"]{1,$max}\s
|[^\s\"]*(?:\"[^\"]*\"[ \t]?[^\s\"]*)+\s
|[^\s\"]+\s
)
//x
);
push @x, $header;
map { s/\s*$// } @x;
if (@x > 1 and length($x[-1]) + length($x[-2]) < $max) {
$x[-2] .= " $x[-1]";
pop @x;
}
$x[0] =~ s/^\s*//;
$header = join("\n ", @x);
}
$header =~ s/^(\S+)\n\s*(?=\S)/$1 /so;
return $header;
}
########## Browsing and caching subroutines
# Mirrors a given thing
sub download {
my $thing = shift;
my $thgopts = shift || '';
my $manual = shift; # true="bts cache", false="bts show/bug"
my $mboxing = shift; # true="bts --mbox show/bugs", and only if $manual=0
my $bug_current = shift; # current bug being downloaded if caching
my $bug_total = shift; # total things to download if caching
my $timestamp = 0;
my $versionstamp = '';
my ($url, $urltype);
my $oldcwd = getcwd;
# What URL are we to download?
if ($thgopts ne '') {
# have to be intelligent here :/
($url, undef) = thing_to_url($thing);
$url = $url . $thgopts;
} else {
# let the BTS be intelligent
$url = "$btsurl$thing";
}
if (!-d $cachedir) {
die "$progname: download() called but no cachedir!\n";
}
chdir($cachedir) || die "$progname: chdir $cachedir: $!\n";
if (-f cachefile($thing, $thgopts)) {
($timestamp, $versionstamp) = get_timestamp($thing, $thgopts);
$timestamp ||= 0;
$versionstamp ||= 0;
# And ensure we preserve any manual setting
if (is_manual($timestamp)) { $manual = 1; }
}
# do we actually have to do more than we might have thought?
# yes, if we've caching with --cache-mode=mbox or full and the bug had
# previously been cached in a less thorough format
my $forcedownload = 0;
if ($thing =~ /^\d+$/ and !$refreshmode) {
if (old_cache_format_version($versionstamp)) {
$forcedownload = 1;
} elsif ($cachemode ne 'min' or $mboxing) {
if (!-r mboxfile($thing)) {
$forcedownload = 1;
} elsif ($cachemode eq 'full' and -d $thing) {
opendir DIR, $thing
or die "$progname: opendir $cachedir/$thing: $!\n";
my @htmlfiles = grep { /^\d+\.html$/ } readdir(DIR);
closedir DIR;
$forcedownload = 1 unless @htmlfiles;
}
}
}
print "Caching $url ... "
if !$quiet
and $thing ne "css/bugs.css";
IO::Handle::flush(\*STDOUT);
my ($ret, $msg, $livepage, $contenttype)
= bts_mirror($url, $timestamp, $forcedownload);
my $charset = $contenttype || '';
if ($charset =~ m/charset=(.*?)(;|\Z)/) {
$charset = $1;
} else {
$charset = "";
}
if ($ret == MIRROR_UP_TO_DATE) {
# we have an up-to-date version already, nothing to do
# and $timestamp is guaranteed to be well-defined
if (is_automatic($timestamp) and $manual) {
set_timestamp($thing, $thgopts, make_manual($timestamp),
$versionstamp);
}
if (!$quiet and $thing ne "css/bugs.css") {
print "(cache already up-to-date) ";
print "$bug_current/$bug_total" if $bug_total;
print "\n";
}
chdir $oldcwd or die "$progname: chdir $oldcwd failed: $!\n";
} elsif ($ret == MIRROR_DOWNLOADED) {
# Note the current timestamp, but don't record it until
# we've successfully stashed the data away
$timestamp = time;
die "$progname: empty page downloaded\n" unless length $livepage;
my $bug2filename = {};
if ($thing =~ /^\d+$/) {
# we've downloaded an individual bug, and it's been updated,
# so we need to also download all the attachments
$bug2filename
= download_attachments($thing, $livepage, $timestamp);
}
my $data = $livepage; # work on a copy, not the original
my $cachefile = cachefile($thing, $thgopts);
open(OUT_CACHE, ">$cachefile")
or die "$progname: open $cachefile: $!\n";
$livepage
= mangle_cache_file($livepage, $thing, $bug2filename, $timestamp,
$charset ? $contenttype : '');
print OUT_CACHE $livepage;
close OUT_CACHE
or die "$progname: problems writing to $cachefile: $!\n";
set_timestamp($thing, $thgopts,
$manual ? make_manual($timestamp) : make_automatic($timestamp),
$version);
if (!$quiet and $thing ne "css/bugs.css") {
print "(cached new version) ";
print "$bug_current/$bug_total" if $bug_total;
print "\n";
} elsif ($quiet == 1 and $manual and $thing ne "css/bugs.css") {
print "Caching $url ... (cached new version)\n";
} elsif ($quiet > 1) {
# do nothing
}
chdir $oldcwd or die "$progname: chdir $oldcwd failed: $!\n";
} else {
die "$progname: couldn't download $url:\n$msg\n";
}
}
sub download_attachments {
my ($thing, $toppage, $timestamp) = @_;
my %bug2filename;
# We search for appropriate strings in the top page, and save the
# attachments in files with names as follows:
# - if the attachment specifies a filename, save as bug#/msg#-att#/filename
# - if not, save as bug#/msg#-att# with suffix .txt if plain/text and
# .html if plain/html, no suffix otherwise (too much like hard work!)
# Since messages are never modified retrospectively, we don't download
# attachments which have already been downloaded
# Yuck, yuck, yuck. This regex splits the $data string at every
# occurrence of either "[<a " or plain "<a ", preserving any "[".
my @data = split /(?:(?=\[<[Aa]\s)|(?<!\[)(?=<[Aa]\s))/, $toppage;
foreach (@data) {
next
unless
m%<a(?: class=\".*?\")? href="(?:/cgi(?:-bin)?/)?((bugreport\.cgi[^\"]+)"(?: .*?)?>|(version\.cgi[^\"]+)"><img[^>]* src="(?:/cgi(?:-bin)?/)?([^\"]+)">|(version\.cgi[^\"]+)">)%i;
my $ref = $5;
$ref = $4 if not defined $ref;
$ref = $2 if not defined $ref;
my ($msg, $filename) = href_to_filename($_);
next unless defined $msg;
if ($msg =~ /^\d+-\d+$/) {
# it's an attachment, must download
if (-f dirname($filename)) {
warn
"$progname: found file where directory expected; using existing file ("
. dirname($filename) . ")\n";
$bug2filename{$msg} = dirname($filename);
} else {
$bug2filename{$msg} = $filename;
}
# already downloaded?
next if -f $bug2filename{$msg} and not $refreshmode;
} elsif ($cachemode eq 'full' and $msg =~ /^\d+$/) {
$bug2filename{$msg} = $filename;
# already downloaded?
next if -f $bug2filename{$msg} and not $refreshmode;
} elsif ($cachemode eq 'full' and $msg =~ /^\d+-mbox$/) {
$bug2filename{$msg} = $filename;
# already downloaded?
next if -f $bug2filename{$msg} and not $refreshmode;
} elsif (($cachemode eq 'full' or $cachemode eq 'mbox' or $mboxmode)
and $msg eq 'mbox') {
$bug2filename{$msg} = $filename;
# This always needs refreshing, as it does change as the bug
# changes
} elsif ($cachemode eq 'full' and $msg =~ /^(status|raw)mbox$/) {
$bug2filename{$msg} = $filename;
# Always need refreshing, as they could change each time the
# bug does
} elsif ($cachemode eq 'full' and $msg eq 'versions') {
$bug2filename{$msg} = $filename;
# Ensure we always download the full size images for
# version graphs, without the informational links
$ref =~ s%;info=1%;info=0%;
$ref =~ s%(;|\?)(height|width)=\d+%$1%g;
# already downloaded?
next if -f $bug2filename{$msg} and not $refreshmode;
}
next unless exists $bug2filename{$msg};
warn "bts debug: downloading $btscgiurl$ref\n" if $debug;
init_agent() unless $ua; # shouldn't be necessary, but do just in case
my $request = HTTP::Request->new('GET', $btscgiurl . $ref);
my $response = $ua->request($request);
if ($response->is_success) {
my $content_length
= defined $response->content ? length($response->content) : 0;
if ($content_length == 0) {
warn
"$progname: failed to download $ref (length 0), skipping\n";
next;
}
my $data = $response->content;
if ($msg =~ /^\d+$/) {
# we're dealing with a boring message, and so we must be
# in 'full' mode
$data =~ s%<HEAD>%<HEAD><BASE href="../">%;
$data = mangle_cache_file($data, $thing, 'full', $timestamp);
}
make_path(dirname($bug2filename{$msg}));
open OUT_CACHE, ">$bug2filename{$msg}"
or die "$progname: open cache $bug2filename{$msg}\n";
print OUT_CACHE $data;
close OUT_CACHE;
} else {
my $status = $response->status_line;
warn "$progname: failed to download $ref ($status), skipping\n";
next;
}
}
return \%bug2filename;
}
# Download the mailbox for a given bug thing. Appends to $outfile on
# success, dies on failure.
sub download_mbox {
my $thing = shift;
if (!have_lwp()) {
die "$progname: couldn't run bts --mbox: $lwp_broken\n";
}
init_agent() unless $ua;
my $request = HTTP::Request->new('GET',
$btscgiurl . "bugreport.cgi?bug=$thing;mboxmaint=yes");
my $response = $ua->request($request);
if ($response->is_success) {
my $content_length
= defined $response->content ? length($response->content) : 0;
if ($content_length == 0) {
die "$progname: failed to download mbox (length 0).\n";
}
return $response->content;
} else {
my $status = $response->status_line;
die "$progname: failed to download mbox ($status).\n";
}
}
# Mangle downloaded file to work in the local cache, so
# selectively modify the links
sub mangle_cache_file {
my ($data, $thing, $bug2filename, $timestamp, $ctype) = @_;
my $fullmode = !ref $bug2filename;
# Undo unnecessary '+' encoding in URLs
while ($data =~ s!(href=\"[^\"]*)\%2b!$1+!ig) { }
my $time = localtime(abs($timestamp));
$data
=~ s%(<BODY.*>)%$1<p><em>[Locally cached on $time by devscripts version $version]</em></p>%i;
$data =~ s%href="/css/bugs.css"%href="bugs.css"%;
if ($ctype) {
$data
=~ s%(<HEAD.*>)%$1<META HTTP-EQUIV="Content-Type" CONTENT="$ctype">%i;
}
my @data;
# We have to distinguish between release-critical pages and normal BTS
# pages as they have a different structure
if ($thing =~ /^release-critical/) {
@data = split /(?=<[Aa])/, $data;
foreach (@data) {
s%<a href="(https?://$btsserver/cgi(?:-bin)?/bugreport\.cgi.*bug=(\d+)[^\"]*)">(.+?)</a>%<a href="$2.html">$3</a> (<a href="$1">online</a>)%i;
s%<a href="(https?://$btsserver/cgi(?:-bin)?/pkgreport\.cgi.*pkg=([^\"&;]+)[^\"]*)">(.+?)</a>%<a href="$2.html">$3</a> (<a href="$1">online</a>)%i;
# References to other bug lists on bugs.d.o/release-critical
if (m%<a href="((?:debian|other)[-a-z/]+\.html)"%i) {
my $ref = 'release-critical/' . $1;
$ref =~ s%/%_%g;
s%<a href="((?:debian|other)[-a-z/]+\.html)">(.+?)</a>%<a href="$ref">$2</a> (<a href="${btsurl}release-critical/$1">online</a>)%i;
}
# Maintainer email address - YUCK!!
s%<a href="(https?://$btsserver/([^\"?]*\@[^\"?]*))">(.+?)</a>>%<a href="$2.html">$3</a>> (<a href="$1">online</a>)%i;
# Graph - we don't download
s%<img src="graph.png" alt="Graph of RC bugs">%<img src="${btsurl}release-critical/graph.png" alt="Graph of RC bugs (online)">%;
}
} else {
# Yuck, yuck, yuck. This regex splits the $data string at every
# occurrence of either "[<a " or plain "<a ", preserving any "[".
@data = split /(?:(?=\[<[Aa]\s)|(?<!\[)(?=<[Aa]\s))/, $data;
foreach (@data) {
if (
m%<a(?: class=\".*?\")? href=\"(?:/cgi(?:-bin)?/)?bugreport\.cgi[^\?]*\?.*?;?bug=(\d+)%i
) {
my $bug = $1;
my ($msg, $filename) = href_to_filename($_);
if ($bug eq $thing and defined $msg) {
if ($fullmode
or (!$fullmode and exists $$bug2filename{$msg})) {
s%<a((?: class=\".*?\")?) href="(?:/cgi(?:-bin)?/)?(bugreport\.cgi[^\"]*)">(.+?)</a>%<a$1 href="$filename">$3</a> (<a$1 href="$btscgiurl$2">online</a>)%i;
} else {
s%<a((?: class=\".*?\")?) href="(?:/cgi(?:-bin)?/)?(bugreport\.cgi[^\"]*)">(.+?)</a>%$3 (<a$1 href="$btscgiurl$2">online</a>)%i;
}
} else {
s%<a((?: class=\".*?\")?) href="(?:/cgi(?:-bin)?/)?(bugreport\.cgi[^\?]*\?.*?bug=(\d+))"(.*?)>(.+?)</a>%<a$1 href="$3.html"$4>$5</a> (<a$1 href="$btscgiurl$2">online</a>)%i;
}
} else {
s%<a((?: class=\".*?\")?) href="(?:/cgi(?:-bin)?/)?(pkgreport\.cgi\?(?:pkg|maint)=([^\"&;]+)[^\"]*)">(.+?)</a>%<a$1 href="$3.html">$4</a> (<a$1 href="$btscgiurl$2">online</a>)%gi;
s%<a((?: class=\".*?\")?) href="(?:/cgi(?:-bin)?/)?(pkgreport\.cgi\?src=([^\"&;]+)[^\"]*)">(.+?)</a>%<a$1 href="src_$3.html">$4</a> (<a$1 href="$btscgiurl$2">online</a>)%i;
s%<a((?: class=\".*?\")?) href="(?:/cgi(?:-bin)?/)?(pkgreport\.cgi\?submitter=([^\"&;]+)[^\"]*)">(.+?)</a>%<a$1 href="from_$3.html">$4</a> (<a$1 href="$btscgiurl$2">online</a>)%i;
s%<a((?: class=\".*?\")?) href="(?:/cgi(?:-bin)?/)?(pkgreport\.cgi\?.*?;?archive=([^\"&;]+);submitter=([^\"&;]+)[^\"]*)">(.+?)</a>%<a$1 href="from_$4_3Barchive_3D$3.html">$5</a> (<a$1 href="$btscgiurl$2">online</a>)%i;
s%<a((?: class=\".*?\")?) href="(?:/cgi(?:-bin)?/)?(pkgreport\.cgi\?.*?;?package=([^\"&;]+)[^\"]*)">(.+?)</a>%<a$1 href="$3.html">$4</a> (<a$1 href="$btscgiurl$2">online</a>)%gi;
s%<a((?: class=\".*?\")?) href="(?:/cgi(?:-bin)?/)?(bugspam\.cgi[^\"]+)">%<a$1 href="$btscgiurl$2">%i;
s%<a((?: class=\".*?\")?) href="/([0-9]+?)">(.+?)</a>%<a$1 href="$2.html">$3</a> (<a$1 href="$btsurl$2">online</a>)%i;
# Version graphs
# - remove 'package=' and move the package to the front
s%((?:<img[^>]* src=\"|<a[^>]* href=\")(?:/cgi(?:-bin)?/)?version\.cgi\?)([^\"]+)package=([^;\"]+)([^\"]+\"|\")>%$1$3;$2$4>%gi;
# - replace 'found=' with '.f.' and 'fixed=' with '.fx.'
1 while
s%((?:<img[^>]* src=\"|<a[^>]* href=\")(?:/cgi(?:-bin)?/)?version\.cgi\?)(.*?;)found=([^\"]+)\">%$1$2.f.$3">%i;
1 while
s%((?:<img[^>]* src=\"|<a[^>]* href=\")(?:/cgi(?:-bin)?/)?version\.cgi\?)(.*?;)fixed=([^\"]+)\">%$1$2.fx.$3">%i;
1 while
s%((?:<img[^>]* src=\"|<a[^>]* href=\")(?:/cgi(?:-bin)?/)?version\.cgi\?found=)([^\"]+)\">%$1.f.$2">%i;
1 while
s%((?:<img[^>]* src=\"|<a[^>]* href=\")(?:/cgi(?:-bin)?/)?version\.cgi\?fixed=)([^\"]+)\">%$1.fx.$2">%i;
# - replace '%2F' or '%2C' (a URL-encoded / or ,) with '.'
1 while
s%((?:<img[^>]* src=\"|<a[^>]* href=\")(?:/cgi(?:-bin)?/)?version\.cgi\?[^\%]*)\%2[FC]([^\"]+)\">%$1.$2">%gi;
# - display collapsed graph images at 25%
s%(<img[^>]* src=\"[^\"]+);collapse=1([^\"]+)\">%$1$2.co" width="25\%" height="25\%">%gi;
# - and link to the collapsed graph
s%(<a[^>]* href=\"[^\"]+);collapse=1([^\"]+)\">%$1$2.co">%gi;
# - remove any other parameters
1 while
s%((?:<img[^>]* src|<a[^>]* href)=\"(?:/cgi(?:-bin)?/)?version\.cgi\?[^\"]+);(?:\w+=\d+)([^>]+)\>%$1$2>%gi;
# - remove any +s (encoded spaces)
1 while
s%((?:<img[^>]* src=\"|<a[^>]* href=\")(?:/cgi(?:-bin)?/)?version\.cgi\?[^\+]*)\+([^\"]+)\">%$1$2">%gi;
# - remove trailing ";" and ";." from previous substitutions
1 while
s%((?:<img[^>]* src=\"|<a[^>]* href=\")(?:/cgi(?:-bin)?/)?version\.cgi\?[^\"]+);\.(.*?)>%$1.$2>%gi;
1 while
s%((?:<img[^>]* src=\"|<a[^>]* href=\")(?:/cgi(?:-bin)?/)?version\.cgi\?[^\"]+);\">%$1">%gi;
# - final reference should be $package.$versions[.co].png
s%(<img[^>]* src=\"|<a[^>]* href=\")(?:/cgi(?:-bin)?/)?version\.cgi\?([^\"]+)(\"[^>]*)>%$1$2.png$3>%gi;
}
}
}
return join("", @data);
}
# Removes a specified thing from the cache
sub deletecache {
my $thing = shift;
my $thgopts = shift || '';
if (!-d $cachedir) {
die "$progname: deletecache() called but no cachedir!\n";
}
delete_timestamp($thing, $thgopts);
unlink cachefile($thing, $thgopts);
if ($thing =~ /^\d+$/) {
rmtree("$cachedir/$thing", 0, 1) if -d "$cachedir/$thing";
unlink("$cachedir/$thing.mbox") if -f "$cachedir/$thing.mbox";
unlink("$cachedir/$thing.status.mbox")
if -f "$cachedir/$thing.status.mbox";
unlink("$cachedir/$thing.raw.mbox") if -f "$cachedir/$thing.raw.mbox";
}
}
# Given a thing, returns the filename for it in the cache.
sub cachefile {
my $thing = shift;
my $thgopts = shift || '';
if ($thing eq '') { die "$progname: cachefile given empty argument\n"; }
if ($thing =~ /bugs.css$/) { return $cachedir . "bugs.css" }
$thing =~ s/^src:/src_/;
$thing =~ s/^from:/from_/;
$thing =~ s/^tag:/tag_/;
$thing =~ s/^usertag:/usertag_/;
$thing =~ s%^release-critical/index\.html$%release-critical.html%;
$thing =~ s%/%_%g;
$thgopts =~ s/;/_3B/g;
$thgopts =~ s/=/_3D/g;
return File::Spec->catfile($cachedir,
$thing . $thgopts . ($thing =~ /\.html$/ ? "" : ".html"));
}
# Given a thing, returns the filename for its mbox in the cache.
sub mboxfile {
my $thing = shift;
return $thing =~ /^\d+$/
? File::Spec->catfile($cachedir, $thing . ".mbox")
: undef;
}
# Given a bug number, returns the dirname for it in the cache.
sub cachebugdir {
my $thing = shift;
if ($thing !~ /^\d+$/) {
die "$progname: cachebugdir given faulty argument: $thing\n";
}
return File::Spec->catdir($cachedir, $thing);
}
# And the reverse: Given a filename in the cache, returns the corresponding
# "thing".
sub cachefile_to_thing {
my $thing = basename(shift, '.html');
my $thgopts = '';
$thing =~ s/^src_/src:/;
$thing =~ s/^from_/from:/;
$thing =~ s/^tag_/tag:/;
$thing =~ s/^usertag_/usertag:/;
$thing =~ s%^release-critical\.html$%release-critical/index\.html%;
$thing =~ s%_%/%g;
$thing =~ s/_3B/;/g;
$thing =~ s/_3D/=/g;
$thing =~ /^(.*?)((?:;.*)?)$/;
($thing, $thgopts) = ($1, $2);
return ($thing, $thgopts);
}
# Given a thing, gives the official BTS cgi page for it
sub thing_to_url {
my $thing = shift;
my $thingurl;
# have to be intelligent here :/
if ($thing =~ /^\d+$/) {
$thingurl = $btscgibugurl . "?bug=" . $thing;
return ($thingurl, "bug");
} elsif ($thing =~ /^from:/) {
($thingurl = $thing) =~ s/^from:/submitter=/;
$thingurl = $btscgipkgurl . '?' . $thingurl;
return ($thingurl, "submitter");
} elsif ($thing =~ /^src:/) {
($thingurl = $thing) =~ s/^src:/src=/;
$thingurl = $btscgipkgurl . '?' . $thingurl;
return ($thingurl, "src");
} elsif ($thing =~ /^tag:/) {
($thingurl = $thing) =~ s/^tag:/tag=/;
$thingurl = $btscgipkgurl . '?' . $thingurl;
return ($thingurl, "tag");
} elsif ($thing =~ /^usertag:/) {
($thingurl = $thing) =~ s/^usertag:/tag=/;
$thingurl = $btscgipkgurl . '?' . $thingurl;
return ($thingurl, "usertag");
} elsif ($thing =~ m%^release-critical(\.html|/(index\.html)?)?$%) {
$thingurl = $btsurl . 'release-critical/index.html';
return ($thingurl, "RC");
} elsif ($thing =~ m%^release-critical/%) {
$thingurl = $btsurl . $thing;
return ($thingurl, "RC");
} elsif ($thing =~ /\@/) { # so presume it's a maint request
$thingurl = $btscgipkgurl . '?maint=' . $thing;
return ($thingurl, "maint");
} else { # it's a package, or had better be...
$thingurl = $btscgipkgurl . '?pkg=' . $thing;
return ($thingurl, "package");
}
die "$progname: thing_to_url() fell through";
}
# Given a thing, reads all links to bugs from the corresponding cache file
# if there is one, and returns a list of them.
sub bugs_from_thing {
my $thing = shift;
my $thgopts = shift || '';
my $cachefile = cachefile($thing, $thgopts);
if (-f $cachefile) {
local $/;
open(IN, $cachefile) || die "$progname: open $cachefile: $!\n";
my $data = <IN>;
close IN;
return $data =~ m!href="(\d+)\.html"!g;
} else {
return ();
}
}
# Given an <a href="bugreport.cgi?...>...</a> string, return a
# msg id and corresponding filename
sub href_to_filename {
my $href = $_[0];
my ($msg, $filename);
if ($href
=~ m%\[<a(?: class=\".*?\")? href="((?:/cgi(?:-bin)?/)?bugreport\.cgi([^\?]*)\?[^\"]*)">.*?\(([^,]*), .*?\)\]%
) {
# this looks like an attachment; $4 should give the MIME-type
my $uri = URI->new($1);
my $urlfilename = $2;
my $bug = $uri->query_param_delete('bug');
my $mimetype = $3;
my $ref = $uri->query();
$ref =~ s/&(?:amp;)?/;/g; # normalise all hrefs
$uri->query($ref);
$msg = $uri->query_param('msg');
my $att = $uri->query_param('att');
return undef unless $msg && $att;
$msg .= "-$att";
$urlfilename ||= $att // '';
my $fileext = '';
if ($urlfilename =~ m%^/%) {
$filename = basename($urlfilename);
} else {
$filename = '';
if ($mimetype eq 'text/plain') { $fileext = '.txt'; }
if ($mimetype eq 'text/html') { $fileext = '.html'; }
}
if (length($filename)) {
$filename = "$bug/$msg/$filename";
} else {
$filename = "$bug/$msg$fileext";
}
} elsif ($href
=~ m%<a(?: class=\".*?\")? href="((?:/cgi(?:-bin)?/)?bugreport\.cgi([^\?]*)\?([^"]*))".*?>%
) {
my $uri = URI->new($1);
my $urlfilename = $2;
my $bug = $uri->query_param_delete('bug');
$msg = $uri->query_param_delete('msg');
my $ref = $uri->query // '';
$ref =~ s/&(?:amp;)?/;/g; # normalise all hrefs
$ref =~ s/;archive=(yes|no)\b//;
$ref =~ s/%3D/=/g;
$uri->query($ref);
my %params = (
mboxstatus => '',
mboxstat => '',
mboxmaint => '',
mbox => '',
$uri->query_form(),
);
if ($msg && !%params) {
$filename = File::Spec->catfile($bug, "$msg.html");
} elsif (($params{mboxstat} || $params{mboxstatus}) eq 'yes') {
$msg = 'statusmbox';
$filename = "$bug.status.mbox";
} elsif ($params{mboxmaint} eq 'yes') {
$msg = 'mbox';
$filename = "$bug.mbox";
} elsif ($params{mbox} eq 'yes') {
if ($msg) {
$filename = "$bug/$msg.mbox";
$msg .= '-mbox';
} else {
$filename = "$bug.raw.mbox";
$msg = 'rawmbox';
}
} elsif (!$ref) {
return undef;
} else {
$href =~ s/>.*/>/s;
warn
"$progname: in href_to_filename: unrecognised BTS URL type: $href\n";
return undef;
}
} elsif ($href
=~ m%<(?:a[^>]* href|img [^>]* src)="((?:/cgi(?:-bin)?/)?version\.cgi\?[^"]+)"[^>]*>%i
) {
my $uri = URI->new($1);
my %params = $uri->query_form();
if ($params{package}) {
$filename .= $params{package};
}
if ($params{found}) {
$filename .= ".f.$params{found}";
}
if ($params{fixed}) {
$filename .= ".fx.$params{fixed}";
}
if ($params{collapse}) {
$filename .= '.co';
}
# Replace encoded "/" and "," characters with "."
$filename =~ s@(?:%2[FC]|/|,)@.@gi;
# Remove encoded spaces
$filename =~ s/\+//g;
$msg = 'versions';
$filename .= '.png';
} else {
return undef;
}
return ($msg, $filename);
}
# Select bugs referred to by thing, download mboxes and launch mailreader.
sub read_many_bugs {
my $thing = shift;
my @opts = shift || ();
my $thingtype = shift;
my ($temp_handle, $tempfile) = tempfile(
"bts-bugsXXXXXX",
SUFFIX => ".mbox",
DIR => File::Spec->tmpdir,
UNLINK => 1
);
my @bugs = ();
if ($thingtype eq 'bug') {
push @bugs, $thing;
} else {
s/=/:/g for @opts;
if ($thingtype eq 'package') {
unshift(@opts, ('package:' . $thing));
} elsif ($thingtype eq 'maint') {
unshift(@opts, ('maint:' . $thing));
} else {
unshift(@opts, $thing);
}
# TODO: Could and should support caching with bugs_from_thing()
my $result = Devscripts::Debbugs::select(@opts);
if (not defined $result) {
die "$progname: Error while retrieving bugs list from SOAP server";
}
push @bugs, @{$result};
my $count = scalar(@bugs);
say "Downloading $count bugs ... ";
}
foreach my $bug (@bugs) {
warn "bts debug: downloading bug mbox $bug\n"
if $debug;
my $mbox = download_mbox($bug);
print $temp_handle $mbox;
}
close $temp_handle
or die "$progname: writing to mbox file $tempfile failed: $!\n";
runmailreader($tempfile);
}
# Browses a given thing, with preprocessed list of URL options such as
# ";opt1=val1;opt2=val2" with possible caching if there are no options
sub browse {
prunecache();
my $thing = shift;
my @opts = shift;
# Are there any options?
my $thgopts = '';
if (@opts) {
$thgopts = join(";", '', @_); # so it'll be ";opt1=val1;opt2=val2"
$thgopts =~ s/:/=/g;
$thgopts =~ s/;tag=/;include=/;
}
if ($thing eq '' && $thgopts ne '') {
die "$progname: browse: empty \$thing";
}
# Check that if we're requesting a tag, that it's a valid tag
if (($thing . $thgopts) =~ /(?:^|;)(?:tag|include|exclude)[:=]([^;]*)/) {
unless (exists $valid_tags{$1}) {
die
"$progname: invalid tag requested: $1\nRecognised tag names are: "
. join(" ", @valid_tags) . "\n";
}
}
if ($offlinemode) {
my $cachefile = cachefile($thing, $thgopts);
if (!-d $cachedir) {
die "\
$progname: Sorry, you are in offline mode and have no cache.
Run \"bts cache\" or \"bts show\" to create one.\n";
} elsif ((!$mboxmode and !-r $cachefile)
or ($mboxmode and !-r mboxfile($thing))) {
die "\
$progname: Sorry, you are in offline mode and that is not cached.
Use \"bts [--cache-mode=...] cache\" to update the cache.\n";
}
if ($mboxmode) {
runmailreader(mboxfile($thing));
} else {
runbrowser("file://$cachefile");
}
}
# else we're in online mode
elsif (have_lwp() && $thing ne '') {
my ($thingurl, $thingtype) = thing_to_url($thing);
my $pid;
if (!$mboxmode) {
# Download cache in background since runbrowser() may or may not
# block (www-browser vs x-www-browser).
$pid = fork()
// die "$progname: fork()ing into background failed!";
if ($pid) {
# Foreground (parent) process
if ($thgopts ne '') {
runbrowser($thingurl . $thgopts);
} else {
# let the BTS be intelligent
runbrowser($btsurl . $thing);
}
my $child;
if (($child = waitpid($pid, WNOHANG)) == 0) {
print("\nStill downloading cache hang on ... ");
IO::Handle::flush(\*STDOUT);
}
$child = waitpid($pid, 0) if not $child;
$child and say "bts debug: child $child exited $?"
if $debug;
return;
}
say "bts debug: child $$: Doing background download()" if $debug;
# Now in background child
}
# May be in background child
my $tempmbox = $mboxmode && $thingtype ne 'bug';
if ($caching && (-d $cachedir || make_path($cachedir))) {
download($thing, $thgopts, 0, $mboxmode);
} else {
$caching
&& warn "$progname: couldn't create cache $cachedir: $!\n";
warn "$progname: Falling back to mbox tempfile download\n"
if $debug;
$tempmbox = 1;
}
if (defined $pid) { # Exit if background child
exit(0);
} elsif ($tempmbox) {
read_many_bugs($thing, @opts, $thingtype);
} elsif ($mboxmode) {
runmailreader(mboxfile($thing));
}
}
}
# Removes all files from the cache which were downloaded automatically
# and have not been accessed for more than 30 days. We also only run
# this at most once per day for efficiency.
sub prunecache {
# TODO: Remove handling of $oldcache post-Stretch
my $oldcache = File::Spec->catdir($ENV{HOME}, '.devscripts_cache', 'bts');
if (-d $oldcache && !-d $cachedir) {
my $err;
make_path(dirname($cachedir), { error => \$err });
if (!@$err) {
system('mv', $oldcache, $cachedir);
}
}
return unless -d $cachedir;
return if -f $prunestamp and -M _ < 1;
my $oldcwd = getcwd;
chdir($cachedir) || die "$progname: chdir $cachedir: $!\n";
# remove the now-defunct live-download file
unlink "live_download.html";
opendir DIR, '.' or die "$progname: opendir $cachedir: $!\n";
my @cachefiles = grep { !/^\.\.?$/ } readdir(DIR);
closedir DIR;
# Are there any unexpected files lying around?
my @known_files = map { basename($_) }
($timestampdb, $timestampdb . ".lock", $prunestamp);
my %weirdfiles = map { $_ => 1 } grep { !/\.(html|css|png)$/ } @cachefiles;
foreach (@known_files) {
delete $weirdfiles{$_} if exists $weirdfiles{$_};
}
# and bug directories
foreach (@cachefiles) {
if (/^(\d+)\.html$/) {
delete $weirdfiles{$1} if exists $weirdfiles{$1} and -d $1;
delete $weirdfiles{"$1.mbox"}
if exists $weirdfiles{"$1.mbox"} and -f "$1.mbox";
delete $weirdfiles{"$1.raw.mbox"}
if exists $weirdfiles{"$1.raw.mbox"} and -f "$1.raw.mbox";
delete $weirdfiles{"$1.status.mbox"}
if exists $weirdfiles{"$1.status.mbox"} and -f "$1.status.mbox";
}
}
warn "$progname: unexpected files/dirs in cache directory $cachedir:\n "
. join("\n ", keys %weirdfiles) . "\n"
if keys %weirdfiles;
my @oldfiles;
foreach (@cachefiles) {
next unless /\.(html|css)$/;
push @oldfiles, $_ if -A $_ > 30;
}
# We now remove the oldfiles if they're automatically downloaded
tie(%timestamp, "Devscripts::DB_File_Lock", $timestampdb,
O_RDWR() | O_CREAT(),
0600, $DB_HASH, "write")
or die "$progname: couldn't open DB file $timestampdb for writing: $!\n"
if !tied %timestamp;
my @unrecognised;
foreach my $oldfile (@oldfiles) {
my ($thing, $thgopts) = cachefile_to_thing($oldfile);
unless (defined get_timestamp($thing, $thgopts)) {
push @unrecognised, $oldfile;
next;
}
next if is_manual(get_timestamp($thing, $thgopts));
# Otherwise, it's automatic and we purge it
deletecache($thing, $thgopts);
}
untie %timestamp;
if (!-e $prunestamp) {
open PRUNESTAMP,
">$prunestamp" || die "$progname: prune timestamp: $!\n";
close PRUNESTAMP;
}
chdir $oldcwd || die "$progname: chdir $oldcwd: $!\n";
utime time, time, $prunestamp;
}
# Determines which browser to use
sub runbrowser {
my $URL = shift;
say("Browsing to $URL");
if (system('sensible-browser', $URL) >> 8 != 0) {
warn "Problem running sensible-browser: $!\n";
}
say("bts debug: browser quit.") if $debug;
}
# Determines which mailreader to use
sub runmailreader {
my $file = shift;
my $quotedfile;
die "$progname: could not read mbox file $file!\n" unless -r $file;
if ($file !~ /\'/) { $quotedfile = qq['$file']; }
elsif ($file !~ /[\"\\\$\'\!]/) { $quotedfile = qq["$file"]; }
else {
die
"$progname: could not figure out how to quote the mbox filename \"$file\"\n";
}
my $reader = $mailreader;
$reader =~ s/\%([%s])/$1 eq '%' ? '%' : $quotedfile/eg;
if (system($reader) >> 8 != 0) {
warn "Problem running mail reader: $!\n";
}
}
# Timestamp handling
#
# We store a +ve timestamp to represent an automatic download and
# a -ve one to represent a manual download.
sub get_timestamp {
my $thing = shift;
my $thgopts = shift || '';
my $timestamp = undef;
my $versionstamp = undef;
if (tied %timestamp) {
($timestamp, $versionstamp) = split /;/,
$timestamp{ $thing . $thgopts }
if exists $timestamp{ $thing . $thgopts };
} else {
tie(%timestamp, "Devscripts::DB_File_Lock", $timestampdb,
O_RDONLY(), 0600, $DB_HASH, "read")
or die
"$progname: couldn't open DB file $timestampdb for reading: $!\n";
($timestamp, $versionstamp) = split /;/,
$timestamp{ $thing . $thgopts }
if exists $timestamp{ $thing . $thgopts };
untie %timestamp;
}
return wantarray ? ($timestamp, $versionstamp) : $timestamp;
}
sub set_timestamp {
my $thing = shift;
my $thgopts = shift || '';
my $timestamp = shift;
my $versionstamp = shift || $version;
if (tied %timestamp) {
$timestamp{ $thing . $thgopts } = "$timestamp;$versionstamp";
} else {
tie(%timestamp, "Devscripts::DB_File_Lock", $timestampdb,
O_RDWR() | O_CREAT(),
0600, $DB_HASH, "write")
or die
"$progname: couldn't open DB file $timestampdb for writing: $!\n";
$timestamp{ $thing . $thgopts } = "$timestamp;$versionstamp";
untie %timestamp;
}
}
sub delete_timestamp {
my $thing = shift;
my $thgopts = shift || '';
if (tied %timestamp) {
delete $timestamp{ $thing . $thgopts };
} else {
tie(%timestamp, "Devscripts::DB_File_Lock", $timestampdb,
O_RDWR() | O_CREAT(),
0600, $DB_HASH, "write")
or die
"$progname: couldn't open DB file $timestampdb for writing: $!\n";
delete $timestamp{ $thing . $thgopts };
untie %timestamp;
}
}
sub is_manual {
return $_[0] < 0;
}
sub make_manual {
return -abs($_[0]);
}
sub is_automatic {
return $_[0] > 0;
}
sub make_automatic {
return abs($_[0]);
}
# Returns true if current cached version is older than critical version
# We're only using really simple version numbers here: a.b.c
sub old_cache_format_version {
my $cacheversion = $_[0];
my @cache = split /\./, $cacheversion;
my @new = split /\./, $new_cache_format_version;
push @cache, 0, 0, 0, 0;
push @new, 0, 0;
return
($cache[0] < $new[0])
|| ($cache[0] == $new[0] && $cache[1] < $new[1])
|| ($cache[0] == $new[0] && $cache[1] == $new[1] && $cache[2] < $new[2])
|| ( $cache[0] == $new[0]
&& $cache[1] == $new[1]
&& $cache[2] == $new[2]
&& $cache[3] < $new[3]);
}
# We would love to use LWP::Simple::mirror in this script.
# Unfortunately, bugs.debian.org does not respect the
# If-Modified-Since header. For single bug reports, however,
# bugreport.cgi will return a Last-Modified header if sent a HEAD
# request. So this is a hack, based on code from the LWP modules. :-(
# Return value:
# (return value, error string)
# with return values: MIRROR_ERROR failed
# MIRROR_DOWNLOADED downloaded new version
# MIRROR_UP_TO_DATE up-to-date
sub bts_mirror {
my ($url, $timestamp, $force) = @_;
init_agent() unless $ua;
if ($url =~ m%/\d+$% and !$refreshmode and !$force) {
# Single bug, worth doing timestamp checks
my $request = HTTP::Request->new('HEAD', $url);
my $response = $ua->request($request);
if ($response->is_success) {
# TODO: Debbugs replaced Last-Modified with ETag.
# See https://salsa.debian.org/debbugs-team/debbugs/61c42ddd
my $lm = $response->last_modified;
if (defined $lm and $lm <= abs($timestamp)) {
return (MIRROR_UP_TO_DATE, $response->status_line);
}
} else {
return (MIRROR_ERROR, $response->status_line);
}
}
# So now we download the full thing regardless
# We don't care if we scotch the contents of $file - it's only
# a temporary file anyway
my $request = HTTP::Request->new('GET', $url);
my $response = $ua->request($request);
if ($response->is_success) {
# This check from LWP::UserAgent; I don't even know whether
# the BTS sends a Content-Length header...
my $nominal_content_length = $response->content_length || 0;
my $true_content_length
= defined $response->content ? length($response->content) : 0;
if ($true_content_length == 0) {
return (MIRROR_ERROR, $response->status_line);
}
if ($nominal_content_length > 0) {
if ($true_content_length < $nominal_content_length) {
return (MIRROR_ERROR,
"Transfer truncated: only $true_content_length out of $nominal_content_length bytes received"
);
}
if ($true_content_length > $nominal_content_length) {
return (MIRROR_ERROR,
"Content-length mismatch: expected $nominal_content_length bytes, got $true_content_length"
);
}
# else OK
}
return (
MIRROR_DOWNLOADED, $response->status_line,
$response->content, $response->header('Content-Type'));
} else {
return (MIRROR_ERROR, $response->status_line);
}
}
sub init_agent {
$ua = new LWP::UserAgent; # we create a global UserAgent object
$ua->agent("LWP::UserAgent/Devscripts/$version");
$ua->env_proxy;
}
sub opts_done {
if (@_) {
die "$progname: unknown options to '$shortcmd[$index]': @_\n";
}
}
sub edit {
my $message = shift;
my ($fh, $filename);
($fh, $filename) = tempfile(
"btsXXXX",
SUFFIX => ".mail",
DIR => File::Spec->tmpdir
);
open(OUT_MAIL, ">$filename")
or die "$progname: writing to temporary file: $!\n";
print OUT_MAIL $message;
close OUT_MAIL;
my $rv = system("sensible-editor $filename </dev/tty") >> 8;
undef $message;
if ($rv == 0) {
open(OUT_MAIL, "<$filename")
or die "$progname: reading from temporary file: $!\n";
while (<OUT_MAIL>) {
$message .= $_;
}
close OUT_MAIL;
}
unlink($filename);
return $message;
}
=back
=head1 ENVIRONMENT VARIABLES
=over 4
=item B<DEBEMAIL>
If this is set, the From: line in the email will be set to use this email
address instead of your normal email address (as would be determined by
B<mail>).
=item B<DEBFULLNAME>
If B<DEBEMAIL> is set, B<DEBFULLNAME> is examined to determine the full name
to use; if this is not set, B<bts> attempts to determine a name from
your F<passwd> entry.
=item B<BROWSER>
If set, it specifies the browser to use for the B<show> and B<bugs>
options. See L<sensible-brower(1)>.
=back
=head1 CONFIGURATION VARIABLES
The two configuration files F</etc/devscripts.conf> and
F<~/.devscripts> are sourced by a shell in that order to set
configuration variables. Command-line options can be used to override
configuration file settings. Environment variable settings are
ignored for this purpose. The currently recognised variables are:
=for comment TODO: Replace "Same as ..." with more explicit "Overidden by ..."
=over 4
=item B<BTS_OFFLINE>
If this is set to B<yes>, then it is the same as the B<--offline> command
line parameter being used. Only has an effect on the B<show> and B<bugs>
commands. The default is B<no>. See the description of the B<show>
command above for more information.
=item B<BTS_CACHE>
If this is set to B<no>, then it is the same as the B<--no-cache> command
line parameter being used. Only has an effect on the B<show> and B<bug>
commands. The default is B<yes>. Again, see the B<show> command above
for more information.
=item B<BTS_CACHE_MODE=>{B<min>,B<mbox>,B<full>}
How much of the BTS should we mirror when we are asked to cache something?
Just the minimum, or also the mbox or the whole thing? The default is
B<min>, and it has the same meaning as the B<--cache-mode> command-line
parameter. Only has an effect on the cache. See the B<cache> command for more
information.
=item B<BTS_FORCE_REFRESH>
If this is set to B<yes>, then it is the same as the B<--force-refresh>
command-line parameter being used. Only has an effect on the B<cache>
command. The default is B<no>. See the B<cache> command for more
information.
=item B<BTS_WORKFLOW>={B<mail>,B<web>}
Set the default I<Workflow Mode>. Overidden by "Workflow Mode Options"
B<--mail> and B<--web>, see B<OPTIONS>. See also "Workflows" in
B<DESCRIPTION>.
When set to B<mail> unlocks implicit enablement of B<--mutt>.
=item B<BTS_MAIL_READER>
Interactive command-line mail client (MUA) to use for reading mailbox files
when using the mail workflow (B<--mail>, B<BTS_WORKFLOW=mail>).
Default depends on mailreaders avalable on the system. The following are
tried in order (first match wins):
=over 2
=item * A (supported) MUA B<bts> is running inside of as determined by
examining $_, the 'underscore' environment variable).
=item * 'B<mutt -f %s>' -- if mutt is installed,
=item * 'B<neomutt -f %s>' -- if neomutt is installed,
=item * 'B<aerc -I mbox:%s>' -- if B<bts> is invoked from inside B<aerc>,
=item * 'B<aerc mbox:%s>' -- if aerc is installed otherwise.
=back
Can be overridden by B<--mailreader> command-line option.
The 'B<%s>' is replaced by the path to an MBOX file.
=item B<BTS_MUTT_COMMAND>
Interactive command-line mail client (MUA) to use for interactively
composing and sending mails when B<--mutt> is active or implied.
Default depends on mail clients avalable on the system. The following are
tried in order:
=over 2
=item * A supported MUA B<bts> is running inside of as determined by
examining $_, the 'underscore' environment variable).
=item * 'B<mutt -H %s>' -- if mutt is installed,
=item * 'B<neomutt -H %s>' -- if neomutt is installed,
=back
The 'B<%s>' is replaced by the path to a raw draft email message file
including headers.
=item B<BTS_SENDMAIL_COMMAND>
If this is set, specifies a B<sendmail> command to use instead of
F</usr/sbin/sendmail>. Same as the B<--sendmail> command-line option.
=item B<BTS_ONLY_NEW>
Download only new bugs when caching. Do not check for updates in
bugs we already have. The default is B<no>. Same as the B<--only-new>
command-line option.
=item B<BTS_SMTP_HOST>
If this is set, specifies an SMTP host to use for sending mail rather
than using the B<sendmail> command. Same as the B<--smtp-host> command-line
option.
Note that this option takes priority over B<BTS_SENDMAIL_COMMAND> if both are
set, unless the B<--sendmail> option is used.
=item B<BTS_SMTP_REPORTBUG>
If set to B<yes> use Debian's open submission reportbug.debian.org SMTP
server to send bug reports and change requests. No account registration or
authentication is needed but submissions are rate-limited to a couple per
hour.
If set to B<yes> it is equivalent to setting both
B<BTS_SMTP_HOST>=reportbug.debian.org:587 and B<BTS_INTERACTIVE>=yes.
=item B<BTS_SMTP_AUTH_USERNAME>, B<BTS_SMTP_AUTH_PASSWORD>
If these options are set, then it is the same as the B<--smtp-username> and
B<--smtp-password> options being used.
=item B<BTS_SMTP_HELO>
Same as the B<--smtp-helo> command-line option.
=item B<BTS_INCLUDE_RESOLVED>
If this is set to B<no>, then it is the same as the B<--no-include-resolved>
command-line parameter being used. Only has an effect on the B<cache>
command. The default is B<yes>. See the B<cache> command for more
information.
=item B<BTS_SUPPRESS_ACKS>
If this is set to B<yes>, then it is the same as the B<--no-ack> command
line parameter being used. The default is B<no>.
=item B<BTS_INTERACTIVE>
If this is set to B<yes> or B<force>, then it is the same as the
B<--interactive> or B<--force-interactive> command-line parameter being used.
The default is B<no>.
=item B<BTS_DEFAULT_CC>
Specify a list of e-mail addresses to which a carbon copy of the generated
e-mail to the control bot should automatically be sent.
=item B<BTS_SERVER>
Specify the name of a debbugs server which should be used instead of
https://bugs.debian.org.
=back
=head1 SEE ALSO
Please see L<https://www.debian.org/Bugs/server-control> for
more details on how to control the BTS using emails and
L<https://www.debian.org/Bugs/> for more information about the BTS.
querybts(1), reportbug(1), pts-subscribe(1), devscripts.conf(5)
=head1 COPYRIGHT
This program is Copyright (C) 2001-2003 by Joey Hess <joeyh@debian.org>.
Many modifications have been made, Copyright (C) 2002-2005 Julian
Gilbey <jdg@debian.org> and Copyright (C) 2007 Josh Triplett
<josh@freedesktop.org>.
It is licensed under the terms of the GPL, either version 2 of the
License, or (at your option) any later version.
=cut
# Please leave this alone unless you understand the seek above.
__DATA__
|