Virtualmin outgoing email goes to spam folder - ubuntu-18.04

I have VPS at Hostwinds and I host my company website on it. I have an issue with outgoing email. Every email send to clients goes in their spam folder. In the header details I see that email authentication is PASS, but still goes in the spam folder. What worries me is one line in the middle of the header: Received: from mydomain.com (localhost [127.0.0.1]) . This is the email header:
SPF: PASS with IP 123.456.789.123 Learn more
DKIM: 'PASS' with domain mydomain.com Learn more
DMARC: 'PASS' Learn more
Delivered-To: myemail#gmail.com
Received: by 2002:a05:600c:2512:0:0:0:0 with SMTP id d18csp2849809wma;
Sun, 30 Aug 2020 09:10:26 -0700 (PDT)
X-Google-Smtp-Source: ABdhPJxJilweL27JR79vtPCAMzHED+3eOqm/43WBjywm9Kd1BZCpiPt5sizaAr5giUSayqvkRcbS
X-Received: by 2002:aca:724c:: with SMTP id p73mr1349454oic.123.1598803826168;
Sun, 30 Aug 2020 09:10:26 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1598803826; cv=none;
d=google.com; s=arc-20160816;
b=qq545ttDSaZHhFNhUHVv9MCEmFQSQoM68j8HFF5xYbaqp1a4Vid+LN6myAkFMqY5IU
9RRNQekRExzrHcegQ2cmaQ3NpR+b3+xeu/GakXnLzJGGvLx6zjgGWcI757gc3G/DEDs+
CsmEB3J36wg91suAG6SKtfCexvuaQuOYO2fNbd1NysGtwsJjarnj5ilieh3ut6ReWu8N
PzcMjaJ2zbQHXUkBxgM1AG03UhbSXlypmeQJOEXnems8pPL+ytVVFuDLTSY6h3AnQ5Sl
770f+tjhFW01y++ftZp0n5MWNQAf9SNUxiYD/NRFT+1d523qLJulz2+md1bKCjRjBbBJ
Z5PQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
h=content-transfer-encoding:message-id:user-agent:subject:to:from
:date:mime-version:dkim-signature:dkim-filter;
bh=/uVZaDgKu5ckl+oayfwbuWWkFIHwnJbHWiyokjkFpqY=;
b=d5uFkvhfbgQ2TtnJLGmixBQafE5xQs73bQFh+BL403zno5b9qH77VavUQu+tp4spgA
0tHMLoTvJOzhOrnrPKBoWkYxyThOtNCcCG2sN9uqPEK1lZbFRFrbKf7FqUsNDQQNODJd
lQ7RAOVXS3zJjJle8el7sQuXw0CBTF8zM0TTQoPFJ7735YmtUkkBQwaZyhKi8HP0sBxn
51I4FBrJtUHJWB1mBeidqChrhd26WtFtaKDVcrquSljdOZ8Zdi6CDhP0N8DVwSYX6kNg
1fvJ1S/LPICGWm/wEnpkqWcp52egWbNYU94yGstuGUnsxGVCEyu5QyzoboLUfuGLPMEi
mpbw==
ARC-Authentication-Results: i=1; mx.google.com;
dkim=pass header.i=#mydomain.com header.s=default header.b=qWoCXeE4;
spf=pass (google.com: domain of John#mydomain.com designates 123.456.789.123 as permitted sender) smtp.mailfrom=John#mydomain.com;
dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mydomain.com
Return-Path: <John#mydomain.com>
Received: from hwsrv-myserver.hostwindsdns.com (hwsrv-myserver.hostwindsdns.com. [123.456.789.123])
by mx.google.com with ESMTPS id n9si3239879otq.34.2020.08.30.09.10.26
for <myemail#gmail.com>
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Sun, 30 Aug 2020 09:10:26 -0700 (PDT)
Received-SPF: pass (google.com: domain of John#mydomain.com designates 123.456.789.123 as permitted sender) client-ip=123.456.789.123;
Authentication-Results: mx.google.com;
dkim=pass header.i=#mydomain.com header.s=default header.b=qWoCXeE4;
spf=pass (google.com: domain of John#mydomain.com designates 123.456.789.123 as permitted sender) smtp.mailfrom=John#mydomain.com;
dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mydomain.com
Received: from mydomain.com (localhost [127.0.0.1]) by hwsrv-myserver.hostwindsdns.com (Postfix) with ESMTPA id C34505000C6D for <myemail#gmail.com>; Sun, 30 Aug 2020 16:10:25 +0000 (UTC)
DKIM-Filter: OpenDKIM Filter v2.11.0 hwsrv-myserver.hostwindsdns.com C34505000C6D
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mydomain.com; s=default; t=1598803825; bh=/uVZaDgKu5ckl+oayfwbuWWkFIHwnJbHWiyokjkFpqY=; h=Date:From:To:Subject:From; b=qWoCXeE4l55YNaNV6k/kr6ySb+dTmHNKlAa3lESHfvUEJ5g47cb8DaeF6uav2moaQ
qrh8aHMKqNsWumx6R7poQ/jD3pTrTdZGRsxBdwdwE4P1qtexOrBLlRrxo9FRsMn8lD
TE/U7mhJ6l1gkBv6pY/pqV+/yJoZaBOxl/4H7DK3I8MFannGYVfivz1uA6O78OSjKD
kIacp+k3W7CV42l9yn6VwPFJmKqqdLlfitZ3esLFcw7ygzvXx37YeSL0ljEkcUh3CJ
APEwG0gE/sQfo/VvF31urzNzHvkuU+yMQSitRXnVpkxrxHvbpwjv+07Z0CmSxkFmbI
KOds89R71FL2Q==
MIME-Version: 1.0
Date: Sun, 30 Aug 2020 11:10:25 -0500
From: "John-mydomain.com" <John#mydomain.com>
To: myemail#gmail.com
Subject: Test email again
User-Agent: Roundcube Webmail/1.4.8
Message-ID: <493106b566f97bb7a4e314e4334ce685#mydomain.com>
X-Sender: John#mydomain.com
Content-Type: text/plain; charset=US-ASCII; format=flowed
Content-Transfer-Encoding: 7bit
My host file contains the following lines:
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
123.456.789.123 hwsrv-myserver.hostwindsdns.com hwsrv-myserver
Any help is highly appreciated.
Thank you.

It takes time to build IP reputation for an email server. I bet your email server new. use mx toolbox to see if your IP isn't blacklisted anywhere. Please ask your clients to mark your email as NOT SPAM. it will take some time, but it will go to the inbox eventually.

Related

Gmail API - getParts() returning null for yahoo messages

When reading email sent from an yahoo account, the method message.getPayload().getParts() returns null. Tested it with other domains (gmail, outlook, hotmail) and had no problem.
In fact, getPayload() returns a string without the "parts" field.
Any ideas?
Thanks.
Edit:
I'm using Java.
And that's an example of the raw message:
Delivered-To: ...#gmail.com
Received: by 10.25.38.80 with SMTP id m77csp2082720lfm;
Wed, 23 Aug 2017 11:21:52 -0700 (PDT)
X-Received: by 10.36.88.19 with SMTP id f19mr3619353itb.114.1503512512655;
Wed, 23 Aug 2017 11:21:52 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1503512512; cv=none;
d=google.com; s=arc-20160816;
b=hNlRtyLieEAxck27i5zZez/QG7M98ZOJjAHmzvMHPs/ON5G3TvtKm5IQ4SWxGef1bu
pMLtqt3u3ti8EmOoaGvIsWF8fkCEYWJNyTrm+AfVBIW/vWcaBO5C+/gU/2l8c1bz640/
cjGyUkfYH5P7eaA8Bn5qJqbGC6RN0jH99qP0keLCCXDEtD15pNUqWvlRy2cYthvxrApX
gwmB5RGoDHJxWym97ULj2jbXU8d2msM2oCTKsGKAYPfPUKxpmU9omE1fAPSd+0a2UuGo
qXviZ6r9ZOoj2UYeCulbLe2c8OaKXSPYT+j6OGSRQ/9KkM7122Mo3U7B30WdSm0steTO
cOPg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
h=references:content-transfer-encoding:mime-version:subject
:message-id:to:reply-to:from:date:dkim-signature
:arc-authentication-results;
bh=Tz5JmALH26W2NmpUut1b8KAtYumw1nslUgD+V4O7niU=;
b=GACDabh89djjl0DusVFNR6mcyoStwHcH311IyqNkxC/rAipc9kIVjaxJHetooodQ4/
TKBVH4N2mfLpeQSr0sFHILcnJWklC8K9ZMI11GVC1KMcvr0sdfSLBXZ2xXxkBq2aM/F9
1AmCJ3dLwsn6n7qoFUPKukpt1dJWTmU9OdWq2rdw5477Ol7ieXnnC2SX3K7GyD1fKDjV
/Skj6Q+vKDuNUzexuh1V4zTcuuAUM03VlG/gbrFjPrp3ABvnlzuV1/8nu4QdQte/h3Cz
HJUOikVOQHm7HPTHJQi91639k3/Nl/TvC8bPpWF56CwRxBfMTtRZDHJAzjymOqYNjndM
PL5g==
ARC-Authentication-Results: i=1; mx.google.com;
dkim=pass header.i=#yahoo.com header.s=s2048 header.b=n8P3/tJJ;
spf=pass (google.com: domain of ...#yahoo.com designates 66.163.190.61 as permitted sender) smtp.mailfrom=...#yahoo.com;
dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=yahoo.com
Return-Path: <...#yahoo.com>
Received: from sonic307-38.consmr.mail.ne1.yahoo.com (sonic307-38.consmr.mail.ne1.yahoo.com. [66.163.190.61])
by mx.google.com with ESMTPS id c132si2139994itc.196.2017.08.23.11.21.52
for <...#gmail.com>
(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
Wed, 23 Aug 2017 11:21:52 -0700 (PDT)
Received-SPF: pass (google.com: domain of ...#yahoo.com designates 66.163.190.61 as permitted sender) client-ip=66.163.190.61;
Authentication-Results: mx.google.com;
dkim=pass header.i=#yahoo.com header.s=s2048 header.b=n8P3/tJJ;
spf=pass (google.com: domain of ...#yahoo.com designates 66.163.190.61 as permitted sender) smtp.mailfrom=...#yahoo.com;
dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=yahoo.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1503512512; bh=Tz5JmALH26W2NmpUut1b8KAtYumw1nslUgD+V4O7niU=; h=Date:From:Reply-To:To:Subject:References:From:Subject; b=n8P3/tJJ46TZtkbxEu9p93hHodloAc938JlVtFNggsFDKOh1CXeELNzqwZpx2RpnlxKLg0mMIrSO+6ixFI2jQXpI2OEkMjMW+Lojz2f6MDRzktI24qeoHK6z0OODwEr13l8+NRFuvEgatiOoKG4nK/0ESYRYj6MK2580zYFdMO34vdAUKwS5c7+T7cNTbb2Ov3+zNP+kHVOnFTpxcYKeRvqnueRbJMAgu/zqNEb5uptfny/uv96oSj0qampNulxjw3RM+rXzGnDhzex/dKS3aKUxkaTA/C1Y/pK88Arp14BYh5SUwlY1IM8+ae/gFFYHQmcN4tD99+f6QZkL+U+nDA==
X-YMail-OSG: bU76A0cVM1mKMrarfFd.RRvN1pJLGQPGtympfd4w.3r6YP1PfmogV2hMIGfIjW3
p3.MJ5enUkT9dmftCW24yuYPZH4MhX2BJCXOQBBjVdpf4n7AWMev2Lg2V1l_yh9aivYy3lyFz2mp
E7B7QicUKsBZsDrLKZy6aj1p1SKMXTK2BaM1FLvw7geXcSVImhw8xoWaTjWwXgrTrKmZv4xl9Lfn
J17mHtiuK_aFBVuPTbneEqxexfSgqN.mZCJzHZYFUAOeU3U3dfVEYVxG8ohJK.rUNxEj2EgXdCg2
FZq.xcE.R9_.ghSDSm5GH3G2BkpEEQ95VGAyPXfhEmZMLDKf08zx5_6FM_npwflAYYnnlLNYDJ0j
bvuKIfPljJunLWdxSQvx3_RsKdlFrBXXR1umg41QuqzXlZs4C8FQBdgzNwPrhuGU_NoPKf.MAhCW
rJmi9RcDFfNENxetttsECz9TvDacjN3.Ij3z6cf3oVkKVNTM8coPQpv5iEYUtQ0PRt3Iay.g.dg-
-
Received: from sonic.gate.mail.ne1.yahoo.com by sonic307.consmr.mail.ne1.yahoo.com with HTTP; Wed, 23 Aug 2017 18:21:52 +0000
Date: Wed, 23 Aug 2017 18:17:51 +0000 (UTC)
From: ... <...#yahoo.com>
Reply-To: ... <...#yahoo.com>
To: "...#gmail.com" <...#gmail.com>
Message-ID: <843172102.808351.1503512271497#mail.yahoo.com>
Subject: =?UTF-8?Q?[Sala_de_semin=C3=A1rios]?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
References: <843172102.808351.1503512271497.ref#mail.yahoo.com>
X-Mailer: WebService/1.1.10451 YahooMailNeo Mozilla/5.0 (X11; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0
Content-Length: 53
Data: 01/01/1970
Hora: 11:30
Dura=C3=A7=C3=A3o: 00:30
This information might help. It appears there's a restriction in using Yahoo Mail unlike other domains.
Yahoo! Mail
Currently, accessing Yahoo! Mail mailbox messages via POP3 is
restricted to paying users of the Yahoo! Mail plus service. Other than
that, most parameters are similar to Gmail and Hotmail, except that
the user name should be just the account user name, thus without the #
character and the domain name.
$pop3 = new pop3_class;
$pop3->hostname = "pop.mail.yahoo.com";
$pop3->port = 995;
$pop3->tls = 1;
$user = "account";
$password = "account password";

How can I tell that the content of this URL is gzip-encoded?

I am downloading a Helm chart from https://kubernetes-charts.storage.googleapis.com/redis-0.5.1.tgz. (The fact that it is Redis or related to Helm or anything in particular is irrelevant to this question, which is just about things like Content-Encoding and so on.)
When I check its headers like this:
$ curl -H "Accept-Encoding: gzip" -I https://kubernetes-charts.storage.googleapis.com/redis-0.5.1.tgz
…I do not see a Content-Encoding header in the output, and the Content-Type is listed as being application/x-tar:
HTTP/1.1 200 OK
X-GUploader-UploadID: AEnB2UqBzSXfTToMAdMARXSjJeN0on3jaNY3u74eXcWfvqsOwRpi38Xc6T0XrrmY4otPeySaYRwXyHccHYtChoPAgFQwYZhQMhcpZRWtZURRANGdfRJoupI
Expires: Tue, 27 Jun 2017 00:21:59 GMT
Date: Mon, 26 Jun 2017 23:21:59 GMT
Cache-Control: public, max-age=3600
Last-Modified: Fri, 05 May 2017 03:03:41 GMT
ETag: "e4184c81a58fb731283847222a1f4005"
x-goog-generation: 1493953421241613
x-goog-metageneration: 1
x-goog-stored-content-encoding: identity
x-goog-stored-content-length: 3550
x-goog-meta-goog-reserved-file-mtime: 1493953414
Content-Type: application/x-tar
x-goog-hash: crc32c=bQHveg==
x-goog-hash: md5=5BhMgaWPtzEoOEciKh9ABQ==
x-goog-storage-class: STANDARD
Accept-Ranges: bytes
Content-Length: 3550
Server: UploadServer
Alt-Svc: quic=":443"; ma=2592000; v="39,38,37,36,35"
The resulting file, when downloaded, is a gzipped tar archive.
What is the proper way of programmatically detecting that the payload is in fact gzipped? Or is this a problem with the web server in question?
I think the server is misconfigured. Since .tgz is just abbreviation for .tar.gz it should get the content type application/gzip-
Content-Type: application/x-tar
this header tells you the type, but i'm not sure that's gzip
https://superuser.com/questions/901962/what-is-the-correct-mime-type-for-a-tar-gz-file
see accepted answer at
How to check if a file is gzip compressed? . for way to identify programmatically

Emails sent via GMail API are empty

I have been switching from Google App Engine MailServier to the GMail API recently and I'm running into a strange issue:
The emails are being sent out correctly, but on the recipients end the body is empty! (Subject is still there).
I'm creating HTML emails with optional attachments and encode them using the snippet from the GMail API docs:
I'm using the snippet from the GMail API docs to encode the email:
public static Message createMessageWithEmail(MimeMessage email)
throws MessagingException, IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
email.writeTo(baos);
String encodedEmail = Base64.encodeBase64URLSafeString(baos.toByteArray());
Message message = new Message();
message.setRaw(encodedEmail);
return message;
}
When looking into my "Sent" folder in GMail, I can see the message just fine (it is an HTML email body):
Received: from 889121556365-na05chj5g3il9flll2l3otqeh7q7ja22.apps.googleusercontent.com
named unknown
by gmailapi.google.com
with HTTPREST;
Thu, 18 Jun 2015 05:29:12 -0400
From: daniel.florey#gmail.com
To: daniel.florey#floreysoft.net
Message-Id: <CAHWc4t9o6gpRs_HT0Y8E1szJtDTwfSMS7OH+jVro-LiA1kBLJw#mail.gmail.com>
Subject: Test
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_1_15413936.1434619752068"
Date: Thu, 18 Jun 2015 05:29:12 -0400
------=_Part_1_15413936.1434619752068
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: base64
------=_Part_1_15413936.1434619752068
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: base64
TnVyIGVpbiBUZXN0ITxkaXY+PGJyPjwvZGl2PjxkaXY+PGZvbnQgc2l6ZT0iNiI+SGFoYWhhITwv
Zm9udD48L2Rpdj4=
------=_Part_1_15413936.1434619752068--
On the recipients end the same message is empty:
Delivered-To: daniel.florey#floreysoft.net
Received: by 10.140.94.46 with SMTP id f43csp925254qge;
Thu, 18 Jun 2015 02:29:13 -0700 (PDT)
X-Received: by 10.180.94.39 with SMTP id cz7mr61405623wib.66.1434619752847;
Thu, 18 Jun 2015 02:29:12 -0700 (PDT)
Return-Path: <daniel.florey#gmail.com>
Received: from mail-wi0-x233.google.com (mail-wi0-x233.google.com. [2a00:1450:400c:c05::233])
by mx.google.com with ESMTPS id ju2si35306720wid.33.2015.06.18.02.29.12
for <daniel.florey#floreysoft.net>
(version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
Thu, 18 Jun 2015 02:29:12 -0700 (PDT)
Received-SPF: pass (google.com: domain of daniel.florey#gmail.com designates 2a00:1450:400c:c05::233 as permitted sender) client-ip=2a00:1450:400c:c05::233;
Authentication-Results: mx.google.com;
spf=pass (google.com: domain of daniel.florey#gmail.com designates 2a00:1450:400c:c05::233 as permitted sender) smtp.mail=daniel.florey#gmail.com;
dkim=pass header.i=#gmail.com;
dmarc=pass (p=NONE dis=NONE) header.from=gmail.com
Received: by wicgi11 with SMTP id gi11so7511413wic.0
for <daniel.florey#floreysoft.net>; Thu, 18 Jun 2015 02:29:12 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20120113;
h=from:mime-version:date:message-id:subject:to:content-type;
bh=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=;
b=aYXfdO2NjbNXjQglJuER7ul/PfgQ84kxfMtDvUr4XEYuYEEhOZzWTiBj4Aedq8xtrH
5upGVtwKjHVc0R36BcFUD0tTq5IXLXsESIMEXL0pV0KJCFnXvMRCC+rn0uUzbCVWcSp4
LG8RxP9YTWRMhWQUattO/vI43kV34EMLax+irhY+98pXkaHHrNd5+GGO2OMzdcRPOpCg
gZ9bdQeEDsSrW4YJrxdKA/hJfCh6ceZ9mDgeRPiD+tC9AibhPK1QDqM8SKzh1QRoSZtl
yPGyJWGUXYMM9o7XaCh8ZenKLvd/AdTF2oAbwyqXnycAvOZqqj03x4sA38o5c4fEjkIQ
rAxQ==
X-Received: by 10.180.72.176 with SMTP id e16mr26991312wiv.12.1434619752466;
Thu, 18 Jun 2015 02:29:12 -0700 (PDT)
Received: from 889121556365-na05chj5g3il9flll2l3otqeh7q7ja22.apps.googleusercontent.com
named unknown by gmailapi.google.com with HTTPREST; Thu, 18 Jun 2015 05:29:12 -0400
From: daniel.florey#gmail.com
MIME-Version: 1.0
Date: Thu, 18 Jun 2015 05:29:12 -0400
Message-ID: <CAHWc4t9o6gpRs_HT0Y8E1szJtDTwfSMS7OH+jVro-LiA1kBLJw#mail.gmail.com>
Subject: Test
To: daniel.florey#floreysoft.net
Content-Type: text/plain; charset=UTF-8
The content type has been switched to text/plain?!
Any ideas?

Gmail automatically urlencodes links in mail

I'm trying to send an email to a gmail account containing a link which looks like this:
http://www.example.com/#/something#param=1
This is a link to an AngularJS application which needs the second '#' as a separator.
The problem is that gmail changes the seconds '#' to '%23' and this causes the application not to recognize the char as a separator.
Is there anything I can do with this?
Thanks.
I did a quick test using gmail to try to figure out what happens.
Here is the raw message
MIME-Version: 1.0
Received: by 10.96.50.232 with HTTP; Mon, 19 Jan 2015 05:44:30 -0800 (PST)
Date: Mon, 19 Jan 2015 14:44:30 +0100
Delivered-To: *******#gmail.com
Message-ID: <CPZt8dX3Q17wXmU7UT2iXp7q4tSn1UsDmyiUbXFVK7xE2Q0C10A#mail.gmail.com>
Subject: test
From: <name> <*******#gmail.com>
To: <name> <*******#gmail.com>
Content-Type: multipart/alternative; boundary=20cf303b41179134a6050d0185f4
--20cf303b41179134a6050d0185f4
Content-Type: text/plain; charset=UTF-8
http://www.example.com/#/something#param=1
--20cf303b41179134a6050d0185f4
Content-Type: text/html; charset=UTF-8
<div dir="ltr">http://www.example.com/#/something#param=1<br></div>
--20cf303b41179134a6050d0185f4--
The original message is showing the correct values, but I also noticed how my actual gmail client shows the second # as the html encoded %23.
Surprisingly enough, in contrast to what I suggested in my comment, using plain-text will actually give the desired result.
MIME-Version: 1.0
Received: by 10.96.50.232 with HTTP; Mon, 19 Jan 2015 06:06:39 -0800 (PST)
Date: Mon, 19 Jan 2015 15:06:39 +0100
Delivered-To: *****#gmail.com
Message-ID: <KMBt8bX2CrmEL66iRFAJ+_s_1W2eodD=9X=bMdsBK_13qzh6DaA#mail.gmail.com>
Subject: test4
From: <name> <*****#gmail.com>
To: <name> <*****#gmail.com>
Content-Type: text/plain; charset=UTF-8
http://www.example.com/#/something#param=1
I don't know how your AngularJS application reads the link from the email, so plain-text may not be an option, but the link in the above email is mapped to http://www.example.com/#/something#param=1 in my gmail client.

Mocking or Stubbing mtime for File::Stat

My object GETs a file over HTTP.
It does so, using the If-Modified-Since header. If the files has not been modified since the time in the header a Not Modified response will be returned and the file should not be fetched&written. Like so:
class YouTube
#...
def parse
uri = URI("http://i.ytimg.com/vi/#{#id}/0.jpg")
req = Net::HTTP::Get.new(uri.request_uri)
if File.exists? thumbname
stat = File.stat thumbname
req['If-Modified-Since'] = stat.mtime.rfc2822
end
res = Net::HTTP.start(uri.hostname, uri.port) {|http|
http.request(req)
}
File.open(thumbname, 'wb') do |f|
f.write res.body
end if res.is_a?(Net::HTTPSuccess)
end
#...
end
I want to test both cases (in both cases, a file on disk exists). To do so, I'd need to stub either something in Net::HTTP, or I need to stub the File.stat to return an mtime for which I a sure the online resource will return a new or Not-modified-since.
Should I stub (or even mock) Net::HTTP? And if so, what?
Or should I stub mtime to return a date far in the past or far in the future to enforce or suppress the Not-modified Header?
Edit: Diving deeper into the matter, I learned that the i.ytimg.com-domain does not support these headers. So i'll need to solve this by inspecing JSON from the YouTube API. However, the problem "What and how to mock when testing if-modified-since-headers" still stands.
Here is how I conclude the domain does not support this:
$curl -I --header 'If-Modified-Since: Sun, 24 Mar 2013 17:33:29 +0100' -L http://i.ytimg.com/vi/D80QdsFWdcQ/0.jpg
HTTP/1.1 200 OK
Content-Type: image/jpeg
Date: Sun, 24 Mar 2013 16:31:10 GMT
Expires: Sun, 24 Mar 2013 22:31:10 GMT
X-Content-Type-Options: nosniff
Server: sffe
Content-Length: 13343
X-XSS-Protection: 1; mode=block
Cache-Control: public, max-age=21600
Age: 822
There is no "Last-Modified" there. Illustrated with another call, to exaple.com, which does support the if-modified-since headers.
$curl -I --header 'If-Modified-Since: Sun, 24 Mar 2013 17:33:29 +0100' -L example.com
HTTP/1.0 302 Found
Location: http://www.iana.org/domains/example/
Server: BigIP
Connection: Keep-Alive
Content-Length: 0
HTTP/1.1 302 FOUND
Date: Sun, 24 Mar 2013 16:47:47 GMT
Server: Apache/2.2.3 (CentOS)
Location: http://www.iana.org/domains/example
Connection: close
Content-Type: text/html; charset=utf-8
HTTP/1.1 304 NOT MODIFIED
Date: Sun, 24 Mar 2013 16:47:47 GMT
Server: Apache/2.2.3 (CentOS)
Connection: close

Resources