Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7412455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:32:33+00:00 2026-05-29T06:32:33+00:00

POP Servers allow for the LIST command that returns a list of all of

  • 0

POP Servers allow for the LIST command that returns a list of all of the emails in the mail box. Unfortunately it does not return ALL of the emails, it only returns the emails from the Inbox. So if an email lands in a junk folder it cannot find it.

Is it possible to download emails from the junk folder using POP?

This is the current class(s) that I am using:

Option Strict On
Option Explicit On
Imports System.Net, System.Text
Public Class POP3
    Inherits Sockets.TcpClient

    Dim Stream As Sockets.NetworkStream
    Dim UsesSSL As Boolean = False
    Dim SslStream As Security.SslStream
    Dim SslStreamDisposed As Boolean = False
    Public LastLineRead As String = vbNullString

    Public Overloads Sub Connect(ByVal Server As String, ByVal Username As String, ByVal Password As String, Optional ByVal InPort As Integer = 110,Optional ByVal UseSSL As Boolean = False)
        If Connected Then Disconnect()
        UsesSSL = UseSSL
        MyBase.Connect(Server, InPort)
        Stream = MyBase.GetStream
        If UsesSSL Then
            SslStream = New Security.SslStream(Stream)
            SslStream.AuthenticateAsClient(Server)
        End If

        If Not CheckResponse() Then Exit Sub

        If CBool(Len(Username)) Then
            Me.Submit("USER " & Username & vbCrLf)
            If Not CheckResponse() Then Exit Sub
        End If

        If CBool(Len(Password)) Then
            Me.Submit("PASS " & Password & vbCrLf)
            If Not CheckResponse() Then Exit Sub
        End If
    End Sub

    Public Function CheckResponse() As Boolean
        If Not IsConnected() Then Return False
        LastLineRead = Me.Response
        If (Left(LastLineRead, 3) <> "+OK") Then
            Throw New POP3Exception(LastLineRead)
            Return False
        End If
        Return True
    End Function

    Public Function IsConnected() As Boolean
        If Not Connected Then
            Throw New POP3Exception("Not Connected to an POP3 Server.")
            Return False
        End If
        Return True
    End Function


    Public Function Response(Optional ByVal dataSize As Integer = 1) As String
        Dim enc As New ASCIIEncoding
        Dim ServerBufr() As Byte
        Dim Index As Integer = 0
        If dataSize > 1 Then

            ReDim ServerBufr(dataSize - 1)
            Dim dtsz As Integer = dataSize
            Dim sz As Integer
            Do While Index < dataSize
                If UsesSSL Then
                    sz = SslStream.Read(ServerBufr, Index, dtsz)
                Else
                    sz = Stream.Read(ServerBufr, Index, dtsz)
                End If
                If sz = 0 Then Return vbNullString
                Index += sz
                dtsz -= sz
            Loop
        Else
            ReDim ServerBufr(255)
            Do
                If UsesSSL Then
                    ServerBufr(Index) = CByte(SslStream.ReadByte)
                Else
                    ServerBufr(Index) = CByte(Stream.ReadByte)
                End If
                If ServerBufr(Index) = -1 Then Exit Do
                Index += 1
                If ServerBufr(Index - 1) = 10 Then Exit Do
                If Index > UBound(ServerBufr) Then
                    ReDim Preserve ServerBufr(Index + 255)
                End If
            Loop
        End If
        Return enc.GetString(ServerBufr, 0, Index)
    End Function

    Public Sub Submit(ByVal message As String)
        Dim enc As New ASCIIEncoding
        Dim WriteBuffer() As Byte = enc.GetBytes(message)
        If UsesSSL Then
            SslStream.Write(WriteBuffer, 0, WriteBuffer.Length)
        Else
            Stream.Write(WriteBuffer, 0, WriteBuffer.Length)
        End If
    End Sub

    Public Sub Disconnect()
        Me.Submit("QUIT" & vbCrLf)
        CheckResponse()
        If UsesSSL Then
            SslStream.Dispose()
            SslStreamDisposed = True
        End If
    End Sub

    '*******************************************************************************
    ' Function Name : List
    ' Purpose       : Get the drop listing from the maildrop
    '               :
    ' Returns       : Any Arraylist of POP3Message objects
    '               :
    ' Typical telNet I/O:
    'LIST            (submit)
    '+OK Mailbox scan listing follows
    '1 2532          (record index and size in bytes)
    '2 1610
    '3 12345
    '.               (end of records terminator)
    '*******************************************************************************
    Public Function List() As ArrayList
        If Not IsConnected() Then Return Nothing 'exit if not in TRANSACTION mode

        Me.Submit("LIST" & vbCrLf)                          'submit List request
        If Not CheckResponse() Then Return Nothing 'check for a response, but if an error, return nothing
        '
        'get a list of emails waiting on the server for the authenticated user
        '
        Dim retval As New ArrayList                         'set aside message list storage
        Do
            Dim response As String = Me.Response            'check response
            If (response = "." & vbCrLf) Then               'done with list?
                Exit Do                                     'yes
            End If
            Dim msg As New POP3Message                      'establish a new message
            Dim msgInfo() As String = Split(response, " "c) 'separate by spaces, which divide its fields
            msg.MailID = Integer.Parse(msgInfo(0))          'get the list item number
            msg.ByteCount = Integer.Parse(msgInfo(1))           'get the size of the email message
            msg.Retrieved = False                           'indicate its message body is not yet retreived
            retval.Add(msg)                                 'add a new entry into the retrieval list
        Loop
        Return retval                                       'return the list
    End Function


    Public Function GetHeader(ByRef msg As POP3Message, Optional ByVal BodyLines As Integer = 0) As POP3Message
        If Not IsConnected() Then Return Nothing
        Me.Submit("TOP " & msg.MailID.ToString & " " & BodyLines.ToString & vbCrLf)
        If Not CheckResponse() Then Return Nothing
        msg.Message = vbNullString
        Do
            Dim response As String = Me.Response
            If response = "." & vbCrLf Then
                Exit Do
            End If
            msg.Message &= response
        Loop
        Return msg
    End Function

    Public Function Retrieve(ByRef msg As POP3Message) As POP3Message
        If Not IsConnected() Then Return Nothing
        Me.Submit("RETR " & msg.MailID.ToString & vbCrLf)
        If Not CheckResponse() Then Return Nothing
        msg.Message = Me.Response(msg.ByteCount)
        Do
            Dim S As String = Response()
            If S = "." & vbCrLf Then
                Exit Do
            End If
            msg.Message &= S
        Loop
        msg.ByteCount = Len(msg.Message)
        Return msg
    End Function

    Public Sub Delete(ByVal msgHdr As POP3Message)
        If Not IsConnected() Then Exit Sub
        Me.Submit("DELE " & msgHdr.MailID.ToString & vbCrLf)
        CheckResponse()
    End Sub

    Public Sub Reset()
        If Not IsConnected() Then Exit Sub
        Me.Submit("RSET" & vbCrLf)
        CheckResponse()
    End Sub

    Public Function NOOP() As Boolean
        If Not IsConnected() Then Return False
        Me.Submit("NOOP")
        Return CheckResponse()
    End Function

    Protected Overrides Sub Finalize()
        If Not SslStreamDisposed Then
            SslStream.Dispose()
        End If
        MyBase.Finalize()
    End Sub
End Class

Public Class POP3Message
    Public MailID As Integer = 0
    Public ByteCount As Integer = 0
    Public Retrieved As Boolean = False
    Public Message As String = vbNullString

    Public Overrides Function ToString() As String
        Return Message
    End Function
End Class

Public Class POP3Exception
    Inherits ApplicationException

    Public Sub New(ByVal str As String)
        MyBase.New(str)
    End Sub
End Class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:32:34+00:00Added an answer on May 29, 2026 at 6:32 am

    As per the comments, the POP3 standard only allows for downloading from the “Inbox”. It’s not designed for anything more advanced.

    The ideal solution would be to use IMAP4, if the mail server supports it.

    IMAP4 allows you to save, flag, copy and delete messages, as well as allowing folders and subfolders and it does not require exclusive access.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to pop up a dialog box that says Saving... and once the
Does anyone know how can I create a pop-up message box in server side,
Say I am 1000 pop emails that I have to pull emails from. I
I'm seeing it pop up more and more and not really understanding the purpose
I have a pop up form that i wish to close on successfull submit
I'm looking for a library that will allow me to deliver simple text events
Does python have a full fledged email library with things for pop, smtp, pop3
Answer: I know this is not the kind of thing that goes well as
Q: I want to list the most used modal pop up in asp.net to
One of the views on my MVC web app has URLs that allow users

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.