Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Usenet NNTP Post Canceller

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Usenet NNTP Post Canceller

    A simple tool to delete usenet posts. Just copy the header of the post you want to delete (just the header, nothing more) into the main textbox and click the Do It button.

    When you cancel a post you are basically just sending the original header, but with "X-Cancelled-by" and "Control: cancel" fields added to the header.

    Not all NNTP servers will allow you to delete posts.

    Code:
    #COMPILE EXE
    #INCLUDE "WIN32API.INC"
    
    GLOBAL hDlg1 AS LONG
    
    %DIALOG1  =  101
    %LABEL1   = 1001
    %TEXTBOX1 = 1002
    %LABEL2   = 1003
    %TEXTBOX2 = 1004
    %BUTTON1  = 1005
    
    DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
    DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
    
    DECLARE SUB DoCancelPost
    $AppTitle = "NNTP Canceller"
    
    FUNCTION PBMAIN()
        ShowDIALOG1 %HWND_DESKTOP
    END FUNCTION
    
    CALLBACK FUNCTION ShowDIALOG1Proc()
        SELECT CASE AS LONG CBMSG
            CASE %WM_NCACTIVATE
                STATIC hWndSaveFocus AS DWORD
                IF ISFALSE CBWPARAM THEN  ' Save control focus
                    hWndSaveFocus = GetFocus()
                ELSEIF hWndSaveFocus THEN ' Restore control focus
                    SetFocus(hWndSaveFocus): hWndSaveFocus = 0
                END IF
            CASE %WM_COMMAND
                SELECT CASE AS LONG CBCTL
                    CASE %BUTTON1
                        IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                            DoCancelPost
                        END IF
                END SELECT
        END SELECT
    END FUNCTION
    
    FUNCTION GetField(sTxt AS STRING, sField AS STRING) AS STRING
    LOCAL i1 AS LONG, i2 AS LONG, lLen AS LONG
    lLen = LEN(sField)
    i1 = INSTR(1, sTxt, sField)
    i2 = INSTR(i1, sTxt, CHR$(13))
    FUNCTION = TRIM$(MID$(sTxt, i1 + lLen, i2 - i1 - lLen))
    END FUNCTION
    
    SUB DoCancelPost
    LOCAL Buffer$, hTCP AS LONG, i1 AS LONG, i2 AS LONG, sTxt AS STRING, sTmp AS STRING, sxFrom AS STRING, sxGroups AS STRING, sxSubject AS STRING, sxMsgID AS STRING, sxAgent AS STRING, sServer AS STRING, sOut AS STRING
    CONTROL GET TEXT hDlg1, %TEXTBOX1 TO sTxt
    CONTROL GET TEXT hDlg1, %TEXTBOX2 TO sServer
    sxFrom = GetField(sTxt, "From:")
    sxGroups = GetField(sTxt, "Newsgroups:")
    sxSubject = GetField(sTxt, "Subject:")
    sxMsgID = GetField(sTxt, "Message-ID:")
    sxAgent = GetField(sTxt, "X-HTTP-UserAgent:")
    sOut = "From: " & sxFrom & $CRLF & _
        "Approved: " & sxFrom & $CRLF & _
        "X-Cancelled-by: " & sxFrom & $CRLF & _
        "Control: cancel " & sxMsgID & $CRLF & _
        "Subject: cmsg cancel " & sxMsgID & $CRLF & _
        "Newsgroups: " & sxGroups & $CRLF & _
        "X-HTTP-UserAgent: " & sxAgent & $CRLF & $CRLF & _
        "cancel " & sxMsgID & $CRLF & $CRLF & $CRLF & "." & $CRLF
    hTCP = FREEFILE
    DIALOG SET TEXT hDlg1, "Connecting to server ..."
    TCP OPEN PORT 119 AT sServer AS hTCP TIMEOUT 6000
    IF ERR THEN    'Could we connect?
        MSGBOX "ERROR - Couldnt connect to " & sServer & ":119"
        DIALOG SET TEXT hDlg1, $AppTitle
        EXIT SUB
    END IF
    TCP RECV hTCP, 4096, Buffer$
    DIALOG SET TEXT hDlg1, "Connected. Cancelling the post ..."
    TCP SEND hTCP, "MODE READER" & $CRLF
    TCP RECV hTCP, 4096, Buffer$
    TCP SEND hTCP, "POST" & $CRLF
    TCP RECV hTCP, 4096, Buffer$
    TCP SEND hTCP, sOut
    TCP SEND hTCP, $CRLF & "." & $CRLF
    TCP RECV hTCP, 4096, Buffer$
    TCP CLOSE hTCP
    MSGBOX "Reply from server:" & $CRLF & Buffer$, %MB_OK + %MB_ICONINFORMATION, "Finished"
    DIALOG SET TEXT hDlg1, $AppTitle
    END SUB
    
    FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
        LOCAL lRslt AS LONG
        LOCAL hDlg  AS DWORD
        DIALOG NEW hParent, "NNTP Post Canceller", 70, 70, 306, 238, %WS_POPUP OR _
            %WS_BORDER OR %WS_DLGFRAME OR %WS_CAPTION OR %WS_SYSMENU OR _
            %WS_MINIMIZEBOX OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME _
            OR %DS_SETFOREGROUND OR %DS_CENTER OR %DS_3DLOOK OR %DS_NOFAILCREATE _
            OR %DS_SETFONT, %WS_EX_WINDOWEDGE OR %WS_EX_CONTROLPARENT OR _
            %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
        CONTROL ADD LABEL,   hDlg, %LABEL1, "Post header:", 5, 5, 190, 10
        CONTROL ADD TEXTBOX, hDlg, %TEXTBOX1, "Copy the full header of the post " + _
            "here ...", 5, 15, 295, 200, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP _
            OR %WS_HSCROLL OR %WS_VSCROLL OR %ES_LEFT OR %ES_MULTILINE OR _
            %ES_AUTOHSCROLL OR %ES_WANTRETURN, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT _
            OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR
        CONTROL ADD LABEL,   hDlg, %LABEL2, "NNTP Server:", 5, 220, 55, 10
        CONTROL ADD TEXTBOX, hDlg, %TEXTBOX2, "", 65, 219, 180, 12
        CONTROL ADD BUTTON,  hDlg, %BUTTON1, "Do it", 255, 219, 45, 12
        hDlg1 = hDlg
        DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
        FUNCTION = lRslt
    END FUNCTION
    Last edited by Wayne Diamond; 18 Jun 2008, 12:34 AM.
    -
Working...
X