libcurl.pbi

Share your advanced PureBasic knowledge/code with the community.
flashbob
User
User
Posts: 92
Joined: Sat May 11, 2024 4:04 pm

Re: libcurl.pbi

Post by flashbob »

... of course it's just a simple example ;-)

When I look at the commands regarding POP3 (see also links below), libcurl's functionality seems to be limited here. According to my research so far, even in C/C++ there is no example for retrieving all emails at once without logging into the server for each mail.

Even Stenberg's manual does not provide any useful information here.

After you maintain this topic, you might have a tip for an example in C, C++, PHP or a corresponding link ?


https://everything.curl.dev/usingcurl/reademail.html
https://curl.se/libcurl/c/example.html
https://github.com/curl/curl/tree/master/docs/examples
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: libcurl.pbi

Post by infratec »

I only provide the access to the libcurl commands.

But ...

you can do multiple curl_easy_perform() after an other.
login should be only done once.

So first get the list of ids, then do a loop with

Code: Select all

ForEach IndexList()
 curl_easy_setopt(curl, #CURLOPT_URL, "pop3://pop.example.com/" + str(IndexList()))
 curl_easy_perform()
 ...
Next
flashbob
User
User
Posts: 92
Joined: Sat May 11, 2024 4:04 pm

Re: libcurl.pbi

Post by flashbob »

Thanks for the info.

Your example shows normal usage of curl_easy. This works for me too (runs in its own thread).
The Problem: Every time you receive a message, a new login is performed (see code below).

Code: Select all

curl = curl_easy_init()
If curl
  ; Set username and password
  curl_easy_setopt_str(curl, #CURLOPT_USERNAME, User$)                            ; **** Login (every time in loop)
  curl_easy_setopt_str(curl, #CURLOPT_PASSWORD, Password$)               
  curl_easy_setopt_str(curl, #CURLOPT_URL, Url$ + "/" + Str(MsgNum))
  ...
  res = curl_easy_perform(curl)
  If res = #CURLE_OK
    ...
  endif
  curl_easy_cleanup(curl)
endif  
My idea was to log into the server once and then retrieve all emails without having to re-authenticate.
I think when using curl_easy there is no other way to bypass the repeated login...
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: libcurl.pbi

Post by infratec »

I see no loop in your code.

The loop needs to be inside your If curl after your settings.

Look in my code snippet above.
flashbob
User
User
Posts: 92
Joined: Sat May 11, 2024 4:04 pm

Re: libcurl.pbi

Post by flashbob »

That is clear. This shouldn't be the complete code with loop, but just show that a login is required every time you use curl_easy...

but thanks for the info...
User avatar
HeX0R
Addict
Addict
Posts: 1189
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: libcurl.pbi

Post by HeX0R »

I don't want to hijack this thread, but maybe this is an alternative:
viewtopic.php?t=51959
flashbob
User
User
Posts: 92
Joined: Sat May 11, 2024 4:04 pm

Re: libcurl.pbi

Post by flashbob »

Hi HeXOR,
thanks for the information, I know the thread and your code works really fine on windows - good stuff!

I used libcurl because my application runs on Windows and MAC and I didn't find the necessary libs for libTLS for MAC ;-)
Furthermore libcurl is part of macOS... and I didn't want to compile the libs myself ;-)

So at the moment my program (Pop3) is running fine under Windows/Mac, but from my point of view the performance of
libcurl (curl_easy function) has potential for improvement. That's why I asked here if there is another way for (faster) retrieval of emails.

Maybe I find a corresponding example under C or PHP that I can adapt.
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: libcurl.pbi

Post by infratec »

libcurl dlls updated to 8.11.0
User avatar
le_magn
Enthusiast
Enthusiast
Posts: 277
Joined: Wed Aug 24, 2005 12:11 pm
Location: Italia

Re: libcurl.pbi

Post by le_magn »

Hi Infratec, could you show me an example of how to monitor the progress of a file download? thanks
Image
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: libcurl.pbi

Post by infratec »

Added DownloadProgress.pb

You can use PostEvents to update a main program.
User avatar
le_magn
Enthusiast
Enthusiast
Posts: 277
Joined: Wed Aug 24, 2005 12:11 pm
Location: Italia

Re: libcurl.pbi

Post by le_magn »

infratec wrote: Mon Dec 02, 2024 10:31 pm Added DownloadProgress.pb

You can use PostEvents to update a main program.
thank you very much :)
Image
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: libcurl.pbi

Post by infratec »

Modified DownloadProgress.pb to show it with a ProgressBarGadget()
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: libcurl.pbi

Post by infratec »

Added an example:

FTPS_rename.pb
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: libcurl.pbi

Post by infratec »

libcurl dlls updated to 8.11.1
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: libcurl.pbi

Post by infratec »

Added HTTP_gzip.pb

To show how a content can be downloaded witz gzip compression to reduce transmission data size.

Since the internal libcurl can not handle the compression, the external libcurl.dll is needed beside the executable.
Post Reply